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

Commit 85561d1e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix testQuickSwitchFromApp" into ub-launcher3-master

parents e60ae45b bc42d64c
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -248,33 +248,32 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
    @Test
    @NavigationModeSwitch
    @PortraitLandscape
    @Ignore("Temporarily disabled b/140252765")
    public void testQuickSwitchFromApp() throws Exception {
        startAppFast(getAppPackageName());
        startTestActivity(2);
        String calculatorPackage = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR);
        startAppFast(calculatorPackage);
        startTestActivity(3);
        startTestActivity(4);

        Background background = getAndAssertBackground();
        background.quickSwitchToPreviousApp();
        assertTrue("The first app we should have quick switched to is not running",
                isTestActivityRunning("TestActivity2"));
                isTestActivityRunning(3));

        background = getAndAssertBackground();
        background.quickSwitchToPreviousApp();
        if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) {
            // 3-button mode toggles between 2 apps, rather than going back further.
            assertTrue("Second quick switch should have returned to the first app.",
                    mDevice.wait(Until.hasObject(By.pkg(calculatorPackage)), DEFAULT_UI_TIMEOUT));
                    isTestActivityRunning(4));
        } else {
            assertTrue("The second app we should have quick switched to is not running",
                    isTestActivityRunning("Test Pin Item"));
                    isTestActivityRunning(2));
        }
        getAndAssertBackground();
    }

    private boolean isTestActivityRunning(String activityLabel) {
        return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName()).text(activityLabel)),
    private boolean isTestActivityRunning(int activityNumber) {
        return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName())
                        .text("TestActivity" + activityNumber)),
                DEFAULT_UI_TIMEOUT);
    }

@@ -285,7 +284,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
        startTestActivity(2);
        mLauncher.pressHome().quickSwitchToPreviousApp();
        assertTrue("The most recent task is not running after quick switching from home",
                isTestActivityRunning("TestActivity2"));
                isTestActivityRunning(2));
        getAndAssertBackground();
    }
}
+12 −4
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue;

import static java.lang.System.exit;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -373,7 +375,8 @@ public abstract class AbstractLauncherUiTest {
        startIntent(
                getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(
                        packageName),
                By.pkg(packageName).depth(0));
                By.pkg(packageName).depth(0),
                true /* newTask */);
    }

    public static void startTestActivity(int activityNumber) {
@@ -382,12 +385,17 @@ public abstract class AbstractLauncherUiTest {
                getLaunchIntentForPackage(packageName);
        intent.setComponent(new ComponentName(packageName,
                "com.android.launcher3.tests.Activity" + activityNumber));
        startIntent(intent, By.pkg(packageName).text("TestActivity" + activityNumber));
        startIntent(intent, By.pkg(packageName).text("TestActivity" + activityNumber),
                false /* newTask */);
    }

    private static void startIntent(Intent intent, BySelector selector) {
    private static void startIntent(Intent intent, BySelector selector, boolean newTask) {
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        if (newTask) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        } else {
            intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
        }
        getInstrumentation().getTargetContext().startActivity(intent);
        assertTrue("App didn't start: " + selector,
                UiDevice.getInstance(getInstrumentation())