blob: dcdf76fe35287790730494c76b6b857c53013684 [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
chaviw3277faf2021-05-19 16:45:23 -050022#include <gui/WindowInfo.h>
Robert Carr3720ed02018-08-08 16:08:27 -070023
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050024using std::chrono_literals::operator""s;
25
Robert Carr3720ed02018-08-08 16:08:27 -070026namespace android {
chaviw3277faf2021-05-19 16:45:23 -050027
28using gui::InputApplicationInfo;
29using gui::TouchOcclusionMode;
30using gui::WindowInfo;
31
Robert Carr3720ed02018-08-08 16:08:27 -070032namespace test {
33
chaviw3277faf2021-05-19 16:45:23 -050034TEST(WindowInfo, ParcellingWithoutToken) {
35 WindowInfo i, i2;
Robert Carr5c8a0262018-10-03 16:30:44 -070036 i.token = nullptr;
Robert Carr3720ed02018-08-08 16:08:27 -070037
38 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070039 ASSERT_EQ(OK, i.writeToParcel(&p));
Robert Carr3720ed02018-08-08 16:08:27 -070040 p.setDataPosition(0);
Chris Ye0783e992020-06-02 21:34:49 -070041 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070042 ASSERT_TRUE(i2.token == nullptr);
Robert Carr3720ed02018-08-08 16:08:27 -070043}
44
chaviw3277faf2021-05-19 16:45:23 -050045TEST(WindowInfo, Parcelling) {
Vishnu Nair6fabeec2019-03-12 13:42:49 -070046 sp<IBinder> touchableRegionCropHandle = new BBinder();
chaviw3277faf2021-05-19 16:45:23 -050047 WindowInfo i;
Robert Carr5c8a0262018-10-03 16:30:44 -070048 i.token = new BBinder();
chaviwe0ba4e92021-08-11 11:38:41 -050049 i.windowToken = new BBinder();
chaviwaf87b3e2019-10-01 16:59:28 -070050 i.id = 1;
Robert Carr3720ed02018-08-08 16:08:27 -070051 i.name = "Foobar";
chaviw3277faf2021-05-19 16:45:23 -050052 i.flags = WindowInfo::Flag::SLIPPERY;
53 i.type = WindowInfo::Type::INPUT_METHOD;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050054 i.dispatchingTimeout = 12s;
Robert Carr3720ed02018-08-08 16:08:27 -070055 i.frameLeft = 93;
56 i.frameTop = 34;
57 i.frameRight = 16;
58 i.frameBottom = 19;
Robert Carr5cb25782018-11-14 14:01:42 -080059 i.surfaceInset = 17;
Robert Carre07e1032018-11-26 12:55:53 -080060 i.globalScaleFactor = 0.3;
Bernardo Rufinoea97d182020-08-19 14:43:14 +010061 i.alpha = 0.7;
chaviw9eaa22c2020-07-01 16:21:27 -070062 i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
Robert Carr3720ed02018-08-08 16:08:27 -070063 i.visible = false;
Vishnu Nair47074b82020-08-14 11:54:47 -070064 i.focusable = false;
Robert Carr3720ed02018-08-08 16:08:27 -070065 i.hasWallpaper = false;
66 i.paused = false;
Bernardo Rufinoea97d182020-08-19 14:43:14 +010067 i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
Robert Carr3720ed02018-08-08 16:08:27 -070068 i.ownerPid = 19;
69 i.ownerUid = 24;
Bernardo Rufinoea97d182020-08-19 14:43:14 +010070 i.packageName = "com.example.package";
chaviw3277faf2021-05-19 16:45:23 -050071 i.inputFeatures = WindowInfo::Feature::DISABLE_USER_ACTIVITY;
Robert Carr3720ed02018-08-08 16:08:27 -070072 i.displayId = 34;
Tiger Huang85b8c5e2019-01-17 18:34:54 +080073 i.portalToDisplayId = 2;
Vishnu Nair6fabeec2019-03-12 13:42:49 -070074 i.replaceTouchableRegionWithCrop = true;
75 i.touchableRegionCropHandle = touchableRegionCropHandle;
Chris Ye6c4243b2020-07-22 12:07:12 -070076 i.applicationInfo.name = "ApplicationFooBar";
77 i.applicationInfo.token = new BBinder();
Siarhei Vishniakou70622952020-07-30 11:17:23 -050078 i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
Robert Carr3720ed02018-08-08 16:08:27 -070079
80 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070081 i.writeToParcel(&p);
Robert Carr3720ed02018-08-08 16:08:27 -070082 p.setDataPosition(0);
chaviw3277faf2021-05-19 16:45:23 -050083 WindowInfo i2;
Chris Ye0783e992020-06-02 21:34:49 -070084 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070085 ASSERT_EQ(i.token, i2.token);
chaviwe0ba4e92021-08-11 11:38:41 -050086 ASSERT_EQ(i.windowToken, i2.windowToken);
chaviwaf87b3e2019-10-01 16:59:28 -070087 ASSERT_EQ(i.id, i2.id);
Robert Carr3720ed02018-08-08 16:08:27 -070088 ASSERT_EQ(i.name, i2.name);
Michael Wright44753b12020-07-08 13:48:11 +010089 ASSERT_EQ(i.flags, i2.flags);
90 ASSERT_EQ(i.type, i2.type);
Robert Carr3720ed02018-08-08 16:08:27 -070091 ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
92 ASSERT_EQ(i.frameLeft, i2.frameLeft);
93 ASSERT_EQ(i.frameTop, i2.frameTop);
94 ASSERT_EQ(i.frameRight, i2.frameRight);
95 ASSERT_EQ(i.frameBottom, i2.frameBottom);
Robert Carr5cb25782018-11-14 14:01:42 -080096 ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -080097 ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
Bernardo Rufinoea97d182020-08-19 14:43:14 +010098 ASSERT_EQ(i.alpha, i2.alpha);
chaviw1ff3d1e2020-07-01 15:53:47 -070099 ASSERT_EQ(i.transform, i2.transform);
Robert Carr3720ed02018-08-08 16:08:27 -0700100 ASSERT_EQ(i.visible, i2.visible);
Vishnu Nair47074b82020-08-14 11:54:47 -0700101 ASSERT_EQ(i.focusable, i2.focusable);
Robert Carr3720ed02018-08-08 16:08:27 -0700102 ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper);
103 ASSERT_EQ(i.paused, i2.paused);
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100104 ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
Robert Carr3720ed02018-08-08 16:08:27 -0700105 ASSERT_EQ(i.ownerPid, i2.ownerPid);
106 ASSERT_EQ(i.ownerUid, i2.ownerUid);
Bernardo Rufinoea97d182020-08-19 14:43:14 +0100107 ASSERT_EQ(i.packageName, i2.packageName);
Robert Carr3720ed02018-08-08 16:08:27 -0700108 ASSERT_EQ(i.inputFeatures, i2.inputFeatures);
109 ASSERT_EQ(i.displayId, i2.displayId);
Tiger Huang85b8c5e2019-01-17 18:34:54 +0800110 ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId);
Vishnu Nair6fabeec2019-03-12 13:42:49 -0700111 ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
112 ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
Chris Ye6c4243b2020-07-22 12:07:12 -0700113 ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
114}
115
116TEST(InputApplicationInfo, Parcelling) {
117 InputApplicationInfo i;
118 i.token = new BBinder();
119 i.name = "ApplicationFooBar";
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500120 i.dispatchingTimeoutMillis = 0x12345678ABCD;
Chris Ye6c4243b2020-07-22 12:07:12 -0700121
122 Parcel p;
123 ASSERT_EQ(i.writeToParcel(&p), OK);
124 p.setDataPosition(0);
125 InputApplicationInfo i2;
126 ASSERT_EQ(i2.readFromParcel(&p), OK);
127 ASSERT_EQ(i, i2);
Robert Carr3720ed02018-08-08 16:08:27 -0700128}
129
130} // namespace test
131} // namespace android