1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <flag_macros.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <input/PointerController.h>
#include <input/SpriteController.h>
#include <atomic>
#include <thread>
#include "input/Input.h"
#include "mocks/MockSprite.h"
#include "mocks/MockSpriteController.h"
namespace android {
enum TestCursorType {
CURSOR_TYPE_DEFAULT = 0,
CURSOR_TYPE_HOVER,
CURSOR_TYPE_TOUCH,
CURSOR_TYPE_ANCHOR,
CURSOR_TYPE_ADDITIONAL,
CURSOR_TYPE_ADDITIONAL_ANIM,
CURSOR_TYPE_STYLUS,
CURSOR_TYPE_CUSTOM = -1,
};
static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION;
using ::testing::AllOf;
using ::testing::Field;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::Test;
std::pair<float, float> getHotSpotCoordinatesForType(int32_t type) {
return std::make_pair(type * 10, type * 10 + 5);
}
class MockPointerControllerPolicyInterface : public PointerControllerPolicyInterface {
public:
virtual void loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId displayId) override;
virtual void loadPointerResources(PointerResources* outResources,
ui::LogicalDisplayId displayId) override;
virtual void loadAdditionalMouseResources(
std::map<PointerIconStyle, SpriteIcon>* outResources,
std::map<PointerIconStyle, PointerAnimation>* outAnimationResources,
ui::LogicalDisplayId displayId) override;
virtual PointerIconStyle getDefaultPointerIconId() override;
virtual PointerIconStyle getDefaultStylusIconId() override;
virtual PointerIconStyle getCustomPointerIconId() override;
bool allResourcesAreLoaded();
bool noResourcesAreLoaded();
private:
void loadPointerIconForType(SpriteIcon* icon, int32_t cursorType);
bool pointerIconLoaded{false};
bool pointerResourcesLoaded{false};
bool additionalMouseResourcesLoaded{false};
};
void MockPointerControllerPolicyInterface::loadPointerIcon(SpriteIcon* icon, ui::LogicalDisplayId) {
loadPointerIconForType(icon, CURSOR_TYPE_DEFAULT);
pointerIconLoaded = true;
}
void MockPointerControllerPolicyInterface::loadPointerResources(PointerResources* outResources,
ui::LogicalDisplayId) {
loadPointerIconForType(&outResources->spotHover, CURSOR_TYPE_HOVER);
loadPointerIconForType(&outResources->spotTouch, CURSOR_TYPE_TOUCH);
loadPointerIconForType(&outResources->spotAnchor, CURSOR_TYPE_ANCHOR);
pointerResourcesLoaded = true;
}
void MockPointerControllerPolicyInterface::loadAdditionalMouseResources(
std::map<PointerIconStyle, SpriteIcon>* outResources,
std::map<PointerIconStyle, PointerAnimation>* outAnimationResources, ui::LogicalDisplayId) {
SpriteIcon icon;
PointerAnimation anim;
// CURSOR_TYPE_ADDITIONAL doesn't have animation resource.
int32_t cursorType = CURSOR_TYPE_ADDITIONAL;
loadPointerIconForType(&icon, cursorType);
(*outResources)[static_cast<PointerIconStyle>(cursorType)] = icon;
// CURSOR_TYPE_ADDITIONAL_ANIM has animation resource.
cursorType = CURSOR_TYPE_ADDITIONAL_ANIM;
loadPointerIconForType(&icon, cursorType);
anim.animationFrames.push_back(icon);
anim.durationPerFrame = 10;
(*outResources)[static_cast<PointerIconStyle>(cursorType)] = icon;
(*outAnimationResources)[static_cast<PointerIconStyle>(cursorType)] = anim;
// CURSOR_TYPE_STYLUS doesn't have animation resource.
cursorType = CURSOR_TYPE_STYLUS;
loadPointerIconForType(&icon, cursorType);
(*outResources)[static_cast<PointerIconStyle>(cursorType)] = icon;
additionalMouseResourcesLoaded = true;
}
PointerIconStyle MockPointerControllerPolicyInterface::getDefaultPointerIconId() {
return static_cast<PointerIconStyle>(CURSOR_TYPE_DEFAULT);
}
PointerIconStyle MockPointerControllerPolicyInterface::getDefaultStylusIconId() {
return static_cast<PointerIconStyle>(CURSOR_TYPE_STYLUS);
}
PointerIconStyle MockPointerControllerPolicyInterface::getCustomPointerIconId() {
return static_cast<PointerIconStyle>(CURSOR_TYPE_CUSTOM);
}
bool MockPointerControllerPolicyInterface::allResourcesAreLoaded() {
return pointerIconLoaded && pointerResourcesLoaded && additionalMouseResourcesLoaded;
}
bool MockPointerControllerPolicyInterface::noResourcesAreLoaded() {
return !(pointerIconLoaded || pointerResourcesLoaded || additionalMouseResourcesLoaded);
}
void MockPointerControllerPolicyInterface::loadPointerIconForType(SpriteIcon* icon, int32_t type) {
icon->style = static_cast<PointerIconStyle>(type);
std::pair<float, float> hotSpot = getHotSpotCoordinatesForType(type);
icon->hotSpotX = hotSpot.first;
icon->hotSpotY = hotSpot.second;
}
class TestPointerController : public PointerController {
public:
TestPointerController(sp<android::gui::WindowInfosListener>& registeredListener,
sp<PointerControllerPolicyInterface> policy, const sp<Looper>& looper,
SpriteController& spriteController)
: PointerController(
policy, looper, spriteController,
[®isteredListener](const sp<android::gui::WindowInfosListener>& listener)
-> std::vector<gui::DisplayInfo> {
// Register listener
registeredListener = listener;
return {};
},
[®isteredListener](const sp<android::gui::WindowInfosListener>& listener) {
// Unregister listener
if (registeredListener == listener) registeredListener = nullptr;
}) {}
~TestPointerController() override {}
};
class PointerControllerTest : public Test {
private:
void loopThread();
std::atomic<bool> mRunning = true;
class MyLooper : public Looper {
public:
MyLooper() : Looper(false) {}
~MyLooper() = default;
};
protected:
PointerControllerTest();
~PointerControllerTest();
void ensureDisplayViewportIsSet(ui::LogicalDisplayId displayId = ui::LogicalDisplayId::DEFAULT);
sp<MockSprite> mPointerSprite;
sp<MockPointerControllerPolicyInterface> mPolicy;
std::unique_ptr<MockSpriteController> mSpriteController;
std::shared_ptr<PointerController> mPointerController;
sp<android::gui::WindowInfosListener> mRegisteredListener;
sp<MyLooper> mLooper;
private:
std::thread mThread;
};
PointerControllerTest::PointerControllerTest()
: mPointerSprite(new NiceMock<MockSprite>),
mLooper(new MyLooper),
mThread(&PointerControllerTest::loopThread, this) {
mSpriteController.reset(new NiceMock<MockSpriteController>(mLooper));
mPolicy = new MockPointerControllerPolicyInterface();
EXPECT_CALL(*mSpriteController, createSprite())
.WillOnce(Return(mPointerSprite));
mPointerController = std::make_unique<TestPointerController>(mRegisteredListener, mPolicy,
mLooper, *mSpriteController);
}
PointerControllerTest::~PointerControllerTest() {
mPointerController.reset();
mRunning.store(false, std::memory_order_relaxed);
mThread.join();
}
void PointerControllerTest::ensureDisplayViewportIsSet(ui::LogicalDisplayId displayId) {
DisplayViewport viewport;
viewport.displayId = displayId;
viewport.logicalRight = 1600;
viewport.logicalBottom = 1200;
viewport.physicalRight = 800;
viewport.physicalBottom = 600;
viewport.deviceWidth = 400;
viewport.deviceHeight = 300;
mPointerController->setDisplayViewport(viewport);
}
void PointerControllerTest::loopThread() {
Looper::setForThread(mLooper);
while (mRunning.load(std::memory_order_relaxed)) {
mLooper->pollOnce(100);
}
}
TEST_F(PointerControllerTest, useDefaultCursorTypeByDefault) {
ensureDisplayViewportIsSet();
mPointerController->unfade(PointerController::Transition::IMMEDIATE);
std::pair<float, float> hotspot = getHotSpotCoordinatesForType(CURSOR_TYPE_DEFAULT);
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
EXPECT_CALL(*mPointerSprite,
setIcon(AllOf(Field(&SpriteIcon::style,
static_cast<PointerIconStyle>(CURSOR_TYPE_DEFAULT)),
Field(&SpriteIcon::hotSpotX, hotspot.first),
Field(&SpriteIcon::hotSpotY, hotspot.second))));
mPointerController->reloadPointerResources();
}
TEST_F(PointerControllerTest, useStylusTypeForStylusHover) {
ensureDisplayViewportIsSet();
mPointerController->setPresentation(PointerController::Presentation::STYLUS_HOVER);
mPointerController->unfade(PointerController::Transition::IMMEDIATE);
std::pair<float, float> hotspot = getHotSpotCoordinatesForType(CURSOR_TYPE_STYLUS);
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
EXPECT_CALL(*mPointerSprite,
setIcon(AllOf(Field(&SpriteIcon::style,
static_cast<PointerIconStyle>(CURSOR_TYPE_STYLUS)),
Field(&SpriteIcon::hotSpotX, hotspot.first),
Field(&SpriteIcon::hotSpotY, hotspot.second))));
mPointerController->reloadPointerResources();
}
TEST_F(PointerControllerTest, setPresentationBeforeDisplayViewportDoesNotLoadResources) {
// Setting the presentation mode before a display viewport is set will not load any resources.
mPointerController->setPresentation(PointerController::Presentation::POINTER);
ASSERT_TRUE(mPolicy->noResourcesAreLoaded());
// When the display is set, then the resources are loaded.
ensureDisplayViewportIsSet();
ASSERT_TRUE(mPolicy->allResourcesAreLoaded());
}
TEST_F(PointerControllerTest, updatePointerIconWithChoreographer) {
// When PointerChoreographer is enabled, the presentation mode is set before the viewport.
mPointerController->setPresentation(PointerController::Presentation::POINTER);
ensureDisplayViewportIsSet();
mPointerController->unfade(PointerController::Transition::IMMEDIATE);
int32_t type = CURSOR_TYPE_ADDITIONAL;
std::pair<float, float> hotspot = getHotSpotCoordinatesForType(type);
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
EXPECT_CALL(*mPointerSprite,
setIcon(AllOf(Field(&SpriteIcon::style, static_cast<PointerIconStyle>(type)),
Field(&SpriteIcon::hotSpotX, hotspot.first),
Field(&SpriteIcon::hotSpotY, hotspot.second))));
mPointerController->updatePointerIcon(static_cast<PointerIconStyle>(type));
}
TEST_F(PointerControllerTest, setCustomPointerIcon) {
ensureDisplayViewportIsSet();
mPointerController->unfade(PointerController::Transition::IMMEDIATE);
int32_t style = CURSOR_TYPE_CUSTOM;
float hotSpotX = 15;
float hotSpotY = 20;
SpriteIcon icon;
icon.style = static_cast<PointerIconStyle>(style);
icon.hotSpotX = hotSpotX;
icon.hotSpotY = hotSpotY;
EXPECT_CALL(*mPointerSprite, setVisible(true));
EXPECT_CALL(*mPointerSprite, setAlpha(1.0f));
EXPECT_CALL(*mPointerSprite,
setIcon(AllOf(Field(&SpriteIcon::style, static_cast<PointerIconStyle>(style)),
Field(&SpriteIcon::hotSpotX, hotSpotX),
Field(&SpriteIcon::hotSpotY, hotSpotY))));
mPointerController->setCustomPointerIcon(icon);
}
TEST_F(PointerControllerTest, doesNotGetResourcesBeforeSettingViewport) {
mPointerController->setPresentation(PointerController::Presentation::POINTER);
mPointerController->setPosition(1.0f, 1.0f);
mPointerController->move(1.0f, 1.0f);
mPointerController->unfade(PointerController::Transition::IMMEDIATE);
mPointerController->fade(PointerController::Transition::IMMEDIATE);
EXPECT_TRUE(mPolicy->noResourcesAreLoaded());
ensureDisplayViewportIsSet();
}
TEST_F(PointerControllerTest, updatesSkipScreenshotFlagForTouchSpots) {
ensureDisplayViewportIsSet();
PointerCoords testSpotCoords;
testSpotCoords.clear();
testSpotCoords.setAxisValue(AMOTION_EVENT_AXIS_X, 1);
testSpotCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, 1);
BitSet32 testIdBits;
testIdBits.markBit(0);
std::array<uint32_t, MAX_POINTER_ID + 1> testIdToIndex;
sp<MockSprite> testSpotSprite(new NiceMock<MockSprite>);
// By default sprite is not marked secure
EXPECT_CALL(*mSpriteController, createSprite).WillOnce(Return(testSpotSprite));
EXPECT_CALL(*testSpotSprite, setSkipScreenshot).With(testing::Args<0>(false));
// Update spots to sync state with sprite
mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits,
ui::LogicalDisplayId::DEFAULT);
testing::Mock::VerifyAndClearExpectations(testSpotSprite.get());
// Marking the display to skip screenshot should update sprite as well
mPointerController->setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId::DEFAULT);
EXPECT_CALL(*testSpotSprite, setSkipScreenshot).With(testing::Args<0>(true));
// Update spots to sync state with sprite
mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits,
ui::LogicalDisplayId::DEFAULT);
testing::Mock::VerifyAndClearExpectations(testSpotSprite.get());
// Reset flag and verify again
mPointerController->clearSkipScreenshotFlags();
EXPECT_CALL(*testSpotSprite, setSkipScreenshot).With(testing::Args<0>(false));
mPointerController->setSpots(&testSpotCoords, testIdToIndex.cbegin(), testIdBits,
ui::LogicalDisplayId::DEFAULT);
testing::Mock::VerifyAndClearExpectations(testSpotSprite.get());
}
class PointerControllerSkipScreenshotFlagTest
: public PointerControllerTest,
public testing::WithParamInterface<PointerControllerInterface::ControllerType> {};
TEST_P(PointerControllerSkipScreenshotFlagTest, updatesSkipScreenshotFlag) {
sp<MockSprite> testPointerSprite(new NiceMock<MockSprite>);
EXPECT_CALL(*mSpriteController, createSprite).WillOnce(Return(testPointerSprite));
// Create a pointer controller
mPointerController =
PointerController::create(mPolicy, mLooper, *mSpriteController, GetParam());
ensureDisplayViewportIsSet(ui::LogicalDisplayId::DEFAULT);
// By default skip screenshot flag is not set for the sprite
EXPECT_CALL(*testPointerSprite, setSkipScreenshot).With(testing::Args<0>(false));
// Update pointer to sync state with sprite
mPointerController->setPosition(100, 100);
testing::Mock::VerifyAndClearExpectations(testPointerSprite.get());
// Marking the controller to skip screenshot should update pointer sprite
mPointerController->setSkipScreenshotFlagForDisplay(ui::LogicalDisplayId::DEFAULT);
EXPECT_CALL(*testPointerSprite, setSkipScreenshot).With(testing::Args<0>(true));
// Update pointer to sync state with sprite
mPointerController->move(10, 10);
testing::Mock::VerifyAndClearExpectations(testPointerSprite.get());
// Reset flag and verify again
mPointerController->clearSkipScreenshotFlags();
EXPECT_CALL(*testPointerSprite, setSkipScreenshot).With(testing::Args<0>(false));
mPointerController->move(10, 10);
testing::Mock::VerifyAndClearExpectations(testPointerSprite.get());
}
INSTANTIATE_TEST_SUITE_P(PointerControllerSkipScreenshotFlagTest,
PointerControllerSkipScreenshotFlagTest,
testing::Values(PointerControllerInterface::ControllerType::MOUSE,
PointerControllerInterface::ControllerType::STYLUS));
class MousePointerControllerTest : public PointerControllerTest {
protected:
MousePointerControllerTest() {
sp<MockSprite> testPointerSprite(new NiceMock<MockSprite>);
EXPECT_CALL(*mSpriteController, createSprite).WillOnce(Return(testPointerSprite));
// create a mouse pointer controller
mPointerController =
PointerController::create(mPolicy, mLooper, *mSpriteController,
PointerControllerInterface::ControllerType::MOUSE);
// set display viewport
DisplayViewport viewport;
viewport.displayId = ui::LogicalDisplayId::DEFAULT;
viewport.logicalRight = 5;
viewport.logicalBottom = 5;
viewport.physicalRight = 5;
viewport.physicalBottom = 5;
viewport.deviceWidth = 5;
viewport.deviceHeight = 5;
mPointerController->setDisplayViewport(viewport);
}
};
struct MousePointerControllerTestParam {
vec2 startPosition;
vec2 delta;
vec2 endPosition;
vec2 unconsumedDelta;
};
class PointerControllerViewportTransitionTest
: public MousePointerControllerTest,
public testing::WithParamInterface<MousePointerControllerTestParam> {};
TEST_P(PointerControllerViewportTransitionTest, testPointerViewportTransition) {
const auto& params = GetParam();
mPointerController->setPosition(params.startPosition.x, params.startPosition.y);
auto unconsumedDelta = mPointerController->move(params.delta.x, params.delta.y);
auto position = mPointerController->getPosition();
EXPECT_NEAR(position.x, params.endPosition.x, EPSILON);
EXPECT_NEAR(position.y, params.endPosition.y, EPSILON);
EXPECT_NEAR(unconsumedDelta.x, params.unconsumedDelta.x, EPSILON);
EXPECT_NEAR(unconsumedDelta.y, params.unconsumedDelta.y, EPSILON);
}
INSTANTIATE_TEST_SUITE_P(PointerControllerViewportTransitionTest,
PointerControllerViewportTransitionTest,
testing::Values(
// no transition
MousePointerControllerTestParam{{2.0f, 2.0f},
{2.0f, 2.0f},
{4.0f, 4.0f},
{0.0f, 0.0f}},
// right boundary
MousePointerControllerTestParam{{2.0f, 2.0f},
{3.0f, 0.0f},
{4.0f, 2.0f},
{1.0f, 0.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{3.0f, -1.0f},
{4.0f, 1.0f},
{1.0f, 0.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{3.0f, 1.0f},
{4.0f, 3.0f},
{1.0f, 0.0f}},
// left boundary
MousePointerControllerTestParam{{2.0f, 2.0f},
{-3.0f, 0.0f},
{0.0f, 2.0f},
{-1.0f, 0.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{-3.0f, -1.0f},
{0.0f, 1.0f},
{-1.0f, 0.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{-3.0f, 1.0f},
{0.0f, 3.0f},
{-1.0f, 0.0f}},
// bottom boundary
MousePointerControllerTestParam{{2.0f, 2.0f},
{0.0f, 3.0f},
{2.0f, 4.0f},
{0.0f, 1.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{-1.0f, 3.0f},
{1.0f, 4.0f},
{0.0f, 1.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{1.0f, 3.0f},
{3.0f, 4.0f},
{0.0f, 1.0f}},
// top boundary
MousePointerControllerTestParam{{2.0f, 2.0f},
{0.0f, -3.0f},
{2.0f, 0.0f},
{0.0f, -1.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{-1.0f, -3.0f},
{1.0f, 0.0f},
{0.0f, -1.0f}},
MousePointerControllerTestParam{{2.0f, 2.0f},
{1.0f, -3.0f},
{3.0f, 0.0f},
{0.0f, -1.0f}},
// top-left corner
MousePointerControllerTestParam{{2.0f, 2.0f},
{-3.0f, -3.0f},
{0.0f, 0.0f},
{-1.0f, -1.0f}},
// top-right corner
MousePointerControllerTestParam{{2.0f, 2.0f},
{3.0f, -3.0f},
{4.0f, 0.0f},
{1.0f, -1.0f}},
// bottom-right corner
MousePointerControllerTestParam{{2.0f, 2.0f},
{3.0f, 3.0f},
{4.0f, 4.0f},
{1.0f, 1.0f}},
// bottom-left corner
MousePointerControllerTestParam{{2.0f, 2.0f},
{-3.0f, 3.0f},
{0.0f, 4.0f},
{-1.0f, 1.0f}}));
class PointerControllerWindowInfoListenerTest : public Test {};
TEST_F(PointerControllerWindowInfoListenerTest,
doesNotCrashIfListenerCalledAfterPointerControllerDestroyed) {
sp<Looper> looper = new Looper(false);
auto spriteController = NiceMock<MockSpriteController>(looper);
sp<android::gui::WindowInfosListener> registeredListener;
sp<android::gui::WindowInfosListener> localListenerCopy;
sp<MockPointerControllerPolicyInterface> policy = new MockPointerControllerPolicyInterface();
{
TestPointerController pointerController(registeredListener, policy, looper,
spriteController);
ASSERT_NE(nullptr, registeredListener) << "WindowInfosListener was not registered";
localListenerCopy = registeredListener;
}
EXPECT_EQ(nullptr, registeredListener) << "WindowInfosListener was not unregistered";
localListenerCopy->onWindowInfosChanged({{}, {}, 0, 0});
}
} // namespace android
|