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 using ui::Size;
32
33 namespace test {
34
TEST(WindowInfo,ParcellingWithoutToken)35 TEST(WindowInfo, ParcellingWithoutToken) {
36 WindowInfo i, i2;
37 i.token = nullptr;
38
39 Parcel p;
40 ASSERT_EQ(OK, i.writeToParcel(&p));
41 p.setDataPosition(0);
42 i2.readFromParcel(&p);
43 ASSERT_TRUE(i2.token == nullptr);
44 }
45
TEST(WindowInfo,Parcelling)46 TEST(WindowInfo, Parcelling) {
47 sp<IBinder> touchableRegionCropHandle = new BBinder();
48 WindowInfo i;
49 i.token = new BBinder();
50 i.windowToken = new BBinder();
51 i.id = 1;
52 i.name = "Foobar";
53 i.layoutParamsFlags = WindowInfo::Flag::SLIPPERY;
54 i.layoutParamsType = WindowInfo::Type::INPUT_METHOD;
55 i.dispatchingTimeout = 12s;
56 i.frame = Rect(93, 34, 16, 19);
57 i.contentSize = Size(10, 40);
58 i.surfaceInset = 17;
59 i.globalScaleFactor = 0.3;
60 i.alpha = 0.7;
61 i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
62 i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
63 i.ownerPid = gui::Pid{19};
64 i.ownerUid = gui::Uid{24};
65 i.packageName = "com.example.package";
66 i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE;
67 i.displayId = ui::LogicalDisplayId{34};
68 i.replaceTouchableRegionWithCrop = true;
69 i.touchableRegionCropHandle = touchableRegionCropHandle;
70 i.applicationInfo.name = "ApplicationFooBar";
71 i.applicationInfo.token = new BBinder();
72 i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
73 i.focusTransferTarget = new BBinder();
74
75 Parcel p;
76 i.writeToParcel(&p);
77 p.setDataPosition(0);
78 WindowInfo i2;
79 i2.readFromParcel(&p);
80 ASSERT_EQ(i.token, i2.token);
81 ASSERT_EQ(i.windowToken, i2.windowToken);
82 ASSERT_EQ(i.id, i2.id);
83 ASSERT_EQ(i.name, i2.name);
84 ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags);
85 ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType);
86 ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
87 ASSERT_EQ(i.frame, i2.frame);
88 ASSERT_EQ(i.contentSize, i2.contentSize);
89 ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
90 ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
91 ASSERT_EQ(i.alpha, i2.alpha);
92 ASSERT_EQ(i.transform, i2.transform);
93 ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
94 ASSERT_EQ(i.ownerPid, i2.ownerPid);
95 ASSERT_EQ(i.ownerUid, i2.ownerUid);
96 ASSERT_EQ(i.packageName, i2.packageName);
97 ASSERT_EQ(i.inputConfig, i2.inputConfig);
98 ASSERT_EQ(i.displayId, i2.displayId);
99 ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
100 ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
101 ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
102 ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget);
103 }
104
TEST(InputApplicationInfo,Parcelling)105 TEST(InputApplicationInfo, Parcelling) {
106 InputApplicationInfo i;
107 i.token = new BBinder();
108 i.name = "ApplicationFooBar";
109 i.dispatchingTimeoutMillis = 0x12345678ABCD;
110
111 Parcel p;
112 ASSERT_EQ(i.writeToParcel(&p), OK);
113 p.setDataPosition(0);
114 InputApplicationInfo i2;
115 ASSERT_EQ(i2.readFromParcel(&p), OK);
116 ASSERT_EQ(i, i2);
117 }
118
119 } // namespace test
120 } // namespace android
121