Close details dialog when bugreport is canceled by user.

BUG: 30158896
Change-Id: I0eab22586f6b431f2abe837088d48a655e03d213
This commit is contained in:
Felipe Leme
2016-07-15 10:40:00 -07:00
parent 2b1fa7f923
commit a86a3012ef
3 changed files with 66 additions and 9 deletions

View File

@@ -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.
*/

View File

@@ -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.