Merge "Revert "Revert "Add TaskbarModeSwitchRule to test both transient/persistent taskbar.""" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-11-15 22:31:55 +00:00
committed by Android (Google) Code Review
12 changed files with 269 additions and 9 deletions

View File

@@ -39,6 +39,7 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
protected TestRule getRulesInsideActivityMonitor() {
return RuleChain.
outerRule(new NavigationModeSwitchRule(mLauncher)).
around(new TaskbarModeSwitchRule(mLauncher)).
around(super.getRulesInsideActivityMonitor());
}

View File

@@ -51,7 +51,7 @@ import java.util.concurrent.TimeUnit;
/**
* Test rule that allows executing a test with Quickstep on and then Quickstep off.
* The test should be annotated with @QuickstepOnOff.
* The test should be annotated with @NavigationModeSwitch.
*/
public class NavigationModeSwitchRule implements TestRule {

View File

@@ -17,6 +17,8 @@ package com.android.quickstep;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static com.android.quickstep.TaskbarModeSwitchRule.Mode.PERSISTENT;
import static junit.framework.TestCase.assertEquals;
import android.content.Intent;
@@ -27,6 +29,7 @@ import androidx.test.runner.AndroidJUnit4;
import com.android.launcher3.tapl.Taskbar;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.util.rule.ScreenRecordRule.ScreenRecord;
import com.android.quickstep.TaskbarModeSwitchRule.TaskbarModeSwitch;
import org.junit.After;
import org.junit.Assume;
@@ -53,21 +56,25 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
TaplTestsLauncher3.initialize(this);
startAppFast(CALCULATOR_APP_PACKAGE);
mLauncher.enableBlockTimeout(true);
mLauncher.showTaskbarIfHidden();
}
@After
public void tearDown() {
mLauncher.useDefaultWorkspaceLayoutOnReload();
mLauncher.enableBlockTimeout(false);
}
@Test
@TaskbarModeSwitch(mode = PERSISTENT)
public void testHideShowTaskbar() {
getTaskbar().hide();
mLauncher.getLaunchedAppState().showTaskbar();
}
@Test
@TaskbarModeSwitch(mode = PERSISTENT)
public void testHideTaskbarPersistsOnRecreate() {
getTaskbar().hide();
mLauncher.recreateTaskbar();
@@ -75,16 +82,19 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
}
@Test
@TaskbarModeSwitch
public void testLaunchApp() throws Exception {
getTaskbar().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
}
@Test
@TaskbarModeSwitch
public void testOpenMenu() throws Exception {
getTaskbar().getAppIcon(TEST_APP_NAME).openMenu();
}
@Test
@TaskbarModeSwitch
public void testLaunchShortcut() throws Exception {
getTaskbar().getAppIcon(TEST_APP_NAME)
.openDeepShortcutMenu()
@@ -95,6 +105,7 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
@Test
@ScreenRecord // b/231615831
@PortraitLandscape
@TaskbarModeSwitch
public void testLaunchAppInSplitscreen() throws Exception {
getTaskbar().getAppIcon(TEST_APP_NAME).dragToSplitscreen(
TEST_APP_PACKAGE, CALCULATOR_APP_PACKAGE);
@@ -103,6 +114,7 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
@Test
@ScreenRecord // b/231615831
@PortraitLandscape
@TaskbarModeSwitch
public void testLaunchShortcutInSplitscreen() throws Exception {
getTaskbar().getAppIcon(TEST_APP_NAME)
.openDeepShortcutMenu()
@@ -111,16 +123,19 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
}
@Test
@TaskbarModeSwitch
public void testLaunchApp_FromTaskbarAllApps() throws Exception {
getTaskbar().openAllApps().getAppIcon(TEST_APP_NAME).launch(TEST_APP_PACKAGE);
}
@Test
@TaskbarModeSwitch
public void testOpenMenu_FromTaskbarAllApps() throws Exception {
getTaskbar().openAllApps().getAppIcon(TEST_APP_NAME).openMenu();
}
@Test
@TaskbarModeSwitch
public void testLaunchShortcut_FromTaskbarAllApps() throws Exception {
getTaskbar().openAllApps()
.getAppIcon(TEST_APP_NAME)
@@ -132,6 +147,7 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
@Test
@ScreenRecord // b/231615831
@PortraitLandscape
@TaskbarModeSwitch
public void testLaunchAppInSplitscreen_FromTaskbarAllApps() throws Exception {
getTaskbar().openAllApps()
.getAppIcon(TEST_APP_NAME)
@@ -141,6 +157,7 @@ public class TaplTestsTaskbar extends AbstractQuickStepTest {
@Test
@ScreenRecord // b/231615831
@PortraitLandscape
@TaskbarModeSwitch
public void testLaunchShortcutInSplitscreen_FromTaskbarAllApps() throws Exception {
getTaskbar().openAllApps()
.getAppIcon(TEST_APP_NAME)

View File

@@ -0,0 +1,140 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.quickstep;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static com.android.quickstep.TaskbarModeSwitchRule.Mode.ALL;
import static com.android.quickstep.TaskbarModeSwitchRule.Mode.PERSISTENT;
import static com.android.quickstep.TaskbarModeSwitchRule.Mode.TRANSIENT;
import android.content.Context;
import android.util.Log;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.rule.FailureWatcher;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Test rule that allows executing a test multiple times with different conditions
* ie. with transient taskbar enabled and disabled.
* The test should be annotated with @TaskbarModeSwitch.
*/
public class TaskbarModeSwitchRule implements TestRule {
static final String TAG = "TaskbarModeSwitchRule";
public static final int WAIT_TIME_MS = 10000;
public enum Mode {
TRANSIENT, PERSISTENT, ALL
}
// Annotation for tests that need to be run with quickstep enabled and disabled.
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TaskbarModeSwitch {
Mode mode() default ALL;
}
private final LauncherInstrumentation mLauncher;
public TaskbarModeSwitchRule(LauncherInstrumentation launcher) {
mLauncher = launcher;
}
@Override
public Statement apply(Statement base, Description description) {
if (TestHelpers.isInLauncherProcess()
&& description.getAnnotation(TaskbarModeSwitch.class) != null) {
Mode mode = description.getAnnotation(TaskbarModeSwitch.class).mode();
return new Statement() {
@Override
public void evaluate() throws Throwable {
mLauncher.enableDebugTracing();
final boolean wasTransientTaskbarMode =
isTaskbarTransientMode(getInstrumentation().getTargetContext());
try {
if (mode == TRANSIENT || mode == ALL) {
evaluateWithTransientTaskbar();
}
if (mode == PERSISTENT || mode == ALL) {
evaluateWithPersistentTaskbar();
}
} catch (Throwable e) {
Log.e(TAG, "Error", e);
throw e;
} finally {
Log.d(TAG, "In Finally block");
setTaskbarMode(mLauncher, wasTransientTaskbarMode, description);
}
}
private void evaluateWithPersistentTaskbar() throws Throwable {
setTaskbarMode(mLauncher, false, description);
base.evaluate();
}
private void evaluateWithTransientTaskbar() throws Throwable {
setTaskbarMode(mLauncher, true, description);
base.evaluate();
}
};
} else {
return base;
}
}
private static boolean isTaskbarTransientMode(Context context) {
return DisplayController.isTransientTaskbar(context);
}
public static void setTaskbarMode(LauncherInstrumentation launcher,
boolean expectTransientTaskbar, Description description) throws Exception {
launcher.enableTransientTaskbar(expectTransientTaskbar);
launcher.recreateTaskbar();
Context context = getInstrumentation().getTargetContext();
assertTrue(launcher, "Couldn't set taskbar=" + expectTransientTaskbar,
isTaskbarTransientMode(context) == expectTransientTaskbar, description);
AbstractLauncherUiTest.checkDetectedLeaks(launcher);
}
private static void assertTrue(LauncherInstrumentation launcher, String message,
boolean condition, Description description) {
launcher.checkForAnomaly(true, true);
if (!condition) {
final AssertionError assertionError = new AssertionError(message);
if (description != null) {
FailureWatcher.onError(launcher, description, assertionError);
}
throw assertionError;
}
}
}