mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 18:06:48 +00:00
Fixes: 185820525 Fixes: 177316094 Fixes: 158017601 Fixes: 180915942 Change-Id: I8ce5bde08e1728d3209762c5f061245386408825
75 lines
2.7 KiB
Java
75 lines
2.7 KiB
Java
package com.android.launcher3.ui;
|
|
|
|
import android.util.Log;
|
|
import android.view.Surface;
|
|
|
|
import com.android.launcher3.tapl.TestHelpers;
|
|
import com.android.launcher3.testing.TestProtocol;
|
|
|
|
import org.junit.rules.TestRule;
|
|
import org.junit.runner.Description;
|
|
import org.junit.runners.model.Statement;
|
|
|
|
class PortraitLandscapeRunner implements TestRule {
|
|
private static final String TAG = "PortraitLandscapeRunner";
|
|
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();
|
|
} catch (Throwable e) {
|
|
Log.e(TAG, "Error", e);
|
|
throw e;
|
|
} finally {
|
|
mTest.mDevice.setOrientationNatural();
|
|
mTest.executeOnLauncher(launcher ->
|
|
{
|
|
if (launcher != null) {
|
|
launcher.getRotationHelper().forceAllowRotationForTesting(false);
|
|
}
|
|
});
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
|
|
}
|
|
}
|
|
|
|
private void evaluateInPortrait() throws Throwable {
|
|
mTest.mDevice.setOrientationNatural();
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher);
|
|
base.evaluate();
|
|
mTest.getDevice().pressHome();
|
|
}
|
|
|
|
private void evaluateInLandscape() throws Throwable {
|
|
mTest.mDevice.setOrientationLeft();
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher);
|
|
base.evaluate();
|
|
mTest.getDevice().pressHome();
|
|
}
|
|
};
|
|
}
|
|
}
|