diff options
author | Vadim Tryshev <vadimt@google.com> | 2018-09-28 18:08:44 -0700 |
---|---|---|
committer | Vadim Tryshev <vadimt@google.com> | 2018-10-02 17:32:01 -0700 |
commit | 6ffb2c8faa34c3e4d2b441ef67a88470d6685858 (patch) | |
tree | 2bbb3e19cece9967ea765ac1ca8f63ef67c8755f /quickstep/tests | |
parent | d9f52ae7ba59eeb560a72e2fc712ecbde9549b51 (diff) | |
download | android_packages_apps_Trebuchet-6ffb2c8faa34c3e4d2b441ef67a88470d6685858.tar.gz android_packages_apps_Trebuchet-6ffb2c8faa34c3e4d2b441ef67a88470d6685858.tar.bz2 android_packages_apps_Trebuchet-6ffb2c8faa34c3e4d2b441ef67a88470d6685858.zip |
Make @QuickstepOnOff and @PortraitLandscape available to all UI tests.
Also, fix rotation as Portrait as starting poin for all tests, to avoid
tests running in unexpected configuration.
Bug: 115645301
Test: run all Nexus tests
Change-Id: I3ab0e91db111eeefda77af2960c43962a119de0c
Diffstat (limited to 'quickstep/tests')
-rw-r--r-- | quickstep/tests/src/com/android/quickstep/AbstractQuickStepTest.java | 31 | ||||
-rw-r--r-- | quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java | 89 |
2 files changed, 120 insertions, 0 deletions
diff --git a/quickstep/tests/src/com/android/quickstep/AbstractQuickStepTest.java b/quickstep/tests/src/com/android/quickstep/AbstractQuickStepTest.java new file mode 100644 index 000000000..6854aa8dd --- /dev/null +++ b/quickstep/tests/src/com/android/quickstep/AbstractQuickStepTest.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2018 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 com.android.launcher3.ui.AbstractLauncherUiTest; + +import org.junit.Rule; +import org.junit.rules.TestRule; + +/** + * Base class for all instrumentation tests that deal with Quickstep. + */ +public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest { + @Rule + public TestRule mQuickstepOnOffExecutor = + new QuickStepOnOffRule(mMainThreadExecutor, mLauncher); +} diff --git a/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java new file mode 100644 index 000000000..6a149b74b --- /dev/null +++ b/quickstep/tests/src/com/android/quickstep/QuickStepOnOffRule.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 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 androidx.test.InstrumentationRegistry; + +import com.android.launcher3.tapl.LauncherInstrumentation; +import com.android.launcher3.ui.TestHelpers; + +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; +import java.util.concurrent.Executor; + +/** + * Test rule that allows executing a test with Quickstep on and then Quickstep off. + * The test should be annotated with @QuickstepOnOff. + */ +public class QuickStepOnOffRule implements TestRule { + // Annotation for tests that need to be run with quickstep enabled and disabled. + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface QuickstepOnOff { + } + + private final Executor mMainThreadExecutor; + private final LauncherInstrumentation mLauncher; + + public QuickStepOnOffRule(Executor mainThreadExecutor, LauncherInstrumentation launcher) { + mLauncher = launcher; + this.mMainThreadExecutor = mainThreadExecutor; + } + + @Override + public Statement apply(Statement base, Description description) { + if (TestHelpers.isInLauncherProcess() && + description.getAnnotation(QuickstepOnOff.class) != null) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + try { + evaluateWithQuickstepOn(); + evaluateWithQuickstepOff(); + } finally { + overrideSwipeUpEnabled(null); + } + } + + private void evaluateWithQuickstepOff() throws Throwable { + overrideSwipeUpEnabled(false); + base.evaluate(); + } + + private void evaluateWithQuickstepOn() throws Throwable { + overrideSwipeUpEnabled(true); + base.evaluate(); + } + + private void overrideSwipeUpEnabled(Boolean swipeUpEnabledOverride) { + mLauncher.overrideSwipeUpEnabled(swipeUpEnabledOverride); + mMainThreadExecutor.execute(() -> OverviewInteractionState.INSTANCE.get( + InstrumentationRegistry.getInstrumentation().getTargetContext()). + notifySwipeUpSettingChanged(mLauncher.isSwipeUpEnabled())); + } + }; + } else { + return base; + } + } +} |