• 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 <input/InputWindow.h>
23 #include <input/InputTransport.h>
24 
25 using std::chrono_literals::operator""s;
26 
27 namespace android {
28 namespace test {
29 
TEST(InputWindowInfo,ParcellingWithoutToken)30 TEST(InputWindowInfo, ParcellingWithoutToken) {
31     InputWindowInfo i, i2;
32     i.token = nullptr;
33 
34     Parcel p;
35     ASSERT_EQ(OK, i.writeToParcel(&p));
36     p.setDataPosition(0);
37     i2.readFromParcel(&p);
38     ASSERT_TRUE(i2.token == nullptr);
39 }
40 
TEST(InputWindowInfo,Parcelling)41 TEST(InputWindowInfo, Parcelling) {
42     sp<IBinder> touchableRegionCropHandle = new BBinder();
43     InputWindowInfo i;
44     i.token = new BBinder();
45     i.id = 1;
46     i.name = "Foobar";
47     i.flags = InputWindowInfo::Flag::SLIPPERY;
48     i.type = InputWindowInfo::Type::INPUT_METHOD;
49     i.dispatchingTimeout = 12s;
50     i.frameLeft = 93;
51     i.frameTop = 34;
52     i.frameRight = 16;
53     i.frameBottom = 19;
54     i.surfaceInset = 17;
55     i.globalScaleFactor = 0.3;
56     i.alpha = 0.7;
57     i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
58     i.displayWidth = 1000;
59     i.displayHeight = 2000;
60     i.visible = false;
61     i.focusable = false;
62     i.hasWallpaper = false;
63     i.paused = false;
64     i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
65     i.ownerPid = 19;
66     i.ownerUid = 24;
67     i.packageName = "com.example.package";
68     i.inputFeatures = InputWindowInfo::Feature::DISABLE_USER_ACTIVITY;
69     i.displayId = 34;
70     i.portalToDisplayId = 2;
71     i.replaceTouchableRegionWithCrop = true;
72     i.touchableRegionCropHandle = touchableRegionCropHandle;
73     i.applicationInfo.name = "ApplicationFooBar";
74     i.applicationInfo.token = new BBinder();
75     i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
76 
77     Parcel p;
78     i.writeToParcel(&p);
79     p.setDataPosition(0);
80     InputWindowInfo i2;
81     i2.readFromParcel(&p);
82     ASSERT_EQ(i.token, i2.token);
83     ASSERT_EQ(i.id, i2.id);
84     ASSERT_EQ(i.name, i2.name);
85     ASSERT_EQ(i.flags, i2.flags);
86     ASSERT_EQ(i.type, i2.type);
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.displayWidth, i2.displayWidth);
97     ASSERT_EQ(i.displayHeight, i2.displayHeight);
98     ASSERT_EQ(i.visible, i2.visible);
99     ASSERT_EQ(i.focusable, i2.focusable);
100     ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper);
101     ASSERT_EQ(i.paused, i2.paused);
102     ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
103     ASSERT_EQ(i.ownerPid, i2.ownerPid);
104     ASSERT_EQ(i.ownerUid, i2.ownerUid);
105     ASSERT_EQ(i.packageName, i2.packageName);
106     ASSERT_EQ(i.inputFeatures, i2.inputFeatures);
107     ASSERT_EQ(i.displayId, i2.displayId);
108     ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId);
109     ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
110     ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
111     ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
112 }
113 
TEST(InputApplicationInfo,Parcelling)114 TEST(InputApplicationInfo, Parcelling) {
115     InputApplicationInfo i;
116     i.token = new BBinder();
117     i.name = "ApplicationFooBar";
118     i.dispatchingTimeoutMillis = 0x12345678ABCD;
119 
120     Parcel p;
121     ASSERT_EQ(i.writeToParcel(&p), OK);
122     p.setDataPosition(0);
123     InputApplicationInfo i2;
124     ASSERT_EQ(i2.readFromParcel(&p), OK);
125     ASSERT_EQ(i, i2);
126 }
127 
128 } // namespace test
129 } // namespace android
130