1 /*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <gtest/gtest.h>
18
19 #include <binder/Binder.h>
20 #include <binder/Parcel.h>
21
22 #include <gui/WindowInfo.h>
23
24 using std::chrono_literals::operator""s;
25
26 namespace android {
27
28 using gui::InputApplicationInfo;
29 using gui::TouchOcclusionMode;
30 using gui::WindowInfo;
31
32 namespace test {
33
TEST(WindowInfo,ParcellingWithoutToken)34 TEST(WindowInfo, ParcellingWithoutToken) {
35 WindowInfo i, i2;
36 i.token = nullptr;
37
38 Parcel p;
39 ASSERT_EQ(OK, i.writeToParcel(&p));
40 p.setDataPosition(0);
41 i2.readFromParcel(&p);
42 ASSERT_TRUE(i2.token == nullptr);
43 }
44
TEST(WindowInfo,Parcelling)45 TEST(WindowInfo, Parcelling) {
46 sp<IBinder> touchableRegionCropHandle = new BBinder();
47 WindowInfo i;
48 i.token = new BBinder();
49 i.windowToken = new BBinder();
50 i.id = 1;
51 i.name = "Foobar";
52 i.flags = WindowInfo::Flag::SLIPPERY;
53 i.type = WindowInfo::Type::INPUT_METHOD;
54 i.dispatchingTimeout = 12s;
55 i.frameLeft = 93;
56 i.frameTop = 34;
57 i.frameRight = 16;
58 i.frameBottom = 19;
59 i.surfaceInset = 17;
60 i.globalScaleFactor = 0.3;
61 i.alpha = 0.7;
62 i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
63 i.displayOrientation = ui::Transform::ROT_0;
64 i.displayWidth = 1000;
65 i.displayHeight = 2000;
66 i.visible = false;
67 i.focusable = false;
68 i.hasWallpaper = false;
69 i.paused = false;
70 i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
71 i.ownerPid = 19;
72 i.ownerUid = 24;
73 i.packageName = "com.example.package";
74 i.inputFeatures = WindowInfo::Feature::DISABLE_USER_ACTIVITY;
75 i.displayId = 34;
76 i.portalToDisplayId = 2;
77 i.replaceTouchableRegionWithCrop = true;
78 i.touchableRegionCropHandle = touchableRegionCropHandle;
79 i.applicationInfo.name = "ApplicationFooBar";
80 i.applicationInfo.token = new BBinder();
81 i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
82
83 Parcel p;
84 i.writeToParcel(&p);
85 p.setDataPosition(0);
86 WindowInfo i2;
87 i2.readFromParcel(&p);
88 ASSERT_EQ(i.token, i2.token);
89 ASSERT_EQ(i.windowToken, i2.windowToken);
90 ASSERT_EQ(i.id, i2.id);
91 ASSERT_EQ(i.name, i2.name);
92 ASSERT_EQ(i.flags, i2.flags);
93 ASSERT_EQ(i.type, i2.type);
94 ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
95 ASSERT_EQ(i.frameLeft, i2.frameLeft);
96 ASSERT_EQ(i.frameTop, i2.frameTop);
97 ASSERT_EQ(i.frameRight, i2.frameRight);
98 ASSERT_EQ(i.frameBottom, i2.frameBottom);
99 ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
100 ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
101 ASSERT_EQ(i.alpha, i2.alpha);
102 ASSERT_EQ(i.transform, i2.transform);
103 ASSERT_EQ(i.displayWidth, i2.displayWidth);
104 ASSERT_EQ(i.displayHeight, i2.displayHeight);
105 ASSERT_EQ(i.visible, i2.visible);
106 ASSERT_EQ(i.focusable, i2.focusable);
107 ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper);
108 ASSERT_EQ(i.paused, i2.paused);
109 ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
110 ASSERT_EQ(i.ownerPid, i2.ownerPid);
111 ASSERT_EQ(i.ownerUid, i2.ownerUid);
112 ASSERT_EQ(i.packageName, i2.packageName);
113 ASSERT_EQ(i.inputFeatures, i2.inputFeatures);
114 ASSERT_EQ(i.displayId, i2.displayId);
115 ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId);
116 ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
117 ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
118 ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
119 }
120
TEST(InputApplicationInfo,Parcelling)121 TEST(InputApplicationInfo, Parcelling) {
122 InputApplicationInfo i;
123 i.token = new BBinder();
124 i.name = "ApplicationFooBar";
125 i.dispatchingTimeoutMillis = 0x12345678ABCD;
126
127 Parcel p;
128 ASSERT_EQ(i.writeToParcel(&p), OK);
129 p.setDataPosition(0);
130 InputApplicationInfo i2;
131 ASSERT_EQ(i2.readFromParcel(&p), OK);
132 ASSERT_EQ(i, i2);
133 }
134
135 } // namespace test
136 } // namespace android
137