diff options
author | vadimt <vadimt@google.com> | 2019-08-23 20:56:08 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-08-23 20:56:08 -0700 |
commit | 0d6f41bef2d751df6681df6f1dedfe1132b72a86 (patch) | |
tree | a494d85e74751707c014cc374f189ee077552dce | |
parent | 7468bbd2d4bb6761d2af9a1108e77e794102ad03 (diff) | |
parent | f13eaa02427ea536d9a3be077aa267f706f0a5e1 (diff) | |
download | android_packages_apps_Trebuchet-0d6f41bef2d751df6681df6f1dedfe1132b72a86.tar.gz android_packages_apps_Trebuchet-0d6f41bef2d751df6681df6f1dedfe1132b72a86.tar.bz2 android_packages_apps_Trebuchet-0d6f41bef2d751df6681df6f1dedfe1132b72a86.zip |
Saving screenshots for failures in NavigationModeSwitchRule
am: f13eaa0242
Change-Id: I9a3b4e93491a02263fd90640b3cc9d55aeb41703
-rw-r--r-- | quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java | 19 | ||||
-rw-r--r-- | tests/src/com/android/launcher3/util/rule/FailureWatcher.java | 16 |
2 files changed, 24 insertions, 11 deletions
diff --git a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java index f27f40088..edd5011f2 100644 --- a/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java +++ b/quickstep/tests/src/com/android/quickstep/NavigationModeSwitchRule.java @@ -34,9 +34,9 @@ import androidx.test.uiautomator.UiDevice; import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.TestHelpers; +import com.android.launcher3.util.rule.FailureWatcher; import com.android.systemui.shared.system.QuickStepContract; -import org.junit.Assert; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -79,6 +79,14 @@ public class NavigationModeSwitchRule implements TestRule { description.getAnnotation(NavigationModeSwitch.class) != null) { Mode mode = description.getAnnotation(NavigationModeSwitch.class).mode(); return new Statement() { + private void assertTrue(String message, boolean condition) { + if(!condition) { + final AssertionError assertionError = new AssertionError(message); + FailureWatcher.onError(mLauncher.getDevice(), description, assertionError); + throw assertionError; + } + } + @Override public void evaluate() throws Throwable { mLauncher.enableDebugTracing(); @@ -107,7 +115,8 @@ public class NavigationModeSwitchRule implements TestRule { Log.e(TAG, "Exception", e); throw e; } finally { - Assert.assertTrue(setActiveOverlay(prevOverlayPkg, originalMode)); + assertTrue("Couldn't set overlay", + setActiveOverlay(prevOverlayPkg, originalMode)); } mLauncher.disableDebugTracing(); } @@ -176,7 +185,7 @@ public class NavigationModeSwitchRule implements TestRule { latch.await(10, TimeUnit.SECONDS); targetContext.getMainExecutor().execute(() -> sysUINavigationMode.removeModeChangeListener(listener)); - Assert.assertTrue("Navigation mode didn't change to " + expectedMode, + assertTrue("Navigation mode didn't change to " + expectedMode, currentSysUiNavigationMode() == expectedMode); } @@ -184,7 +193,7 @@ public class NavigationModeSwitchRule implements TestRule { if (mLauncher.getNavigationModel() == expectedMode) break; Thread.sleep(100); } - Assert.assertTrue("Couldn't switch to " + overlayPackage, + assertTrue("Couldn't switch to " + overlayPackage, mLauncher.getNavigationModel() == expectedMode); for (int i = 0; i != 100; ++i) { @@ -192,7 +201,7 @@ public class NavigationModeSwitchRule implements TestRule { Thread.sleep(100); } final String error = mLauncher.getNavigationModeMismatchError(); - Assert.assertTrue("Switching nav mode: " + error, error == null); + assertTrue("Switching nav mode: " + error, error == null); Thread.sleep(5000); return true; diff --git a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java index e7a2bcab6..cdda0f0dc 100644 --- a/tests/src/com/android/launcher3/util/rule/FailureWatcher.java +++ b/tests/src/com/android/launcher3/util/rule/FailureWatcher.java @@ -21,10 +21,10 @@ public class FailureWatcher extends TestWatcher { mDevice = device; } - private void dumpViewHierarchy() { + private static void dumpViewHierarchy(UiDevice device) { final ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { - mDevice.dumpWindowHierarchy(stream); + device.dumpWindowHierarchy(stream); stream.flush(); stream.close(); for (String line : stream.toString().split("\\r?\\n")) { @@ -37,7 +37,11 @@ public class FailureWatcher extends TestWatcher { @Override protected void failed(Throwable e, Description description) { - if (mDevice == null) return; + onError(mDevice, description, e); + } + + public static void onError(UiDevice device, Description description, Throwable e) { + if (device == null) return; final String pathname = getInstrumentation().getTargetContext(). getFilesDir().getPath() + "/TestScreenshot-" + description.getMethodName() + ".png"; @@ -45,15 +49,15 @@ public class FailureWatcher extends TestWatcher { ", screenshot will be saved to " + pathname + ", track trace is below, UI object dump is further below:\n" + Log.getStackTraceString(e)); - dumpViewHierarchy(); + dumpViewHierarchy(device); try { - final String dumpsysResult = mDevice.executeShellCommand( + final String dumpsysResult = device.executeShellCommand( "dumpsys activity service TouchInteractionService"); Log.d(TAG, "TouchInteractionService: " + dumpsysResult); } catch (IOException ex) { } - mDevice.takeScreenshot(new File(pathname)); + device.takeScreenshot(new File(pathname)); } } |