blob: c59afba87c900f70e95094125d357deb6faa0d49 [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
39#include <input/InputWindow.h>
40#include <input/IInputFlinger.h>
41#include <input/InputTransport.h>
42#include <input/Input.h>
43
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
48
49namespace android {
50namespace test {
51
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;
65
66class InputSurface {
67public:
Vishnu Nairde19f852018-12-18 16:11:53 -080068 InputSurface(const sp<SurfaceControl> &sc, int width, int height) {
69 mSurfaceControl = sc;
Robert Carr1c4c5592018-09-24 13:18:43 -070070
71 InputChannel::openInputChannelPair("testchannels", mServerChannel, mClientChannel);
Robert Carr1c4c5592018-09-24 13:18:43 -070072
73 mInputFlinger = getInputFlinger();
74 mInputFlinger->registerInputChannel(mServerChannel);
75
76 populateInputInfo(width, height);
77
78 mInputConsumer = new InputConsumer(mClientChannel);
79 }
80
Vishnu Nairde19f852018-12-18 16:11:53 -080081 static std::unique_ptr<InputSurface> makeColorInputSurface(const sp<SurfaceComposerClient> &scc,
82 int width, int height) {
83 sp<SurfaceControl> surfaceControl =
84 scc->createSurface(String8("Test Surface"), 0 /* bufHeight */, 0 /* bufWidth */,
Vishnu Nairfa247b12020-02-11 08:58:26 -080085 PIXEL_FORMAT_RGBA_8888,
86 ISurfaceComposerClient::eFXSurfaceEffect);
Vishnu Nairde19f852018-12-18 16:11:53 -080087 return std::make_unique<InputSurface>(surfaceControl, width, height);
88 }
89
90 static std::unique_ptr<InputSurface> makeBufferInputSurface(
91 const sp<SurfaceComposerClient> &scc, int width, int height) {
92 sp<SurfaceControl> surfaceControl =
93 scc->createSurface(String8("Test Buffer Surface"), width, height,
94 PIXEL_FORMAT_RGBA_8888, 0 /* flags */);
95 return std::make_unique<InputSurface>(surfaceControl, width, height);
96 }
97
98 static std::unique_ptr<InputSurface> makeContainerInputSurface(
99 const sp<SurfaceComposerClient> &scc, int width, int height) {
100 sp<SurfaceControl> surfaceControl =
101 scc->createSurface(String8("Test Container Surface"), 0 /* bufHeight */,
102 0 /* bufWidth */, PIXEL_FORMAT_RGBA_8888,
103 ISurfaceComposerClient::eFXSurfaceContainer);
104 return std::make_unique<InputSurface>(surfaceControl, width, height);
105 }
106
Robert Carr1c4c5592018-09-24 13:18:43 -0700107 InputEvent* consumeEvent() {
108 waitForEventAvailable();
109
110 InputEvent *ev;
111 uint32_t seqId;
112 status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev);
113 if (consumed != OK) {
114 return nullptr;
115 }
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100116 status_t status = mInputConsumer->sendFinishedSignal(seqId, true);
117 EXPECT_EQ(OK, status) << "Could not send finished signal";
Robert Carr1c4c5592018-09-24 13:18:43 -0700118 return ev;
119 }
120
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100121 void assertFocusChange(bool hasFocus) {
122 InputEvent *ev = consumeEvent();
123 ASSERT_NE(ev, nullptr);
124 ASSERT_EQ(AINPUT_EVENT_TYPE_FOCUS, ev->getType());
125 FocusEvent *focusEvent = static_cast<FocusEvent *>(ev);
126 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
127 }
128
Robert Carr1c4c5592018-09-24 13:18:43 -0700129 void expectTap(int x, int y) {
130 InputEvent* ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100131 ASSERT_NE(ev, nullptr);
132 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700133 MotionEvent* mev = static_cast<MotionEvent*>(ev);
134 EXPECT_EQ(AMOTION_EVENT_ACTION_DOWN, mev->getAction());
135 EXPECT_EQ(x, mev->getX(0));
136 EXPECT_EQ(y, mev->getY(0));
137
138 ev = consumeEvent();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100139 ASSERT_NE(ev, nullptr);
140 ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, ev->getType());
Robert Carr1c4c5592018-09-24 13:18:43 -0700141 mev = static_cast<MotionEvent*>(ev);
142 EXPECT_EQ(AMOTION_EVENT_ACTION_UP, mev->getAction());
143 }
144
145 ~InputSurface() {
146 mInputFlinger->unregisterInputChannel(mServerChannel);
147 }
148
149 void doTransaction(std::function<void(SurfaceComposerClient::Transaction&,
150 const sp<SurfaceControl>&)> transactionBody) {
151 SurfaceComposerClient::Transaction t;
152 transactionBody(t, mSurfaceControl);
153 t.apply(true);
154 }
155
156 void showAt(int x, int y) {
157 SurfaceComposerClient::Transaction t;
158 t.show(mSurfaceControl);
159 t.setInputWindowInfo(mSurfaceControl, mInputInfo);
160 t.setLayer(mSurfaceControl, LAYER_BASE);
161 t.setPosition(mSurfaceControl, x, y);
162 t.setCrop_legacy(mSurfaceControl, Rect(0, 0, 100, 100));
163 t.setAlpha(mSurfaceControl, 1);
164 t.apply(true);
165 }
166
167private:
168 void waitForEventAvailable() {
169 struct pollfd fd;
170
171 fd.fd = mClientChannel->getFd();
172 fd.events = POLLIN;
173 poll(&fd, 1, 3000);
174 }
175
176 void populateInputInfo(int width, int height) {
Siarhei Vishniakou26d3cfb2019-10-15 17:02:32 -0700177 mInputInfo.token = mServerChannel->getConnectionToken();
Robert Carr1c4c5592018-09-24 13:18:43 -0700178 mInputInfo.name = "Test info";
179 mInputInfo.layoutParamsFlags = InputWindowInfo::FLAG_NOT_TOUCH_MODAL;
180 mInputInfo.layoutParamsType = InputWindowInfo::TYPE_BASE_APPLICATION;
181 mInputInfo.dispatchingTimeout = 100000;
Robert Carre07e1032018-11-26 12:55:53 -0800182 mInputInfo.globalScaleFactor = 1.0;
Robert Carr1c4c5592018-09-24 13:18:43 -0700183 mInputInfo.canReceiveKeys = true;
184 mInputInfo.hasFocus = true;
185 mInputInfo.hasWallpaper = false;
186 mInputInfo.paused = false;
187
188 mInputInfo.touchableRegion.orSelf(Rect(0, 0, width, height));
189
190 // TODO: Fill in from SF?
191 mInputInfo.ownerPid = 11111;
192 mInputInfo.ownerUid = 11111;
193 mInputInfo.inputFeatures = 0;
194 mInputInfo.displayId = 0;
Robert Carr740167f2018-10-11 19:03:41 -0700195
196 InputApplicationInfo aInfo;
197 aInfo.token = new BBinder();
198 aInfo.name = "Test app info";
199 aInfo.dispatchingTimeout = 100000;
200
201 mInputInfo.applicationInfo = aInfo;
Robert Carr1c4c5592018-09-24 13:18:43 -0700202 }
203public:
204 sp<SurfaceControl> mSurfaceControl;
205 sp<InputChannel> mServerChannel, mClientChannel;
206 sp<IInputFlinger> mInputFlinger;
207
208 InputWindowInfo mInputInfo;
209
210 PreallocatedInputEventFactory mInputEventFactory;
211 InputConsumer* mInputConsumer;
212};
213
214class InputSurfacesTest : public ::testing::Test {
215public:
216 InputSurfacesTest() {
217 ProcessState::self()->startThreadPool();
218 }
219
220 void SetUp() {
221 mComposerClient = new SurfaceComposerClient;
222 ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
Vishnu Nairde19f852018-12-18 16:11:53 -0800223
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800224 const auto display = mComposerClient->getInternalDisplayToken();
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100225 ASSERT_NE(display, nullptr);
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800226
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800227 DisplayConfig config;
228 ASSERT_EQ(NO_ERROR, mComposerClient->getActiveDisplayConfig(display, &config));
Vishnu Nairde19f852018-12-18 16:11:53 -0800229
230 // After a new buffer is queued, SurfaceFlinger is notified and will
231 // latch the new buffer on next vsync. Let's heuristically wait for 3
232 // vsyncs.
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -0800233 mBufferPostDelay = static_cast<int32_t>(1e6 / config.refreshRate) * 3;
Robert Carr1c4c5592018-09-24 13:18:43 -0700234 }
235
236 void TearDown() {
237 mComposerClient->dispose();
238 }
239
240 std::unique_ptr<InputSurface> makeSurface(int width, int height) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800241 return InputSurface::makeColorInputSurface(mComposerClient, width, height);
242 }
243
244 void postBuffer(const sp<SurfaceControl> &layer) {
245 // wait for previous transactions (such as setSize) to complete
246 Transaction().apply(true);
247 ANativeWindow_Buffer buffer = {};
248 EXPECT_EQ(NO_ERROR, layer->getSurface()->lock(&buffer, nullptr));
249 ASSERT_EQ(NO_ERROR, layer->getSurface()->unlockAndPost());
250 // Request an empty transaction to get applied synchronously to ensure the buffer is
251 // latched.
252 Transaction().apply(true);
253 usleep(mBufferPostDelay);
Robert Carr1c4c5592018-09-24 13:18:43 -0700254 }
255
256 sp<SurfaceComposerClient> mComposerClient;
Vishnu Nairde19f852018-12-18 16:11:53 -0800257 int32_t mBufferPostDelay;
Robert Carr1c4c5592018-09-24 13:18:43 -0700258};
259
260void injectTap(int x, int y) {
261 char *buf1, *buf2;
262 asprintf(&buf1, "%d", x);
263 asprintf(&buf2, "%d", y);
264 if (fork() == 0) {
265 execlp("input", "input", "tap", buf1, buf2, NULL);
266 }
267}
268
269TEST_F(InputSurfacesTest, can_receive_input) {
270 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
271 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100272 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700273
274 injectTap(101, 101);
275
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100276 EXPECT_NE(surface->consumeEvent(), nullptr);
Robert Carr1c4c5592018-09-24 13:18:43 -0700277}
278
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100279/**
280 * Set up two surfaces side-by-side. Tap each surface.
281 * Next, swap the positions of the two surfaces. Inject tap into the two
282 * original locations. Ensure that the tap is received by the surfaces in the
283 * reverse order.
284 */
Robert Carr1c4c5592018-09-24 13:18:43 -0700285TEST_F(InputSurfacesTest, input_respects_positioning) {
286 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
287 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100288 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700289
290 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
291 surface2->showAt(200, 200);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100292 surface->assertFocusChange(false);
293 surface2->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700294
295 injectTap(201, 201);
296 surface2->expectTap(1, 1);
297
298 injectTap(101, 101);
299 surface->expectTap(1, 1);
300
301 surface2->doTransaction([](auto &t, auto &sc) {
302 t.setPosition(sc, 100, 100);
303 });
304 surface->doTransaction([](auto &t, auto &sc) {
305 t.setPosition(sc, 200, 200);
306 });
307
308 injectTap(101, 101);
309 surface2->expectTap(1, 1);
310
311 injectTap(201, 201);
312 surface->expectTap(1, 1);
313}
314
315TEST_F(InputSurfacesTest, input_respects_layering) {
316 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
317 std::unique_ptr<InputSurface> surface2 = makeSurface(100, 100);
318
319 surface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100320 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700321 surface2->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100322 surface->assertFocusChange(false);
323 surface2->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700324
325 surface->doTransaction([](auto &t, auto &sc) {
326 t.setLayer(sc, LAYER_BASE + 1);
327 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100328 surface2->assertFocusChange(false);
329 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700330
331 injectTap(11, 11);
332 surface->expectTap(1, 1);
333
334 surface2->doTransaction([](auto &t, auto &sc) {
335 t.setLayer(sc, LAYER_BASE + 1);
336 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100337 surface2->assertFocusChange(true);
338 surface->assertFocusChange(false);
Robert Carr1c4c5592018-09-24 13:18:43 -0700339
340 injectTap(11, 11);
341 surface2->expectTap(1, 1);
342
343 surface2->doTransaction([](auto &t, auto &sc) {
344 t.hide(sc);
345 });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100346 surface2->assertFocusChange(false);
347 surface->assertFocusChange(true);
Robert Carr1c4c5592018-09-24 13:18:43 -0700348
349 injectTap(11, 11);
350 surface->expectTap(1, 1);
351}
352
Vishnu Nairde19f852018-12-18 16:11:53 -0800353// Surface Insets are set to offset the client content and draw a border around the client surface
354// (such as shadows in dialogs). Inputs sent to the client are offset such that 0,0 is the start
355// of the client content.
356TEST_F(InputSurfacesTest, input_respects_surface_insets) {
357 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
358 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
359 bgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100360 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800361
362 fgSurface->mInputInfo.surfaceInset = 5;
363 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100364 fgSurface->assertFocusChange(true);
365 bgSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800366
367 injectTap(106, 106);
368 fgSurface->expectTap(1, 1);
369
370 injectTap(101, 101);
371 bgSurface->expectTap(1, 1);
372}
373
374// Ensure a surface whose insets are cropped, handles the touch offset correctly. ref:b/120413463
375TEST_F(InputSurfacesTest, input_respects_cropped_surface_insets) {
376 std::unique_ptr<InputSurface> parentSurface = makeSurface(100, 100);
377 std::unique_ptr<InputSurface> childSurface = makeSurface(100, 100);
378 parentSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100379 parentSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800380
381 childSurface->mInputInfo.surfaceInset = 10;
382 childSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100383 childSurface->assertFocusChange(true);
384 parentSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800385
386 childSurface->doTransaction([&](auto &t, auto &sc) {
387 t.setPosition(sc, -5, -5);
388 t.reparent(sc, parentSurface->mSurfaceControl->getHandle());
389 });
390
391 injectTap(106, 106);
392 childSurface->expectTap(1, 1);
393
394 injectTap(101, 101);
395 parentSurface->expectTap(1, 1);
396}
397
Arthur Hung118b1142019-05-08 21:25:59 +0800398// Ensure a surface whose insets are scaled, handles the touch offset correctly.
399TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets) {
400 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
401 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
402 bgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100403 bgSurface->assertFocusChange(true);
Arthur Hung118b1142019-05-08 21:25:59 +0800404
405 fgSurface->mInputInfo.surfaceInset = 5;
406 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100407 bgSurface->assertFocusChange(false);
408 fgSurface->assertFocusChange(true);
Arthur Hung118b1142019-05-08 21:25:59 +0800409
410 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 4.0); });
411
412 // expect = touch / scale - inset
413 injectTap(112, 124);
414 fgSurface->expectTap(1, 1);
415
416 injectTap(101, 101);
417 bgSurface->expectTap(1, 1);
418}
419
Ady Abraham282f1d72019-07-24 18:05:56 -0700420TEST_F(InputSurfacesTest, input_respects_scaled_surface_insets_overflow) {
421 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
422 // In case we pass the very big inset without any checking.
423 fgSurface->mInputInfo.surfaceInset = INT32_MAX;
424 fgSurface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100425 fgSurface->assertFocusChange(true);
Ady Abraham282f1d72019-07-24 18:05:56 -0700426
427 fgSurface->doTransaction([&](auto &t, auto &sc) { t.setMatrix(sc, 2.0, 0, 0, 2.0); });
428
429 // expect no crash for overflow, and inset size to be clamped to surface size
430 injectTap(202, 202);
431 fgSurface->expectTap(1, 1);
432}
433
Vishnu Nairde19f852018-12-18 16:11:53 -0800434// Ensure we ignore transparent region when getting screen bounds when positioning input frame.
435TEST_F(InputSurfacesTest, input_ignores_transparent_region) {
436 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
437 surface->doTransaction([](auto &t, auto &sc) {
438 Region transparentRegion(Rect(0, 0, 10, 10));
439 t.setTransparentRegionHint(sc, transparentRegion);
440 });
441 surface->showAt(100, 100);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100442 surface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800443 injectTap(101, 101);
444 surface->expectTap(1, 1);
445}
446
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700447// TODO(b/139494112) update tests once we define expected behavior
448// Ensure we still send input to the surface regardless of surface visibility changes due to the
449// first buffer being submitted or alpha changes.
450// Original bug ref: b/120839715
451TEST_F(InputSurfacesTest, input_ignores_buffer_layer_buffer) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800452 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
453 std::unique_ptr<InputSurface> bufferSurface =
454 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
455
456 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100457 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800458 bufferSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100459 bgSurface->assertFocusChange(false);
460 bufferSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800461
462 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700463 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800464
465 postBuffer(bufferSurface->mSurfaceControl);
466 injectTap(11, 11);
467 bufferSurface->expectTap(1, 1);
468}
469
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700470TEST_F(InputSurfacesTest, input_ignores_buffer_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800471 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
472 std::unique_ptr<InputSurface> bufferSurface =
473 InputSurface::makeBufferInputSurface(mComposerClient, 100, 100);
474 postBuffer(bufferSurface->mSurfaceControl);
475
476 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100477 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800478 bufferSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100479 bufferSurface->assertFocusChange(true);
480 bgSurface->assertFocusChange(false);
Vishnu Nairde19f852018-12-18 16:11:53 -0800481
482 injectTap(11, 11);
483 bufferSurface->expectTap(1, 1);
484
485 bufferSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
486
487 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700488 bufferSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800489}
490
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700491TEST_F(InputSurfacesTest, input_ignores_color_layer_alpha) {
Vishnu Nairde19f852018-12-18 16:11:53 -0800492 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
493 std::unique_ptr<InputSurface> fgSurface = makeSurface(100, 100);
494
495 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100496 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800497 fgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100498 bgSurface->assertFocusChange(false);
499 fgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800500
501 injectTap(11, 11);
502 fgSurface->expectTap(1, 1);
503
504 fgSurface->doTransaction([](auto &t, auto &sc) { t.setAlpha(sc, 0.0); });
505
506 injectTap(11, 11);
Vishnu Nairf8678ba2019-10-11 18:11:26 -0700507 fgSurface->expectTap(1, 1);
Vishnu Nairde19f852018-12-18 16:11:53 -0800508}
509
510TEST_F(InputSurfacesTest, input_respects_container_layer_visiblity) {
511 std::unique_ptr<InputSurface> bgSurface = makeSurface(100, 100);
512 std::unique_ptr<InputSurface> containerSurface =
513 InputSurface::makeContainerInputSurface(mComposerClient, 100, 100);
514
515 bgSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100516 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800517 containerSurface->showAt(10, 10);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100518 bgSurface->assertFocusChange(false);
519 containerSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800520
521 injectTap(11, 11);
522 containerSurface->expectTap(1, 1);
523
524 containerSurface->doTransaction([](auto &t, auto &sc) { t.hide(sc); });
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100525 containerSurface->assertFocusChange(false);
526 bgSurface->assertFocusChange(true);
Vishnu Nairde19f852018-12-18 16:11:53 -0800527
528 injectTap(11, 11);
529 bgSurface->expectTap(1, 1);
530}
chaviwfbe5d9c2018-12-26 12:23:37 -0800531
Arthur Hungd20b2702019-01-14 18:16:16 +0800532TEST_F(InputSurfacesTest, input_respects_outscreen) {
533 std::unique_ptr<InputSurface> surface = makeSurface(100, 100);
534 surface->showAt(-1, -1);
Siarhei Vishniakouf1035d42019-09-20 16:32:01 +0100535 surface->assertFocusChange(true);
Arthur Hungd20b2702019-01-14 18:16:16 +0800536
537 injectTap(0, 0);
538 surface->expectTap(1, 1);
539}
Robert Carr1c4c5592018-09-24 13:18:43 -0700540}
541}