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

Commit 074b1434 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Enabling tests in landscape mode" into ub-launcher3-qt-dev

parents 921163a3 06d30e54
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {

    @Test
    @NavigationModeSwitch
    @PortraitLandscape
//    @PortraitLandscape
    public void testBackground() throws Exception {
        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
        final Background background = mLauncher.getBackground();
+3 −41
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.content.pm.PackageManager;
import android.os.Process;
import android.os.RemoteException;
import android.util.Log;
import android.view.Surface;

import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.By;
@@ -67,7 +66,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runners.model.Statement;

import java.io.IOException;
import java.lang.annotation.ElementType;
@@ -124,46 +122,10 @@ public abstract class AbstractLauncherUiTest {
    protected @interface PortraitLandscape {
    }

    @Rule
    public TestRule mPortraitLandscapeExecutor =
            (base, description) -> false && description.getAnnotation(PortraitLandscape.class)
                    != null ? new Statement() {
                @Override
                public void evaluate() throws Throwable {
                    try {
                        // Create launcher activity if necessary and bring it to the front.
                        mLauncher.pressHome();
                        waitForLauncherCondition("Launcher activity wasn't created",
                                launcher -> launcher != null);

                        executeOnLauncher(launcher ->
                                launcher.getRotationHelper().forceAllowRotationForTesting(true));

                        evaluateInPortrait();
                        evaluateInLandscape();
                    } finally {
                        mDevice.setOrientationNatural();
                        executeOnLauncher(launcher ->
                                launcher.getRotationHelper().forceAllowRotationForTesting(false));
                        mLauncher.setExpectedRotation(Surface.ROTATION_0);
                    }
                }

                private void evaluateInPortrait() throws Throwable {
                    mDevice.setOrientationNatural();
                    mLauncher.setExpectedRotation(Surface.ROTATION_0);
                    base.evaluate();
                }

                private void evaluateInLandscape() throws Throwable {
                    mDevice.setOrientationLeft();
                    mLauncher.setExpectedRotation(Surface.ROTATION_90);
                    base.evaluate();
                }
            } : base;

    protected TestRule getRulesInsideActivityMonitor() {
        return new FailureWatcher(this);
        return RuleChain.
                outerRule(new PortraitLandscapeRunner(this)).
                around(new FailureWatcher(this));
    }

    @Rule
+63 −0
Original line number Diff line number Diff line
package com.android.launcher3.ui;

import android.view.Surface;

import com.android.launcher3.tapl.TestHelpers;

import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

class PortraitLandscapeRunner implements TestRule {
    private AbstractLauncherUiTest mTest;

    public PortraitLandscapeRunner(AbstractLauncherUiTest test) {
        mTest = test;
    }

    @Override
    public Statement apply(Statement base, Description description) {
        if (!TestHelpers.isInLauncherProcess() ||
                description.getAnnotation(AbstractLauncherUiTest.PortraitLandscape.class) == null) {
            return base;
        }

        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                try {
                    mTest.mDevice.pressHome();
                    mTest.waitForLauncherCondition("Launcher activity wasn't created",
                            launcher -> launcher != null);

                    mTest.executeOnLauncher(launcher ->
                            launcher.getRotationHelper().forceAllowRotationForTesting(
                                    true));

                    evaluateInPortrait();
                    evaluateInLandscape();
                } finally {
                    mTest.mDevice.setOrientationNatural();
                    mTest.executeOnLauncher(launcher ->
                            launcher.getRotationHelper().forceAllowRotationForTesting(
                                    false));
                    mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
                }
            }

            private void evaluateInPortrait() throws Throwable {
                mTest.mDevice.setOrientationNatural();
                mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
                base.evaluate();
                mTest.mLauncher.pressHome();
            }

            private void evaluateInLandscape() throws Throwable {
                mTest.mDevice.setOrientationLeft();
                mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
                base.evaluate();
                mTest.mLauncher.pressHome();
            }
        };
    }
}
+1 −5
Original line number Diff line number Diff line
@@ -59,11 +59,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {

    public static void initialize(AbstractLauncherUiTest test) throws Exception {
        test.clearLauncherData();
        if (TestHelpers.isInLauncherProcess()) {
            test.mActivityMonitor.returnToHome();
        } else {
        test.mDevice.pressHome();
        }
        test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
        test.waitForState("Launcher internal state didn't switch to Home", LauncherState.NORMAL);
        test.waitForResumed("Launcher internal state is still Background");
+1 −1
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
        }

        // Go back to home
        mActivityMonitor.returnToHome();
        mLauncher.pressHome();
        Wait.atMost(null, new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT);
    }

Loading