Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 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 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 19 | #include <binder/Binder.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 20 | #include <binder/Parcel.h> |
| 21 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 22 | #include <gui/WindowInfo.h> |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 23 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 24 | using std::chrono_literals::operator""s; |
| 25 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 26 | namespace android { |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 27 | |
| 28 | using gui::InputApplicationInfo; |
| 29 | using gui::TouchOcclusionMode; |
| 30 | using gui::WindowInfo; |
| 31 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 32 | namespace test { |
| 33 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 34 | TEST(WindowInfo, ParcellingWithoutToken) { |
| 35 | WindowInfo i, i2; |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 36 | i.token = nullptr; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 37 | |
| 38 | Parcel p; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 39 | ASSERT_EQ(OK, i.writeToParcel(&p)); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 40 | p.setDataPosition(0); |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 41 | i2.readFromParcel(&p); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 42 | ASSERT_TRUE(i2.token == nullptr); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 43 | } |
| 44 | |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 45 | TEST(WindowInfo, Parcelling) { |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 46 | sp<IBinder> touchableRegionCropHandle = new BBinder(); |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 47 | WindowInfo i; |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 48 | i.token = new BBinder(); |
chaviw | e0ba4e9 | 2021-08-11 11:38:41 -0500 | [diff] [blame] | 49 | i.windowToken = new BBinder(); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 50 | i.id = 1; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 51 | i.name = "Foobar"; |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 52 | i.layoutParamsFlags = WindowInfo::Flag::SLIPPERY; |
| 53 | i.layoutParamsType = WindowInfo::Type::INPUT_METHOD; |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 54 | i.dispatchingTimeout = 12s; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 55 | i.frameLeft = 93; |
| 56 | i.frameTop = 34; |
| 57 | i.frameRight = 16; |
| 58 | i.frameBottom = 19; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 59 | i.surfaceInset = 17; |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 60 | i.globalScaleFactor = 0.3; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 61 | i.alpha = 0.7; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 62 | i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1}); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 63 | i.touchOcclusionMode = TouchOcclusionMode::ALLOW; |
Prabir Pradhan | aeebeb4 | 2023-06-13 19:53:03 +0000 | [diff] [blame^] | 64 | i.ownerPid = gui::Pid{19}; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 65 | i.ownerUid = gui::Uid{24}; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 66 | i.packageName = "com.example.package"; |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 67 | i.inputConfig = WindowInfo::InputConfig::NOT_FOCUSABLE; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 68 | i.displayId = 34; |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 69 | i.replaceTouchableRegionWithCrop = true; |
| 70 | i.touchableRegionCropHandle = touchableRegionCropHandle; |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 71 | i.applicationInfo.name = "ApplicationFooBar"; |
| 72 | i.applicationInfo.token = new BBinder(); |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 73 | i.applicationInfo.dispatchingTimeoutMillis = 0x12345678ABCD; |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 74 | i.focusTransferTarget = new BBinder(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 75 | |
| 76 | Parcel p; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 77 | i.writeToParcel(&p); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 78 | p.setDataPosition(0); |
chaviw | 3277faf | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 79 | WindowInfo i2; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 80 | i2.readFromParcel(&p); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 81 | ASSERT_EQ(i.token, i2.token); |
chaviw | e0ba4e9 | 2021-08-11 11:38:41 -0500 | [diff] [blame] | 82 | ASSERT_EQ(i.windowToken, i2.windowToken); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 83 | ASSERT_EQ(i.id, i2.id); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 84 | ASSERT_EQ(i.name, i2.name); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 85 | ASSERT_EQ(i.layoutParamsFlags, i2.layoutParamsFlags); |
| 86 | ASSERT_EQ(i.layoutParamsType, i2.layoutParamsType); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 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); |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 92 | ASSERT_EQ(i.surfaceInset, i2.surfaceInset); |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 93 | ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 94 | ASSERT_EQ(i.alpha, i2.alpha); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 95 | ASSERT_EQ(i.transform, i2.transform); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 96 | ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 97 | ASSERT_EQ(i.ownerPid, i2.ownerPid); |
| 98 | ASSERT_EQ(i.ownerUid, i2.ownerUid); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame] | 99 | ASSERT_EQ(i.packageName, i2.packageName); |
Prabir Pradhan | 4d5c52f | 2022-01-31 08:52:10 -0800 | [diff] [blame] | 100 | ASSERT_EQ(i.inputConfig, i2.inputConfig); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 101 | ASSERT_EQ(i.displayId, i2.displayId); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 102 | ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop); |
| 103 | ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle); |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 104 | ASSERT_EQ(i.applicationInfo, i2.applicationInfo); |
Chavi Weingarten | 847e851 | 2023-03-29 00:26:09 +0000 | [diff] [blame] | 105 | ASSERT_EQ(i.focusTransferTarget, i2.focusTransferTarget); |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | TEST(InputApplicationInfo, Parcelling) { |
| 109 | InputApplicationInfo i; |
| 110 | i.token = new BBinder(); |
| 111 | i.name = "ApplicationFooBar"; |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 112 | i.dispatchingTimeoutMillis = 0x12345678ABCD; |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 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); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | } // namespace test |
| 123 | } // namespace android |