• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.launcher3.ui;
2 
3 import android.view.Surface;
4 
5 import com.android.launcher3.tapl.TestHelpers;
6 
7 import org.junit.rules.TestRule;
8 import org.junit.runner.Description;
9 import org.junit.runners.model.Statement;
10 
11 class PortraitLandscapeRunner implements TestRule {
12     private AbstractLauncherUiTest mTest;
13 
PortraitLandscapeRunner(AbstractLauncherUiTest test)14     public PortraitLandscapeRunner(AbstractLauncherUiTest test) {
15         mTest = test;
16     }
17 
18     @Override
apply(Statement base, Description description)19     public Statement apply(Statement base, Description description) {
20         if (!TestHelpers.isInLauncherProcess() ||
21                 description.getAnnotation(AbstractLauncherUiTest.PortraitLandscape.class) == null) {
22             return base;
23         }
24 
25         return new Statement() {
26             @Override
27             public void evaluate() throws Throwable {
28                 try {
29                     mTest.mDevice.pressHome();
30                     mTest.waitForLauncherCondition("Launcher activity wasn't created",
31                             launcher -> launcher != null);
32 
33                     mTest.executeOnLauncher(launcher ->
34                             launcher.getRotationHelper().forceAllowRotationForTesting(
35                                     true));
36 
37                     evaluateInPortrait();
38                     evaluateInLandscape();
39                 } finally {
40                     mTest.mDevice.setOrientationNatural();
41                     mTest.executeOnLauncher(launcher ->
42                             launcher.getRotationHelper().forceAllowRotationForTesting(
43                                     false));
44                     mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
45                 }
46             }
47 
48             private void evaluateInPortrait() throws Throwable {
49                 mTest.mDevice.setOrientationNatural();
50                 mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
51                 base.evaluate();
52                 mTest.getDevice().pressHome();
53             }
54 
55             private void evaluateInLandscape() throws Throwable {
56                 mTest.mDevice.setOrientationLeft();
57                 mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
58                 base.evaluate();
59                 mTest.getDevice().pressHome();
60             }
61         };
62     }
63 }
64