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 | |
| 22 | #include <input/InputWindow.h> |
| 23 | #include <input/InputTransport.h> |
| 24 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 25 | using std::chrono_literals::operator""s; |
| 26 | |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace test { |
| 29 | |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 30 | TEST(InputWindowInfo, ParcellingWithoutToken) { |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 31 | InputWindowInfo i, i2; |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 32 | i.token = nullptr; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 33 | |
| 34 | Parcel p; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 35 | ASSERT_EQ(OK, i.writeToParcel(&p)); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 36 | p.setDataPosition(0); |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 37 | i2.readFromParcel(&p); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 38 | ASSERT_TRUE(i2.token == nullptr); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | TEST(InputWindowInfo, Parcelling) { |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 42 | sp<IBinder> touchableRegionCropHandle = new BBinder(); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 43 | InputWindowInfo i; |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 44 | i.token = new BBinder(); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 45 | i.id = 1; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 46 | i.name = "Foobar"; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 47 | i.flags = InputWindowInfo::Flag::SLIPPERY; |
| 48 | i.type = InputWindowInfo::Type::INPUT_METHOD; |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 49 | i.dispatchingTimeout = 12s; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 50 | i.frameLeft = 93; |
| 51 | i.frameTop = 34; |
| 52 | i.frameRight = 16; |
| 53 | i.frameBottom = 19; |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 54 | i.surfaceInset = 17; |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 55 | i.globalScaleFactor = 0.3; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 56 | i.alpha = 0.7; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 57 | i.transform.set({0.4, -1, 100, 0.5, 0, 40, 0, 0, 1}); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 58 | i.visible = false; |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 59 | i.focusable = false; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 60 | i.hasWallpaper = false; |
| 61 | i.paused = false; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 62 | i.touchOcclusionMode = TouchOcclusionMode::ALLOW; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 63 | i.ownerPid = 19; |
| 64 | i.ownerUid = 24; |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 65 | i.packageName = "com.example.package"; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 66 | i.inputFeatures = InputWindowInfo::Feature::DISABLE_USER_ACTIVITY; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 67 | i.displayId = 34; |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 68 | i.portalToDisplayId = 2; |
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; |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 74 | |
| 75 | Parcel p; |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 76 | i.writeToParcel(&p); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 77 | p.setDataPosition(0); |
Chris Ye | 0783e99 | 2020-06-02 21:34:49 -0700 | [diff] [blame] | 78 | InputWindowInfo i2; |
| 79 | i2.readFromParcel(&p); |
Robert Carr | 5c8a026 | 2018-10-03 16:30:44 -0700 | [diff] [blame] | 80 | ASSERT_EQ(i.token, i2.token); |
chaviw | af87b3e | 2019-10-01 16:59:28 -0700 | [diff] [blame] | 81 | ASSERT_EQ(i.id, i2.id); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 82 | ASSERT_EQ(i.name, i2.name); |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 83 | ASSERT_EQ(i.flags, i2.flags); |
| 84 | ASSERT_EQ(i.type, i2.type); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 85 | ASSERT_EQ(i.dispatchingTimeout, i2.dispatchingTimeout); |
| 86 | ASSERT_EQ(i.frameLeft, i2.frameLeft); |
| 87 | ASSERT_EQ(i.frameTop, i2.frameTop); |
| 88 | ASSERT_EQ(i.frameRight, i2.frameRight); |
| 89 | ASSERT_EQ(i.frameBottom, i2.frameBottom); |
Robert Carr | 5cb2578 | 2018-11-14 14:01:42 -0800 | [diff] [blame] | 90 | ASSERT_EQ(i.surfaceInset, i2.surfaceInset); |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 91 | ASSERT_EQ(i.globalScaleFactor, i2.globalScaleFactor); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 92 | ASSERT_EQ(i.alpha, i2.alpha); |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 93 | ASSERT_EQ(i.transform, i2.transform); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 94 | ASSERT_EQ(i.visible, i2.visible); |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 95 | ASSERT_EQ(i.focusable, i2.focusable); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 96 | ASSERT_EQ(i.hasWallpaper, i2.hasWallpaper); |
| 97 | ASSERT_EQ(i.paused, i2.paused); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 98 | ASSERT_EQ(i.touchOcclusionMode, i2.touchOcclusionMode); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 99 | ASSERT_EQ(i.ownerPid, i2.ownerPid); |
| 100 | ASSERT_EQ(i.ownerUid, i2.ownerUid); |
Bernardo Rufino | ea97d18 | 2020-08-19 14:43:14 +0100 | [diff] [blame^] | 101 | ASSERT_EQ(i.packageName, i2.packageName); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 102 | ASSERT_EQ(i.inputFeatures, i2.inputFeatures); |
| 103 | ASSERT_EQ(i.displayId, i2.displayId); |
Tiger Huang | 85b8c5e | 2019-01-17 18:34:54 +0800 | [diff] [blame] | 104 | ASSERT_EQ(i.portalToDisplayId, i2.portalToDisplayId); |
Vishnu Nair | 6fabeec | 2019-03-12 13:42:49 -0700 | [diff] [blame] | 105 | ASSERT_EQ(i.replaceTouchableRegionWithCrop, i2.replaceTouchableRegionWithCrop); |
| 106 | ASSERT_EQ(i.touchableRegionCropHandle, i2.touchableRegionCropHandle); |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 107 | ASSERT_EQ(i.applicationInfo, i2.applicationInfo); |
| 108 | } |
| 109 | |
| 110 | TEST(InputApplicationInfo, Parcelling) { |
| 111 | InputApplicationInfo i; |
| 112 | i.token = new BBinder(); |
| 113 | i.name = "ApplicationFooBar"; |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 114 | i.dispatchingTimeoutMillis = 0x12345678ABCD; |
Chris Ye | 6c4243b | 2020-07-22 12:07:12 -0700 | [diff] [blame] | 115 | |
| 116 | Parcel p; |
| 117 | ASSERT_EQ(i.writeToParcel(&p), OK); |
| 118 | p.setDataPosition(0); |
| 119 | InputApplicationInfo i2; |
| 120 | ASSERT_EQ(i2.readFromParcel(&p), OK); |
| 121 | ASSERT_EQ(i, i2); |
Robert Carr | 3720ed0 | 2018-08-08 16:08:27 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | } // namespace test |
| 125 | } // namespace android |