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;
|
|
|
|
|
|
2024-04-11 04:27:23 +00:00
|
|
|
import com.android.launcher3.Launcher;
|
2019-06-11 19:15:14 -07:00
|
|
|
import com.android.launcher3.tapl.TestHelpers;
|
2024-03-07 18:26:29 -08:00
|
|
|
import com.android.launcher3.util.rule.FailureWatcher;
|
2019-06-11 19:15:14 -07:00
|
|
|
|
|
|
|
|
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;
|
2024-04-11 04:27:23 +00:00
|
|
|
import java.util.Objects;
|
2024-02-13 13:50:15 -08:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2023-05-25 02:25:19 +01:00
|
|
|
|
2024-04-11 04:27:23 +00:00
|
|
|
public class PortraitLandscapeRunner<LAUNCHER_TYPE extends Launcher> implements TestRule {
|
2019-07-19 12:12:49 -07:00
|
|
|
private static final String TAG = "PortraitLandscapeRunner";
|
2024-04-11 04:27:23 +00:00
|
|
|
private AbstractLauncherUiTest<LAUNCHER_TYPE> mTest;
|
2019-06-11 19:15:14 -07:00
|
|
|
|
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 {
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-11 04:27:23 +00:00
|
|
|
public PortraitLandscapeRunner(AbstractLauncherUiTest<LAUNCHER_TYPE> test) {
|
2019-06-11 19:15:14 -07:00
|
|
|
mTest = test;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Statement apply(Statement base, Description description) {
|
2023-09-12 14:55:43 -07:00
|
|
|
if (!TestHelpers.isInLauncherProcess()
|
2024-04-01 18:06:25 -07: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 {
|
2024-03-07 18:26:29 -08:00
|
|
|
try {
|
|
|
|
|
// we expect to begin unlocked...
|
|
|
|
|
AbstractLauncherUiTest.verifyKeyguardInvisible();
|
2024-01-31 19:35:40 +00:00
|
|
|
|
2024-03-07 18:26:29 -08:00
|
|
|
mTest.mDevice.pressHome();
|
|
|
|
|
mTest.waitForLauncherCondition("Launcher activity wasn't created",
|
2024-04-11 04:27:23 +00:00
|
|
|
Objects::nonNull,
|
2024-03-07 18:26:29 -08:00
|
|
|
TimeUnit.SECONDS.toMillis(20));
|
2019-06-11 19:15:14 -07:00
|
|
|
|
2024-03-07 18:26:29 -08:00
|
|
|
mTest.executeOnLauncher(launcher ->
|
|
|
|
|
launcher.getRotationHelper().forceAllowRotationForTesting(
|
|
|
|
|
true));
|
|
|
|
|
|
|
|
|
|
} catch (Throwable e) {
|
2024-04-29 11:51:54 -07:00
|
|
|
FailureWatcher.onError(mTest.mLauncher, description);
|
2024-03-07 18:26:29 -08:00
|
|
|
throw e;
|
|
|
|
|
}
|
2019-06-11 19:15:14 -07:00
|
|
|
|
|
|
|
|
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);
|
2024-01-31 19:35:40 +00:00
|
|
|
|
|
|
|
|
// and end unlocked...
|
|
|
|
|
AbstractLauncherUiTest.verifyKeyguardInvisible();
|
2019-06-11 19:15:14 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void evaluateInPortrait() throws Throwable {
|
|
|
|
|
mTest.mDevice.setOrientationNatural();
|
|
|
|
|
mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
|
2023-10-04 10:15:05 -07:00
|
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher, true);
|
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);
|
2023-10-04 10:15:05 -07:00
|
|
|
AbstractLauncherUiTest.checkDetectedLeaks(mTest.mLauncher, true);
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|