2019-06-11 19:15:14 -07:00
|
|
|
package com.android.launcher3.ui;
|
|
|
|
|
|
2019-07-19 12:12:49 -07:00
|
|
|
import android.util.Log;
|
2019-06-11 19:15:14 -07:00
|
|
|
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;
|
|
|
|
|
|
2023-05-25 02:25:19 +01:00
|
|
|
import java.lang.annotation.ElementType;
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
|
import java.lang.annotation.Target;
|
|
|
|
|
|
|
|
|
|
public class PortraitLandscapeRunner implements TestRule {
|
2019-07-19 12:12:49 -07:00
|
|
|
private static final String TAG = "PortraitLandscapeRunner";
|
2019-06-11 19:15:14 -07:00
|
|
|
private AbstractLauncherUiTest mTest;
|
|
|
|
|
|
2023-05-25 02:25:19 +01:00
|
|
|
// Annotation for tests that need to be run in portrait and landscape modes.
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
@Target(ElementType.METHOD)
|
|
|
|
|
public @interface PortraitLandscape {
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-11 19:15:14 -07:00
|
|
|
public PortraitLandscapeRunner(AbstractLauncherUiTest test) {
|
|
|
|
|
mTest = test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Statement apply(Statement base, Description description) {
|
|
|
|
|
if (!TestHelpers.isInLauncherProcess() ||
|
2023-05-25 02:25:19 +01:00
|
|
|
description.getAnnotation(PortraitLandscape.class) == null) {
|
2019-06-11 19:15:14 -07:00
|
|
|
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();
|
2019-12-12 14:18:19 -08:00
|
|
|
} catch (Throwable e) {
|
|
|
|
|
Log.e(TAG, "Error", e);
|
2019-07-19 12:12:49 -07:00
|
|
|
throw e;
|
2019-06-11 19:15:14 -07:00
|
|
|
} finally {
|
|
|
|
|
mTest.mDevice.setOrientationNatural();
|
|
|
|
|
mTest.executeOnLauncher(launcher ->
|
2019-09-06 18:08:22 -07:00
|
|
|
{
|
|
|
|
|
if (launcher != null) {
|
|
|
|
|
launcher.getRotationHelper().forceAllowRotationForTesting(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-06-11 19:15:14 -07:00
|
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void evaluateInPortrait() throws Throwable {
|
|
|
|
|
mTest.mDevice.setOrientationNatural();
|
|
|
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
|
2020-04-17 15:50:52 -07:00
|
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher);
|
2019-06-11 19:15:14 -07:00
|
|
|
base.evaluate();
|
2019-06-21 14:23:15 -07:00
|
|
|
mTest.getDevice().pressHome();
|
2019-06-11 19:15:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void evaluateInLandscape() throws Throwable {
|
|
|
|
|
mTest.mDevice.setOrientationLeft();
|
|
|
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
|
2020-04-17 15:50:52 -07:00
|
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher);
|
2019-06-11 19:15:14 -07:00
|
|
|
base.evaluate();
|
2019-06-21 14:23:15 -07:00
|
|
|
mTest.getDevice().pressHome();
|
2019-06-11 19:15:14 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|