Merge "Fix testQuickSwitchFromApp" into ub-launcher3-qt-future-dev

This commit is contained in:
TreeHugger Robot
2019-10-24 00:47:01 +00:00
committed by Android (Google) Code Review
2 changed files with 21 additions and 16 deletions
@@ -248,33 +248,32 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
@Test @Test
@NavigationModeSwitch @NavigationModeSwitch
@PortraitLandscape @PortraitLandscape
@Ignore("Temporarily disabled b/140252765")
public void testQuickSwitchFromApp() throws Exception { public void testQuickSwitchFromApp() throws Exception {
startAppFast(getAppPackageName());
startTestActivity(2); startTestActivity(2);
String calculatorPackage = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); startTestActivity(3);
startAppFast(calculatorPackage); startTestActivity(4);
Background background = getAndAssertBackground(); Background background = getAndAssertBackground();
background.quickSwitchToPreviousApp(); background.quickSwitchToPreviousApp();
assertTrue("The first app we should have quick switched to is not running", assertTrue("The first app we should have quick switched to is not running",
isTestActivityRunning("TestActivity2")); isTestActivityRunning(3));
background = getAndAssertBackground(); background = getAndAssertBackground();
background.quickSwitchToPreviousApp(); background.quickSwitchToPreviousApp();
if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) { if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) {
// 3-button mode toggles between 2 apps, rather than going back further. // 3-button mode toggles between 2 apps, rather than going back further.
assertTrue("Second quick switch should have returned to the first app.", assertTrue("Second quick switch should have returned to the first app.",
mDevice.wait(Until.hasObject(By.pkg(calculatorPackage)), DEFAULT_UI_TIMEOUT)); isTestActivityRunning(4));
} else { } else {
assertTrue("The second app we should have quick switched to is not running", assertTrue("The second app we should have quick switched to is not running",
isTestActivityRunning("Test Pin Item")); isTestActivityRunning(2));
} }
getAndAssertBackground(); getAndAssertBackground();
} }
private boolean isTestActivityRunning(String activityLabel) { private boolean isTestActivityRunning(int activityNumber) {
return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName()).text(activityLabel)), return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName())
.text("TestActivity" + activityNumber)),
DEFAULT_UI_TIMEOUT); DEFAULT_UI_TIMEOUT);
} }
@@ -285,7 +284,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
startTestActivity(2); startTestActivity(2);
mLauncher.pressHome().quickSwitchToPreviousApp(); mLauncher.pressHome().quickSwitchToPreviousApp();
assertTrue("The most recent task is not running after quick switching from home", assertTrue("The most recent task is not running after quick switching from home",
isTestActivityRunning("TestActivity2")); isTestActivityRunning(2));
getAndAssertBackground(); getAndAssertBackground();
} }
} }
@@ -15,8 +15,6 @@
*/ */
package com.android.launcher3.ui; package com.android.launcher3.ui;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static com.android.launcher3.tapl.LauncherInstrumentation.ContainerType; import static com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName; import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
@@ -25,6 +23,8 @@ import static org.junit.Assert.assertTrue;
import static java.lang.System.exit; import static java.lang.System.exit;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@@ -348,7 +348,8 @@ public abstract class AbstractLauncherUiTest {
startIntent( startIntent(
getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage( getInstrumentation().getContext().getPackageManager().getLaunchIntentForPackage(
packageName), packageName),
By.pkg(packageName).depth(0)); By.pkg(packageName).depth(0),
true /* newTask */);
} }
protected void startTestActivity(int activityNumber) { protected void startTestActivity(int activityNumber) {
@@ -357,12 +358,17 @@ public abstract class AbstractLauncherUiTest {
getLaunchIntentForPackage(packageName); getLaunchIntentForPackage(packageName);
intent.setComponent(new ComponentName(packageName, intent.setComponent(new ComponentName(packageName,
"com.android.launcher3.tests.Activity" + activityNumber)); "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 void startIntent(Intent intent, BySelector selector) { private void startIntent(Intent intent, BySelector selector, boolean newTask) {
intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 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); getInstrumentation().getTargetContext().startActivity(intent);
assertTrue("App didn't start: " + selector, assertTrue("App didn't start: " + selector,
mDevice.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT)); mDevice.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT));