Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7375627e authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix flake in WindowOnBackInvokedDispatcherTest

In rare cases (e.g. when some frames are skipped), it could have happened that no progress update was emitted before onBackCancelled was invoked. This CL ensures that the test doesn't fail in such a case.

Bug: 390528064
Flag: EXEMPT test-only flake fix
Test: WindowOnBackInvokedDispatcherTest
Change-Id: I3c992ef955a4ba11eec1789d812466038d22c1cf
parent 7dd64558
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -541,24 +541,30 @@ public class WindowOnBackInvokedDispatcherTest {
            throws RemoteException, InterruptedException {
        // Setup a callback that unregisters itself after the gesture is finished but before the
        // progress is animated back to 0f
        final AtomicBoolean unregisterOnProgressUpdate = new AtomicBoolean(false);
        final AtomicBoolean unregisterOnNextCallbackInvocation = new AtomicBoolean(false);
        final AtomicInteger onBackInvokedCalled = new AtomicInteger(0);
        final CountDownLatch onBackCancelledCalled = new CountDownLatch(1);
        OnBackAnimationCallback onBackAnimationCallback = new OnBackAnimationCallback() {
            @Override
            public void onBackProgressed(@NonNull BackEvent backEvent) {
                if (unregisterOnProgressUpdate.get()) {
                if (unregisterOnNextCallbackInvocation.getAndSet(false)) {
                    mDispatcher.unregisterOnBackInvokedCallback(this);
                }
            }

            @Override
            public void onBackInvoked() {
                if (unregisterOnNextCallbackInvocation.getAndSet(false)) {
                    mDispatcher.unregisterOnBackInvokedCallback(this);
                }
                onBackInvokedCalled.getAndIncrement();
            }

            @Override
            public void onBackCancelled() {
                if (unregisterOnNextCallbackInvocation.getAndSet(false)) {
                    mDispatcher.unregisterOnBackInvokedCallback(this);
                }
                onBackCancelledCalled.countDown();
            }
        };
@@ -572,7 +578,7 @@ public class WindowOnBackInvokedDispatcherTest {

        // simulate back gesture finished and onBackCancelled() called, which starts the progress
        // animation back to 0f. On the first progress emission, the callback will unregister itself
        unregisterOnProgressUpdate.set(true);
        unregisterOnNextCallbackInvocation.set(true);
        callbackInfo.getCallback().onBackCancelled();
        waitForIdle();
        onBackCancelledCalled.await(1000, TimeUnit.MILLISECONDS);