blob: 7e3a40d7cc0d9bd1995acda5dddd25bfeb125878 [file] [log] [blame]
Robert Carr3720ed02018-08-08 16:08:27 -07001/*
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
Robert Carr5c8a0262018-10-03 16:30:44 -070019#include <binder/Binder.h>
Robert Carr3720ed02018-08-08 16:08:27 -070020#include <binder/Parcel.h>
21
22#include <input/InputWindow.h>
23#include <input/InputTransport.h>
24
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050025using std::chrono_literals::operator""s;
26
Robert Carr3720ed02018-08-08 16:08:27 -070027namespace android {
28namespace test {
29
Robert Carr5c8a0262018-10-03 16:30:44 -070030TEST(InputWindowInfo, ParcellingWithoutToken) {
Chris Ye0783e992020-06-02 21:34:49 -070031 InputWindowInfo i, i2;
Robert Carr5c8a0262018-10-03 16:30:44 -070032 i.token = nullptr;
Robert Carr3720ed02018-08-08 16:08:27 -070033
34 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070035 ASSERT_EQ(OK, i.writeToParcel(&p));
Robert Carr3720ed02018-08-08 16:08:27 -070036 p.setDataPosition(0);
Chris Ye0783e992020-06-02 21:34:49 -070037 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070038 ASSERT_TRUE(i2.token == nullptr);
Robert Carr3720ed02018-08-08 16:08:27 -070039}
40
41TEST(InputWindowInfo, Parcelling) {
Vishnu Nair6fabeec2019-03-12 13:42:49 -070042 sp<IBinder> touchableRegionCropHandle = new BBinder();
Robert Carr3720ed02018-08-08 16:08:27 -070043 InputWindowInfo i;
Robert Carr5c8a0262018-10-03 16:30:44 -070044 i.token = new BBinder();
chaviwaf87b3e2019-10-01 16:59:28 -070045 i.id = 1;
Robert Carr3720ed02018-08-08 16:08:27 -070046 i.name = "Foobar";
Michael Wright44753b12020-07-08 13:48:11 +010047 i.flags = InputWindowInfo::Flag::SLIPPERY;
48 i.type = InputWindowInfo::Type::INPUT_METHOD;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050049 i.dispatchingTimeout = 12s;
Robert Carr3720ed02018-08-08 16:08:27 -070050 i.frameLeft = 93;
51 i.frameTop = 34;
52 i.frameRight = 16;
53 i.frameBottom = 19;
Robert Carr5cb25782018-11-14 14:01:42 -080054 i.surfaceInset = 17;
Robert Carre07e1032018-11-26 12:55:53 -080055 i.globalScaleFactor = 0.3;
chaviw9eaa22c2020-07-01 16:21:27 -070056 i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -070057 i.visible = false;
58 i.canReceiveKeys = false;
59 i.hasFocus = false;
60 i.hasWallpaper = false;
61 i.paused = false;
Robert Carr3720ed02018-08-08 16:08:27 -070062 i.ownerPid = 19;
63 i.ownerUid = 24;
Michael Wright44753b12020-07-08 13:48:11 +010064 i.inputFeatures = InputWindowInfo::Feature::DISABLE_USER_ACTIVITY;
Robert Carr3720ed02018-08-08 16:08:27 -070065 i.displayId = 34;
Tiger Huang85b8c5e2019-01-17 18:34:54 +080066 i.portalToDisplayId = 2;
Vishnu Nair6fabeec2019-03-12 13:42:49 -070067 i.replaceTouchableRegionWithCrop = true;
68 i.touchableRegionCropHandle = touchableRegionCropHandle;
Chris Ye6c4243b2020-07-22 12:07:12 -070069 i.applicationInfo.name = "ApplicationFooBar";
70 i.applicationInfo.token = new BBinder();
Siarhei Vishniakou70622952020-07-30 11:17:23 -050071 i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
Robert Carr3720ed02018-08-08 16:08:27 -070072
73 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070074 i.writeToParcel(&p);
Robert Carr3720ed02018-08-08 16:08:27 -070075 p.setDataPosition(0);
Chris Ye0783e992020-06-02 21:34:49 -070076 InputWindowInfo i2;
77 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070078 ASSERT_EQ(i.token, i2.token);
chaviwaf87b3e2019-10-01 16:59:28 -070079 ASSERT_EQ(i.id, i2.id);
Robert Carr3720ed02018-08-08 16:08:27 -070080 ASSERT_EQ(i.name, i2.name);
Michael Wright44753b12020-07-08 13:48:11 +010081 ASSERT_EQ(i.flags, i2.flags);
82 ASSERT_EQ(i.type, i2.type);
Robert Carr3720ed02018-08-08 16:08:27 -070083 ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
84 ASSERT_EQ(i.frameLeft, i2.frameLeft);
85 ASSERT_EQ(i.frameTop, i2.frameTop);
86 ASSERT_EQ(i.frameRight, i2.frameRight);
87 ASSERT_EQ(i.frameBottom, i2.frameBottom);
Robert Carr5cb25782018-11-14 14:01:42 -080088 ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -080089 ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
chaviw1ff3d1e2020-07-01 15:53:47 -070090 ASSERT_EQ(i.transform, i2.transform);
Robert Carr3720ed02018-08-08 16:08:27 -070091 ASSERT_EQ(i.visible, i2.visible);
92 ASSERT_EQ(i.canReceiveKeys, i2.canReceiveKeys);
93 ASSERT_EQ(i.hasFocus, i2.hasFocus);
94 ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper);
95 ASSERT_EQ(i.paused, i2.paused);
Robert Carr3720ed02018-08-08 16:08:27 -070096 ASSERT_EQ(i.ownerPid, i2.ownerPid);
97 ASSERT_EQ(i.ownerUid, i2.ownerUid);
98 ASSERT_EQ(i.inputFeatures, i2.inputFeatures);
99 ASSERT_EQ(i.displayId, i2.displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800100 ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700101 ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
102 ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
Chris Ye6c4243b2020-07-22 12:07:12 -0700103 ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
104}
105
106TEST(InputApplicationInfo, Parcelling) {
107 InputApplicationInfo i;
108 i.token = new BBinder();
109 i.name = "ApplicationFooBar";
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500110 i.dispatchingTimeoutMillis = 0x12345678ABCD;
Chris Ye6c4243b2020-07-22 12:07:12 -0700111
112 Parcel p;
113 ASSERT_EQ(i.writeToParcel(&p), OK);
114 p.setDataPosition(0);
115 InputApplicationInfo i2;
116 ASSERT_EQ(i2.readFromParcel(&p), OK);
117 ASSERT_EQ(i, i2);
Robert Carr3720ed02018-08-08 16:08:27 -0700118}
119
120} // namespace test
121} // namespace android