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;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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();
|
2019-07-19 12:12:49 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
|
Log.e(TAG, "Exception", e);
|
|
|
|
|
throw e;
|
2019-06-11 19:15:14 -07:00
|
|
|
} 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();
|
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);
|
|
|
|
|
base.evaluate();
|
2019-06-21 14:23:15 -07:00
|
|
|
mTest.getDevice().pressHome();
|
2019-06-11 19:15:14 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|