diff options
author | Felipe Leme <felipeal@google.com> | 2016-07-15 10:40:00 -0700 |
---|---|---|
committer | Felipe Leme <felipeal@google.com> | 2016-07-18 13:29:46 -0700 |
commit | a86a3012ef689af659261b209da86f2e24ac21ec (patch) | |
tree | 6c4d5c9addfd39ce54cdce7ac9c4afcbe1de6b83 /packages/Shell/tests | |
parent | 2b1fa7f9237c9d720d2885781b59e1acad98dad2 (diff) |
Close details dialog when bugreport is canceled by user.
BUG: 30158896
Change-Id: I0eab22586f6b431f2abe837088d48a655e03d213
Diffstat (limited to 'packages/Shell/tests')
-rw-r--r-- | packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java | 34 | ||||
-rw-r--r-- | packages/Shell/tests/src/com/android/shell/UiBot.java | 27 |
2 files changed, 54 insertions, 7 deletions
diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java index 44e956abeb02..ad66dfc992d0 100644 --- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java +++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java @@ -153,7 +153,7 @@ public class BugreportReceiverTest extends InstrumentationTestCase { Log.i(TAG, "#### setup() on " + getName()); Instrumentation instrumentation = getInstrumentation(); mContext = instrumentation.getTargetContext(); - mUiBot = new UiBot(UiDevice.getInstance(instrumentation), TIMEOUT); + mUiBot = new UiBot(instrumentation, TIMEOUT); mListener = ActionSendMultipleConsumerActivity.getListener(mContext); cancelExistingNotifications(); @@ -233,10 +233,7 @@ public class BugreportReceiverTest extends InstrumentationTestCase { assertProgressNotification(NAME, 00.00f); - openProgressNotification(ID); - UiObject cancelButton = mUiBot.getVisibleObject(mContext.getString( - com.android.internal.R.string.cancel).toUpperCase()); - mUiBot.click(cancelButton, "cancel_button"); + cancelFromNotification(); waitForService(false); } @@ -323,6 +320,21 @@ public class BugreportReceiverTest extends InstrumentationTestCase { assertServiceNotRunning(); } + public void testProgress_cancelBugClosesDetailsDialog() throws Exception { + resetProperties(); + sendBugreportStarted(1000); + waitForScreenshotButtonEnabled(true); + + DetailsUi detailsUi = new DetailsUi(mUiBot, ID); + detailsUi.assertName(NAME); // Sanity check + + cancelFromNotification(); + mUiBot.closeNotifications(); + + assertDetailsUiClosed(); + assertServiceNotRunning(); + } + public void testProgress_changeDetailsPlainBugreport() throws Exception { changeDetailsTest(true); } @@ -579,6 +591,13 @@ public class BugreportReceiverTest extends InstrumentationTestCase { } } + private void cancelFromNotification() { + openProgressNotification(ID); + UiObject cancelButton = mUiBot.getVisibleObject(mContext.getString( + com.android.internal.R.string.cancel).toUpperCase()); + mUiBot.click(cancelButton, "cancel_button"); + } + private void assertProgressNotification(String name, float percent) { // TODO: it currently looks for 3 distinct objects, without taking advantage of their // relationship. @@ -929,6 +948,11 @@ public class BugreportReceiverTest extends InstrumentationTestCase { screenshotButton.isEnabled()); } + private void assertDetailsUiClosed() { + // TODO: unhardcode resource ids + mUiBot.assertNotVisibleById("android:id/alertTitle"); + } + /** * Helper class containing the UiObjects present in the bugreport info dialog. */ diff --git a/packages/Shell/tests/src/com/android/shell/UiBot.java b/packages/Shell/tests/src/com/android/shell/UiBot.java index 30f16928ba52..ef24791aac72 100644 --- a/packages/Shell/tests/src/com/android/shell/UiBot.java +++ b/packages/Shell/tests/src/com/android/shell/UiBot.java @@ -16,6 +16,8 @@ package com.android.shell; +import android.app.Instrumentation; +import android.app.StatusBarManager; import android.support.test.uiautomator.By; import android.support.test.uiautomator.UiDevice; import android.support.test.uiautomator.UiObject; @@ -24,6 +26,8 @@ import android.support.test.uiautomator.UiScrollable; import android.support.test.uiautomator.UiSelector; import android.support.test.uiautomator.Until; import android.util.Log; + +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; /** @@ -34,11 +38,13 @@ final class UiBot { private static final String TAG = "UiBot"; private static final String SYSTEMUI_PACKAGE = "com.android.systemui"; + private final Instrumentation mInstrumentation; private final UiDevice mDevice; private final int mTimeout; - public UiBot(UiDevice device, int timeout) { - mDevice = device; + public UiBot(Instrumentation instrumentation, int timeout) { + mInstrumentation = instrumentation; + mDevice = UiDevice.getInstance(instrumentation); mTimeout = timeout; } @@ -57,6 +63,13 @@ final class UiBot { return getObject(text); } + public void closeNotifications() throws Exception { + // TODO: mDevice should provide such method.. + StatusBarManager sbm = + (StatusBarManager) mInstrumentation.getContext().getSystemService("statusbar"); + sbm.collapsePanels(); + } + /** * Opens the system notification and clicks a given notification. * @@ -111,6 +124,16 @@ final class UiBot { return uiObject; } + /** + * Asserts an object is not visible. + */ + public void assertNotVisibleById(String id) { + // TODO: not working when the bugreport dialog is shown, it hangs until the dialog is + // dismissed and hence always work. + boolean hasIt = mDevice.hasObject(By.res(id)); + assertFalse("should not have found object with id '" + id+ "'", hasIt); + } + /** * Clicks on a UI element. |