blob: 9674e24b4c6558267a5b3c7415407bfdc854f214 [file] [log] [blame]
Robert Carr1c4c5592018-09-24 13:18:43 -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#include <stdlib.h>
19#include <unistd.h>
20#include <sys/time.h>
21#include <sys/types.h>
22#include <stdio.h>
23#include <poll.h>
24
25#include <memory>
26
Vishnu Nairde19f852018-12-18 16:11:53 -080027#include <android/native_window.h>
28
Robert Carr1c4c5592018-09-24 13:18:43 -070029#include <binder/Binder.h>
30#include <binder/IServiceManager.h>
31#include <binder/Parcel.h>
32#include <binder/ProcessState.h>
33
Vishnu Nairde19f852018-12-18 16:11:53 -080034#include <gui/ISurfaceComposer.h>
35#include <gui/Surface.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070036#include <gui/SurfaceComposerClient.h>
37#include <gui/SurfaceControl.h>
38
Chris Ye0783e992020-06-02 21:34:49 -070039#include <android/os/IInputFlinger.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070040#include <input/Input.h>
Chris Ye0783e992020-06-02 21:34:49 -070041#include <input/InputTransport.h>
42#include <input/InputWindow.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070043
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080044#include <ui/DisplayConfig.h>
Robert Carr1c4c5592018-09-24 13:18:43 -070045#include <ui/Rect.h>
46#include <ui/Region.h>
47
Chris Ye0783e992020-06-02 21:34:49 -070048using android::os::IInputFlinger;
Robert Carr1c4c5592018-09-24 13:18:43 -070049
Vishnu Nair958da932020-08-21 17:12:37 -070050namespace android::test {
Robert Carr1c4c5592018-09-24 13:18:43 -070051
Vishnu Nairde19f852018-12-18 16:11:53 -080052using Transaction = SurfaceComposerClient::Transaction;
53
Robert Carr1c4c5592018-09-24 13:18:43 -070054sp<IInputFlinger> getInputFlinger() {
55 sp<IBinder> input(defaultServiceManager()->getService(
56 String16("inputflinger")));
57 if (input == nullptr) {
58 ALOGE("Failed to link to input service");
59 } else { ALOGE("Linked to input"); }
60 return interface_cast<IInputFlinger>(input);
61}
62
63// We use the top 10 layers as a way to haphazardly place ourselves above anything else.
64static const int LAYER_BASE = INT32_MAX - 10;
Chris Ye6c4243b2020-07-22 12:07:12 -070065static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 5s;
Robert Carr1c4c5592018-09-24 13:18:43 -070066
67class InputSurface {
68public:
Vishnu Nairde19f852018-12-18 16:11:53 -080069 InputSurface(const sp<SurfaceControl> &sc, int width, int height) {
70 mSurfaceControl = sc;
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050071 std::unique_ptr<InputChannel> clientChannel;
72 InputChannel::openInputChannelPair("testchannels", mServerChannel, clientChannel);
73 mClientChannel = std::move(clientChannel);
Robert Carr1c4c5592018-09-24 13:18:43 -070074
75 mInputFlinger = getInputFlinger();
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -050076 mInputFlinger->registerInputChannel(*mServerChannel);
Robert Carr1c4c5592018-09-24 13:18:43 -070077
78 populateInputInfo(width, height);
79
80 mInputConsumer = new InputConsumer(mClientChannel);
81 }
82
Vishnu Nairde19f852018-12-18 16:11:53 -080083 static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient> &scc,
84 int width, int height) {
85 sp<SurfaceControl> surfaceControl =
86 scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */,
Vishnu Nairfa247b12020-02-11 08:58:26 -080087 PIXEL_FORMAT_RGBA_8888,
88 ISurfaceComposerClient::eFXSurfaceEffect);
Vishnu Nairde19f852018-12-18 16:11:53 -080089 return std::make_unique<InputSurface>(surfaceControl, width, height);
90 }
91
92 static std::unique_ptr<InputSurface> makeBufferInputSurface(
93 const sp<SurfaceComposerClient> &scc, int width, int height) {
94 sp<SurfaceControl> surfaceControl =
95 scc->createSurface(String8("Test Buffer Surface"), width, height,
96 PIXEL_FORMAT_RGBA_8888, 0 /* flags */);
97 return std::make_unique<InputSurface>(surfaceControl, width, height);
98 }
99
100 static std::unique_ptr<InputSurface> makeContainerInputSurface(
101 const sp<SurfaceComposerClient> &scc, int width, int height) {
102 sp<SurfaceControl> surfaceControl =
103 scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */,
104 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888,
105 ISurfaceComposerClient::eFXSurfaceContainer);
106 return std::make_unique<InputSurface>(surfaceControl, width, height);
107 }
108
arthurhungb4a0f852020-06-16 11:02:50 +0800109 static std::unique_ptr<InputSurface> makeCursorInputSurface(
110 const sp<SurfaceComposerClient> &scc, int width, int height) {
111 sp<SurfaceControl> surfaceControl =
112 scc->createSurface(String8("Test Cursor Surface"), 0 /* bufHeight */,
113 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888,
114 ISurfaceComposerClient::eCursorWindow);
115 return std::make_unique<InputSurface>(surfaceControl, width, height);
116 }
117
Robert Carr1c4c5592018-09-24 13:18:43 -0700118 InputEvent* consumeEvent() {
119 waitForEventAvailable();
120
121 InputEvent *ev;
122 uint32_t seqId;
123 status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev);
124 if (consumed != OK) {
125 return nullptr;
126 }
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100127 status_t status = mInputConsumer->sendFinishedSignal(seqId, true);
128 EXPECT_EQ(OK, status) << "Could not send finished signal";
Robert Carr1c4c5592018-09-24 13:18:43 -0700129 return ev;
130 }
131
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100132 void assertFocusChange(bool hasFocus) {
133 InputEvent *ev = consumeEvent();
134 ASSERT_NE(ev, nullptr);
135 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType());
136 FocusEvent *focusEvent = static_cast<FocusEvent *>(ev);
137 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
138 }
139
Robert Carr1c4c5592018-09-24 13:18:43 -0700140 void expectTap(int x, int y) {
141 InputEvent* ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100142 ASSERT_NE(ev, nullptr);
143 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700144 MotionEvent* mev = static_cast<MotionEvent*>(ev);
145 EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
146 EXPECT_EQ(x, mev->getX(0));
147 EXPECT_EQ(y, mev->getY(0));
arthurhungb4a0f852020-06-16 11:02:50 +0800148 EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS);
Robert Carr1c4c5592018-09-24 13:18:43 -0700149
150 ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100151 ASSERT_NE(ev, nullptr);
152 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700153 mev = static_cast<MotionEvent*>(ev);
154 EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
arthurhungb4a0f852020-06-16 11:02:50 +0800155 EXPECT_EQ(0, mev->getFlags() & VERIFIED_MOTION_EVENT_FLAGS);
Robert Carr1c4c5592018-09-24 13:18:43 -0700156 }
157
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500158 ~InputSurface() { mInputFlinger->unregisterInputChannel(*mServerChannel); }
Robert Carr1c4c5592018-09-24 13:18:43 -0700159
160 void doTransaction(std::function<void(SurfaceComposerClient::Transaction&,
161 const sp<SurfaceControl>&)> transactionBody) {
162 SurfaceComposerClient::Transaction t;
163 transactionBody(t, mSurfaceControl);
164 t.apply(true);
165 }
166
167 void showAt(int x, int y) {
168 SurfaceComposerClient::Transaction t;
169 t.show(mSurfaceControl);
170 t.setInputWindowInfo(mSurfaceControl, mInputInfo);
171 t.setLayer(mSurfaceControl, LAYER_BASE);
172 t.setPosition(mSurfaceControl, x, y);
173 t.setCrop_legacy(mSurfaceControl, Rect(0, 0, 100, 100));
174 t.setAlpha(mSurfaceControl, 1);
175 t.apply(true);
176 }
177
Vishnu Nair958da932020-08-21 17:12:37 -0700178 void requestFocus() {
179 SurfaceComposerClient::Transaction t;
180 t.setFocusedWindow(mInputInfo.token, nullptr, systemTime(SYSTEM_TIME_MONOTONIC),
181 0 /* displayId */);
182 t.apply(true);
183 }
184
Robert Carr1c4c5592018-09-24 13:18:43 -0700185private:
186 void waitForEventAvailable() {
187 struct pollfd fd;
188
189 fd.fd = mClientChannel->getFd();
190 fd.events = POLLIN;
191 poll(&fd, 1, 3000);
192 }
193
194 void populateInputInfo(int width, int height) {
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700195 mInputInfo.token = mServerChannel->getConnectionToken();
Robert Carr1c4c5592018-09-24 13:18:43 -0700196 mInputInfo.name = "Test info";
Michael Wright44753b12020-07-08 13:48:11 +0100197 mInputInfo.flags = InputWindowInfo::Flag::NOT_TOUCH_MODAL;
198 mInputInfo.type = InputWindowInfo::Type::BASE_APPLICATION;
Siarhei Vishniakouc1ae5562020-06-30 14:22:57 -0500199 mInputInfo.dispatchingTimeout = 5s;
Robert Carre07e1032018-11-26 12:55:53 -0800200 mInputInfo.globalScaleFactor = 1.0;
Vishnu Nair47074b82020-08-14 11:54:47 -0700201 mInputInfo.focusable = true;
Robert Carr1c4c5592018-09-24 13:18:43 -0700202 mInputInfo.hasWallpaper = false;
203 mInputInfo.paused = false;
204
205 mInputInfo.touchableRegion.orSelf(Rect(0, 0, width, height));
206
207 // TODO: Fill in from SF?
208 mInputInfo.ownerPid = 11111;
209 mInputInfo.ownerUid = 11111;
Robert Carr1c4c5592018-09-24 13:18:43 -0700210 mInputInfo.displayId = 0;
Robert Carr740167f2018-10-11 19:03:41 -0700211
212 InputApplicationInfo aInfo;
213 aInfo.token = new BBinder();
214 aInfo.name = "Test app info";
Siarhei Vishniakou70622952020-07-30 11:17:23 -0500215 aInfo.dispatchingTimeoutMillis =
216 std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count();
Robert Carr740167f2018-10-11 19:03:41 -0700217
218 mInputInfo.applicationInfo = aInfo;
Robert Carr1c4c5592018-09-24 13:18:43 -0700219 }
220public:
221 sp<SurfaceControl> mSurfaceControl;
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500222 std::unique_ptr<InputChannel> mServerChannel;
Siarhei Vishniakouce5ab082020-07-09 17:03:21 -0500223 std::shared_ptr<InputChannel> mClientChannel;
Robert Carr1c4c5592018-09-24 13:18:43 -0700224 sp<IInputFlinger> mInputFlinger;
225
226 InputWindowInfo mInputInfo;
227
228 PreallocatedInputEventFactory mInputEventFactory;
229 InputConsumer* mInputConsumer;
230};
231
232class InputSurfacesTest : public ::testing::Test {
233public:
234 InputSurfacesTest() {
235 ProcessState::self()->startThreadPool();
236 }
237
238 void SetUp() {
239 mComposerClient = new SurfaceComposerClient;
240 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
Vishnu Nairde19f852018-12-18 16:11:53 -0800241
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800242 const auto display = mComposerClient->getInternalDisplayToken();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100243 ASSERT_NE(display, nullptr);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800244
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800245 DisplayConfig config;
246 ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayConfig(display, &config));
Vishnu Nairde19f852018-12-18 16:11:53 -0800247
248 // After a new buffer is queued, SurfaceFlinger is notified and will
249 // latch the new buffer on next vsync. Let's heuristically wait for 3
250 // vsyncs.
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800251 mBufferPostDelay = static_cast<int32_t>(1e6 / config.refreshRate) * 3;
Robert Carr1c4c5592018-09-24 13:18:43 -0700252 }
253
254 void TearDown() {
255 mComposerClient->dispose();
256 }
257
258 std::unique_ptr<InputSurface> makeSurface(int width, int height) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800259 return InputSurface::makeColorInputSurface(mComposerClient, width, height);
260 }
261
262 void postBuffer(const sp<SurfaceControl> &layer) {
263 // wait for previous transactions (such as setSize) to complete
264 Transaction().apply(true);
265 ANativeWindow_Buffer buffer = {};
266 EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr));
267 ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost());
268 // Request an empty transaction to get applied synchronously to ensure the buffer is
269 // latched.
270 Transaction().apply(true);
271 usleep(mBufferPostDelay);
Robert Carr1c4c5592018-09-24 13:18:43 -0700272 }
273
274 sp<SurfaceComposerClient> mComposerClient;
Vishnu Nairde19f852018-12-18 16:11:53 -0800275 int32_t mBufferPostDelay;
Robert Carr1c4c5592018-09-24 13:18:43 -0700276};
277
278void injectTap(int x, int y) {
279 char *buf1, *buf2;
280 asprintf(&buf1, "%d", x);
281 asprintf(&buf2, "%d", y);
282 if (fork() == 0) {
283 execlp("input", "input", "tap", buf1, buf2, NULL);
284 }
285}
286
287TEST_F(InputSurfacesTest, can_receive_input) {
288 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
289 surface->showAt(100, 100);
290
291 injectTap(101, 101);
292
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100293 EXPECT_NE(surface->consumeEvent(), nullptr);
Robert Carr1c4c5592018-09-24 13:18:43 -0700294}
295
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100296/**
297 * Set up two surfaces side-by-side. Tap each surface.
298 * Next, swap the positions of the two surfaces. Inject tap into the two
299 * original locations. Ensure that the tap is received by the surfaces in the
300 * reverse order.
301 */
Robert Carr1c4c5592018-09-24 13:18:43 -0700302TEST_F(InputSurfacesTest, input_respects_positioning) {
303 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
304 surface->showAt(100, 100);
305
306 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
307 surface2->showAt(200, 200);
308
309 injectTap(201, 201);
310 surface2->expectTap(1, 1);
311
312 injectTap(101, 101);
313 surface->expectTap(1, 1);
314
315 surface2->doTransaction([](auto &t, auto &sc) {
316 t.setPosition(sc, 100, 100);
317 });
318 surface->doTransaction([](auto &t, auto &sc) {
319 t.setPosition(sc, 200, 200);
320 });
321
322 injectTap(101, 101);
323 surface2->expectTap(1, 1);
324
325 injectTap(201, 201);
326 surface->expectTap(1, 1);
327}
328
329TEST_F(InputSurfacesTest, input_respects_layering) {
330 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
331 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
332
333 surface->showAt(10, 10);
334 surface2->showAt(10, 10);
335
336 surface->doTransaction([](auto &t, auto &sc) {
337 t.setLayer(sc, LAYER_BASE + 1);
338 });
339
340 injectTap(11, 11);
341 surface->expectTap(1, 1);
342
343 surface2->doTransaction([](auto &t, auto &sc) {
344 t.setLayer(sc, LAYER_BASE + 1);
345 });
346
347 injectTap(11, 11);
348 surface2->expectTap(1, 1);
349
350 surface2->doTransaction([](auto &t, auto &sc) {
351 t.hide(sc);
352 });
353
354 injectTap(11, 11);
355 surface->expectTap(1, 1);
356}
357
Vishnu Nairde19f852018-12-18 16:11:53 -0800358// Surface Insets are set to offset the client content and draw a border around the client surface
359// (such as shadows in dialogs). Inputs sent to the client are offset such that 0,0 is the start
360// of the client content.
361TEST_F(InputSurfacesTest, input_respects_surface_insets) {
362 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
363 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
364 bgSurface->showAt(100, 100);
365
366 fgSurface->mInputInfo.surfaceInset = 5;
367 fgSurface->showAt(100, 100);
368
369 injectTap(106, 106);
370 fgSurface->expectTap(1, 1);
371
372 injectTap(101, 101);
373 bgSurface->expectTap(1, 1);
374}
375
376// Ensure a surface whose insets are cropped, handles the touch offset correctly. ref:b/120413463
377TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) {
378 std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100);
379 std::unique_ptr<InputSurface> childSurface = makeSurface(100, 100);
380 parentSurface->showAt(100, 100);
381
382 childSurface->mInputInfo.surfaceInset = 10;
383 childSurface->showAt(100, 100);
384
385 childSurface->doTransaction([&](auto &t, auto &sc) {
386 t.setPosition(sc, -5, -5);
387 t.reparent(sc, parentSurface->mSurfaceControl->getHandle());
388 });
389
390 injectTap(106, 106);
391 childSurface->expectTap(1, 1);
392
393 injectTap(101, 101);
394 parentSurface->expectTap(1, 1);
395}
396
Arthur Hung118b1142019-05-08 21:25:59 +0800397// Ensure a surface whose insets are scaled, handles the touch offset correctly.
398TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) {
399 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
400 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
401 bgSurface->showAt(100, 100);
402
403 fgSurface->mInputInfo.surfaceInset = 5;
404 fgSurface->showAt(100, 100);
405
406 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); });
407
408 // expect = touch / scale - inset
409 injectTap(112, 124);
410 fgSurface->expectTap(1, 1);
411
412 injectTap(101, 101);
413 bgSurface->expectTap(1, 1);
414}
415
Ady Abraham282f1d72019-07-24 18:05:56 -0700416TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) {
417 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
418 // In case we pass the very big inset without any checking.
419 fgSurface->mInputInfo.surfaceInset = INT32_MAX;
420 fgSurface->showAt(100, 100);
421
422 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); });
423
424 // expect no crash for overflow, and inset size to be clamped to surface size
425 injectTap(202, 202);
426 fgSurface->expectTap(1, 1);
427}
428
Vishnu Nairde19f852018-12-18 16:11:53 -0800429// Ensure we ignore transparent region when getting screen bounds when positioning input frame.
430TEST_F(InputSurfacesTest, input_ignores_transparent_region) {
431 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
432 surface->doTransaction([](auto &t, auto &sc) {
433 Region transparentRegion(Rect(0, 0, 10, 10));
434 t.setTransparentRegionHint(sc, transparentRegion);
435 });
436 surface->showAt(100, 100);
437 injectTap(101, 101);
438 surface->expectTap(1, 1);
439}
440
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700441// TODO(b/139494112) update tests once we define expected behavior
442// Ensure we still send input to the surface regardless of surface visibility changes due to the
443// first buffer being submitted or alpha changes.
444// Original bug ref: b/120839715
445TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800446 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
447 std::unique_ptr<InputSurface> bufferSurface =
448 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
449
450 bgSurface->showAt(10, 10);
451 bufferSurface->showAt(10, 10);
452
453 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700454 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800455
456 postBuffer(bufferSurface->mSurfaceControl);
457 injectTap(11, 11);
458 bufferSurface->expectTap(1, 1);
459}
460
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700461TEST_F(InputSurfacesTest, input_ignores_buffer_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800462 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
463 std::unique_ptr<InputSurface> bufferSurface =
464 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
465 postBuffer(bufferSurface->mSurfaceControl);
466
467 bgSurface->showAt(10, 10);
468 bufferSurface->showAt(10, 10);
469
470 injectTap(11, 11);
471 bufferSurface->expectTap(1, 1);
472
473 bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
474
475 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700476 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800477}
478
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700479TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800480 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
481 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
482
483 bgSurface->showAt(10, 10);
484 fgSurface->showAt(10, 10);
485
486 injectTap(11, 11);
487 fgSurface->expectTap(1, 1);
488
489 fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
490
491 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700492 fgSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800493}
494
495TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) {
496 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
497 std::unique_ptr<InputSurface> containerSurface =
498 InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
499
500 bgSurface->showAt(10, 10);
501 containerSurface->showAt(10, 10);
502
503 injectTap(11, 11);
504 containerSurface->expectTap(1, 1);
505
506 containerSurface->doTransaction([](auto &t, auto &sc) { t.hide(sc); });
507
508 injectTap(11, 11);
509 bgSurface->expectTap(1, 1);
510}
chaviwfbe5d9c2018-12-26 12:23:37 -0800511
Arthur Hungd20b2702019-01-14 18:16:16 +0800512TEST_F(InputSurfacesTest, input_respects_outscreen) {
513 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
514 surface->showAt(-1, -1);
515
516 injectTap(0, 0);
517 surface->expectTap(1, 1);
518}
arthurhungb4a0f852020-06-16 11:02:50 +0800519
520TEST_F(InputSurfacesTest, input_ignores_cursor_layer) {
521 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
522 std::unique_ptr<InputSurface> cursorSurface =
523 InputSurface::makeCursorInputSurface(mComposerClient, 10, 10);
524
525 surface->showAt(10, 10);
arthurhungb4a0f852020-06-16 11:02:50 +0800526 cursorSurface->showAt(10, 10);
527
528 injectTap(11, 11);
529 surface->expectTap(1, 1);
530}
Vishnu Nair958da932020-08-21 17:12:37 -0700531
532TEST_F(InputSurfacesTest, can_be_focused) {
533 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
534 surface->showAt(100, 100);
535 surface->requestFocus();
536
537 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700538}
Vishnu Nair958da932020-08-21 17:12:37 -0700539} // namespace android::test