• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.layoutParamsFlags = WindowInfo::Flag::SLIPPERY;
53     i.layoutParamsType = 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.touchOcclusionMode = TouchOcclusionMode::ALLOW;
64     i.ownerPid = gui::Pid{19};
65     i.ownerUid = gui::Uid{24};
66     i.packageName = "com.example.package";
67     i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE;
68     i.displayId = 34;
69     i.replaceTouchableRegionWithCrop = true;
70     i.touchableRegionCropHandle = touchableRegionCropHandle;
71     i.applicationInfo.name = "ApplicationFooBar";
72     i.applicationInfo.token = new BBinder();
73     i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
74     i.focusTransferTarget = new BBinder();
75 
76     Parcel p;
77     i.writeToParcel(&p);
78     p.setDataPosition(0);
79     WindowInfo i2;
80     i2.readFromParcel(&p);
81     ASSERT_EQ(i.token, i2.token);
82     ASSERT_EQ(i.windowToken, i2.windowToken);
83     ASSERT_EQ(i.id, i2.id);
84     ASSERT_EQ(i.name, i2.name);
85     ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags);
86     ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType);
87     ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
88     ASSERT_EQ(i.frameLeft, i2.frameLeft);
89     ASSERT_EQ(i.frameTop, i2.frameTop);
90     ASSERT_EQ(i.frameRight, i2.frameRight);
91     ASSERT_EQ(i.frameBottom, i2.frameBottom);
92     ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
93     ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
94     ASSERT_EQ(i.alpha, i2.alpha);
95     ASSERT_EQ(i.transform, i2.transform);
96     ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
97     ASSERT_EQ(i.ownerPid, i2.ownerPid);
98     ASSERT_EQ(i.ownerUid, i2.ownerUid);
99     ASSERT_EQ(i.packageName, i2.packageName);
100     ASSERT_EQ(i.inputConfig, i2.inputConfig);
101     ASSERT_EQ(i.displayId, i2.displayId);
102     ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
103     ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
104     ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
105     ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget);
106 }
107 
TEST(InputApplicationInfo,Parcelling)108 TEST(InputApplicationInfo, Parcelling) {
109     InputApplicationInfo i;
110     i.token = new BBinder();
111     i.name = "ApplicationFooBar";
112     i.dispatchingTimeoutMillis = 0x12345678ABCD;
113 
114     Parcel p;
115     ASSERT_EQ(i.writeToParcel(&p), OK);
116     p.setDataPosition(0);
117     InputApplicationInfo i2;
118     ASSERT_EQ(i2.readFromParcel(&p), OK);
119     ASSERT_EQ(i, i2);
120 }
121 
122 } // namespace test
123 } // namespace android
124