diff options
author | 2024-03-08 14:46:47 +0000 | |
---|---|---|
committer | 2024-03-08 14:46:47 +0000 | |
commit | 2446cbe250d0abbbbd5a6990b4e687a35bb9680c (patch) | |
tree | 62ed4eb3abf247945c2bb49f2fb2fee7681f1bb1 | |
parent | 25cf7faf4a428573bec0a900ec628d0919657b2b (diff) | |
parent | 3fea36d90803810a08bcd127371ef5e71262ca2d (diff) |
Merge "FocusResolver: Add test to document focus transfer to mirror" into main
-rw-r--r-- | services/inputflinger/tests/FocusResolver_test.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/services/inputflinger/tests/FocusResolver_test.cpp b/services/inputflinger/tests/FocusResolver_test.cpp index 2ff9c3c784..cb8c3cb03c 100644 --- a/services/inputflinger/tests/FocusResolver_test.cpp +++ b/services/inputflinger/tests/FocusResolver_test.cpp @@ -20,6 +20,7 @@ #define ASSERT_FOCUS_CHANGE(_changes, _oldFocus, _newFocus) \ { \ + ASSERT_TRUE(_changes.has_value()); \ ASSERT_EQ(_oldFocus, _changes->oldFocus); \ ASSERT_EQ(_newFocus, _changes->newFocus); \ } @@ -152,6 +153,38 @@ TEST(FocusResolverTest, SetFocusedMirroredWindow) { ASSERT_FOCUS_CHANGE(changes, /*from*/ invisibleWindowToken, /*to*/ nullptr); } +TEST(FocusResolverTest, FocusTransferToMirror) { + sp<IBinder> focusableWindowToken = sp<BBinder>::make(); + auto window = sp<FakeWindowHandle>::make("Window", focusableWindowToken, + /*focusable=*/true, /*visible=*/true); + auto mirror = sp<FakeWindowHandle>::make("Mirror", focusableWindowToken, + /*focusable=*/true, /*visible=*/true); + + FocusRequest request; + request.displayId = 42; + request.token = focusableWindowToken; + FocusResolver focusResolver; + std::optional<FocusResolver::FocusChanges> changes = + focusResolver.setFocusedWindow(request, {window, mirror}); + ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ focusableWindowToken); + + // The mirror window now comes on top, and the focus does not change + changes = focusResolver.setInputWindows(request.displayId, {mirror, window}); + ASSERT_FALSE(changes.has_value()); + + // The window now comes on top while the mirror is removed, and the focus does not change + changes = focusResolver.setInputWindows(request.displayId, {window}); + ASSERT_FALSE(changes.has_value()); + + // The window is removed but the mirror is on top, and focus does not change + changes = focusResolver.setInputWindows(request.displayId, {mirror}); + ASSERT_FALSE(changes.has_value()); + + // All windows removed + changes = focusResolver.setInputWindows(request.displayId, {}); + ASSERT_FOCUS_CHANGE(changes, /*from*/ focusableWindowToken, /*to*/ nullptr); +} + TEST(FocusResolverTest, SetInputWindows) { sp<IBinder> focusableWindowToken = sp<BBinder>::make(); std::vector<sp<WindowInfoHandle>> windows; @@ -169,6 +202,10 @@ TEST(FocusResolverTest, SetInputWindows) { focusResolver.setFocusedWindow(request, windows); ASSERT_EQ(focusableWindowToken, changes->newFocus); + // When there are no changes to the window, focus does not change + changes = focusResolver.setInputWindows(request.displayId, windows); + ASSERT_FALSE(changes.has_value()); + // Window visibility changes and the window loses focus window->setVisible(false); changes = focusResolver.setInputWindows(request.displayId, windows); @@ -380,18 +417,13 @@ TEST(FocusResolverTest, FocusRequestsAreClearedWhenWindowIsRemoved) { ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); ASSERT_EQ(request.displayId, changes->displayId); - // Start with a focused window - window->setFocusable(true); - changes = focusResolver.setInputWindows(request.displayId, windows); - ASSERT_FOCUS_CHANGE(changes, /*from*/ nullptr, /*to*/ windowToken); - // When a display is removed, all windows are removed from the display // and our focused window loses focus changes = focusResolver.setInputWindows(request.displayId, {}); ASSERT_FOCUS_CHANGE(changes, /*from*/ windowToken, /*to*/ nullptr); focusResolver.displayRemoved(request.displayId); - // When a display is readded, the window does not get focus since the request was cleared. + // When a display is re-added, the window does not get focus since the request was cleared. changes = focusResolver.setInputWindows(request.displayId, windows); ASSERT_FALSE(changes); } |