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

Commit 5eac9a5d authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Waiting for wallpaper animation in widget tests only for Nexus Launcher and in postsubmit

This code flakes in postsubmit and presubmit, but the failure is
not reproducible in local and abtd runs. Landing the change to make postsubmit
flake; then I'll use tricks like tracing to debug the cause.

Bug: 313926097
Flag: N/A
Test: presubmit
Change-Id: I77c324d43a2400fe1015f5cd0a4729e34552687c
parent d60f56c3
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.ShellCommandRule;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;

import org.junit.Before;
@@ -101,7 +102,7 @@ public class TaplAddConfigWidgetTest extends AbstractLauncherUiTest {
        // Verify that the widget id is valid and bound
        assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));

        setResult(acceptConfig);
        setResultAndWaitForAnimation(acceptConfig);
        if (acceptConfig) {
            Wait.atMost("", new WidgetSearchCondition(), DEFAULT_ACTIVITY_TIMEOUT, mLauncher);
            assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
@@ -112,13 +113,22 @@ public class TaplAddConfigWidgetTest extends AbstractLauncherUiTest {
        }
    }

    private void setResult(boolean success) {
        mLauncher.executeAndWaitForWallpaperAnimation(() ->
    private static void setResult(boolean success) {
        getInstrumentation().getTargetContext().sendBroadcast(
                WidgetConfigActivity.getCommandIntent(WidgetConfigActivity.class,
                                        success ? "clickOK" : "clickCancel")),
                        success ? "clickOK" : "clickCancel"));
    }

    private void setResultAndWaitForAnimation(boolean success) {
        if (mLauncher.isLauncher3()
                || TestStabilityRule.isPresubmit() /* b/313926097 */) {
            setResult(success);
        } else {
            mLauncher.executeAndWaitForWallpaperAnimation(
                    () -> setResult(success),
                    "setting widget coinfig result");
        }
    }

    /**
     * Condition for searching widget id