blob: ce22082a9fa4e015a9c141a05747a8de7d008197 [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;
Vishnu Nair494a2e42023-11-10 17:21:19 -080031using ui::Size;
chaviw3277faf2021-05-19 16:45:23 -050032
Robert Carr3720ed02018-08-08 16:08:27 -070033namespace test {
34
chaviw3277faf2021-05-19 16:45:23 -050035TEST(WindowInfo, ParcellingWithoutToken) {
36 WindowInfo i, i2;
Robert Carr5c8a0262018-10-03 16:30:44 -070037 i.token = nullptr;
Robert Carr3720ed02018-08-08 16:08:27 -070038
39 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070040 ASSERT_EQ(OK, i.writeToParcel(&p));
Robert Carr3720ed02018-08-08 16:08:27 -070041 p.setDataPosition(0);
Chris Ye0783e992020-06-02 21:34:49 -070042 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070043 ASSERT_TRUE(i2.token == nullptr);
Robert Carr3720ed02018-08-08 16:08:27 -070044}
45
chaviw3277faf2021-05-19 16:45:23 -050046TEST(WindowInfo, Parcelling) {
Vishnu Nair6fabeec2019-03-12 13:42:49 -070047 sp<IBinder> touchableRegionCropHandle = new BBinder();
chaviw3277faf2021-05-19 16:45:23 -050048 WindowInfo i;
Robert Carr5c8a0262018-10-03 16:30:44 -070049 i.token = new BBinder();
chaviwe0ba4e92021-08-11 11:38:41 -050050 i.windowToken = new BBinder();
chaviwaf87b3e2019-10-01 16:59:28 -070051 i.id = 1;
Robert Carr3720ed02018-08-08 16:08:27 -070052 i.name = "Foobar";
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080053 i.layoutParamsFlags = WindowInfo::Flag::SLIPPERY;
54 i.layoutParamsType = WindowInfo::Type::INPUT_METHOD;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -050055 i.dispatchingTimeout = 12s;
Chavi Weingarten7f019192023-08-08 20:39:01 +000056 i.frame = Rect(93, 34, 16, 19);
Vishnu Nair494a2e42023-11-10 17:21:19 -080057 i.contentSize = Size(10, 40);
Robert Carr5cb25782018-11-14 14:01:42 -080058 i.surfaceInset = 17;
Robert Carre07e1032018-11-26 12:55:53 -080059 i.globalScaleFactor = 0.3;
Bernardo Rufinoea97d182020-08-19 14:43:14 +010060 i.alpha = 0.7;
chaviw9eaa22c2020-07-01 16:21:27 -070061 i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1});
Bernardo Rufinoea97d182020-08-19 14:43:14 +010062 i.touchOcclusionMode = TouchOcclusionMode::ALLOW;
Prabir Pradhanaeebeb42023-06-13 19:53:03 +000063 i.ownerPid = gui::Pid{19};
Prabir Pradhan8a5c41d2023-06-08 19:13:46 +000064 i.ownerUid = gui::Uid{24};
Bernardo Rufinoea97d182020-08-19 14:43:14 +010065 i.packageName = "com.example.package";
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080066 i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE;
Linnan Li13bf76a2024-05-05 19:18:02 +080067 i.displayId = ui::LogicalDisplayId{34};
Vishnu Nair6fabeec2019-03-12 13:42:49 -070068 i.replaceTouchableRegionWithCrop = true;
69 i.touchableRegionCropHandle = touchableRegionCropHandle;
Chris Ye6c4243b2020-07-22 12:07:12 -070070 i.applicationInfo.name = "ApplicationFooBar";
71 i.applicationInfo.token = new BBinder();
Siarhei Vishniakou70622952020-07-30 11:17:23 -050072 i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD;
Chavi Weingarten847e8512023-03-29 00:26:09 +000073 i.focusTransferTarget = new BBinder();
Robert Carr3720ed02018-08-08 16:08:27 -070074
75 Parcel p;
Chris Ye0783e992020-06-02 21:34:49 -070076 i.writeToParcel(&p);
Robert Carr3720ed02018-08-08 16:08:27 -070077 p.setDataPosition(0);
chaviw3277faf2021-05-19 16:45:23 -050078 WindowInfo i2;
Chris Ye0783e992020-06-02 21:34:49 -070079 i2.readFromParcel(&p);
Robert Carr5c8a0262018-10-03 16:30:44 -070080 ASSERT_EQ(i.token, i2.token);
chaviwe0ba4e92021-08-11 11:38:41 -050081 ASSERT_EQ(i.windowToken, i2.windowToken);
chaviwaf87b3e2019-10-01 16:59:28 -070082 ASSERT_EQ(i.id, i2.id);
Robert Carr3720ed02018-08-08 16:08:27 -070083 ASSERT_EQ(i.name, i2.name);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080084 ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags);
85 ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType);
Robert Carr3720ed02018-08-08 16:08:27 -070086 ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout);
Chavi Weingarten7f019192023-08-08 20:39:01 +000087 ASSERT_EQ(i.frame, i2.frame);
Vishnu Nair494a2e42023-11-10 17:21:19 -080088 ASSERT_EQ(i.contentSize, i2.contentSize);
Robert Carr5cb25782018-11-14 14:01:42 -080089 ASSERT_EQ(i.surfaceInset, i2.surfaceInset);
Robert Carre07e1032018-11-26 12:55:53 -080090 ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor);
Bernardo Rufinoea97d182020-08-19 14:43:14 +010091 ASSERT_EQ(i.alpha, i2.alpha);
chaviw1ff3d1e2020-07-01 15:53:47 -070092 ASSERT_EQ(i.transform, i2.transform);
Bernardo Rufinoea97d182020-08-19 14:43:14 +010093 ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode);
Robert Carr3720ed02018-08-08 16:08:27 -070094 ASSERT_EQ(i.ownerPid, i2.ownerPid);
95 ASSERT_EQ(i.ownerUid, i2.ownerUid);
Bernardo Rufinoea97d182020-08-19 14:43:14 +010096 ASSERT_EQ(i.packageName, i2.packageName);
Prabir Pradhan4d5c52f2022-01-31 08:52:10 -080097 ASSERT_EQ(i.inputConfig, i2.inputConfig);
Robert Carr3720ed02018-08-08 16:08:27 -070098 ASSERT_EQ(i.displayId, i2.displayId);
Vishnu Nair6fabeec2019-03-12 13:42:49 -070099 ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop);
100 ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle);
Chris Ye6c4243b2020-07-22 12:07:12 -0700101 ASSERT_EQ(i.applicationInfo, i2.applicationInfo);
Chavi Weingarten847e8512023-03-29 00:26:09 +0000102 ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget);
Chris Ye6c4243b2020-07-22 12:07:12 -0700103}
104
105TEST(InputApplicationInfo, Parcelling) {
106 InputApplicationInfo i;
107 i.token = new BBinder();
108 i.name = "ApplicationFooBar";
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500109 i.dispatchingTimeoutMillis = 0x12345678ABCD;
Chris Ye6c4243b2020-07-22 12:07:12 -0700110
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);
Robert Carr3720ed02018-08-08 16:08:27 -0700117}
118
119} // namespace test
120} // namespace android