From c3dc5d585701ead2eb215365dc40faad385d20f4 Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Thu, 23 Feb 2023 14:22:47 +0000 Subject: De-flake testSystemDrivenInsetsAnimationLoggingListener_onReady Test: atest InsetsControllerTest#testSystemDrivenInsetsAnimationLoggingListener_onReady Fixes: 270547415 Change-Id: Ie72d5b5c538faa038a58033887716bdd870f35fa Merged-In: Ie72d5b5c538faa038a58033887716bdd870f35fa (cherry picked from commit 8e011cea5123b36c1e9ea848fdf1c07409fff8fc) --- .../coretests/src/android/view/InsetsControllerTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/tests/coretests/src/android/view/InsetsControllerTest.java b/core/tests/coretests/src/android/view/InsetsControllerTest.java index 6e59b83810e1..1ad01a19d221 100644 --- a/core/tests/coretests/src/android/view/InsetsControllerTest.java +++ b/core/tests/coretests/src/android/view/InsetsControllerTest.java @@ -237,17 +237,22 @@ public class InsetsControllerTest { @Test public void testSystemDrivenInsetsAnimationLoggingListener_onReady() { + var loggingListener = mock(WindowInsetsAnimationControlListener.class); + prepareControls(); // only the original thread that created view hierarchy can touch its views InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { - WindowInsetsAnimationControlListener loggingListener = - mock(WindowInsetsAnimationControlListener.class); mController.setSystemDrivenInsetsAnimationLoggingListener(loggingListener); mController.getSourceConsumer(ITYPE_IME).onWindowFocusGained(true); // since there is no focused view, forcefully make IME visible. - mController.show(Type.ime(), true /* fromIme */); - verify(loggingListener).onReady(notNull(), anyInt()); + mController.show(WindowInsets.Type.ime(), true /* fromIme */); + // When using the animation thread, this must not invoke onReady() + mViewRoot.getView().getViewTreeObserver().dispatchOnPreDraw(); }); + // Wait for onReady() being dispatched on the animation thread. + InsetsAnimationThread.get().getThreadHandler().runWithScissors(() -> {}, 500); + + verify(loggingListener).onReady(notNull(), anyInt()); } @Test -- cgit v1.2.3-59-g8ed1b