diff options
| author | 2015-12-10 02:03:06 +0000 | |
|---|---|---|
| committer | 2015-12-10 02:03:06 +0000 | |
| commit | d7963806f15a1435d3e6c8023cd55b5a84340e77 (patch) | |
| tree | ca067dd6b6d70f2499e722f39cb9a1a74fc7c725 | |
| parent | ac7518854ee0dba6a79d778db176ffbd0c6dd85f (diff) | |
| parent | ba477939f0ae38926b4b0a6501a2371acc612433 (diff) | |
Merge "Improved test case by checking for dangling service."
| -rw-r--r-- | packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java | 16 | ||||
| -rw-r--r-- | packages/Shell/tests/src/com/android/shell/UiBot.java | 3 |
2 files changed, 17 insertions, 2 deletions
diff --git a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java index 0e31cdf4a0e2..44018a024432 100644 --- a/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java +++ b/packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java @@ -40,6 +40,8 @@ import java.util.zip.ZipInputStream; import java.util.zip.ZipOutputStream; import libcore.io.Streams; +import android.app.ActivityManager; +import android.app.ActivityManager.RunningServiceInfo; import android.app.Instrumentation; import android.app.NotificationManager; import android.content.Context; @@ -130,7 +132,8 @@ public class BugreportReceiverTest extends InstrumentationTestCase { Bundle extras = sendBugreportFinishedIntent(42, PLAIN_TEXT_PATH, SCREENSHOT_PATH); assertActionSendMultiple(extras, BUGREPORT_CONTENT, SCREENSHOT_CONTENT); - // TODO: assert service is down + String service = BugreportProgressService.class.getName(); + assertFalse("Service '" + service + "' is still running", isServiceRunning(service)); } public void testBugreportFinished_withWarning() throws Exception { @@ -306,6 +309,17 @@ public class BugreportReceiverTest extends InstrumentationTestCase { fail("Did not find entry '" + entryName + "' on file '" + uri + "'"); } + private boolean isServiceRunning(String name) { + ActivityManager manager = (ActivityManager) mContext + .getSystemService(Context.ACTIVITY_SERVICE); + for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { + if (service.service.getClassName().equals(name)) { + return true; + } + } + return false; + } + private static void createTextFile(String path, String content) throws IOException { Log.v(TAG, "createFile(" + path + ")"); try (Writer writer = new BufferedWriter(new OutputStreamWriter( diff --git a/packages/Shell/tests/src/com/android/shell/UiBot.java b/packages/Shell/tests/src/com/android/shell/UiBot.java index 5e8bab1d7a3c..7d3713724e76 100644 --- a/packages/Shell/tests/src/com/android/shell/UiBot.java +++ b/packages/Shell/tests/src/com/android/shell/UiBot.java @@ -118,7 +118,8 @@ final class UiBot { // TODO: UI Automator should provide such logic. public void chooseActivity(String name) { // First check if the activity is the default option. - String shareText = String.format("Share with %s", name); + String shareText = "Share with " + name; + Log.v(TAG, "Waiting for ActivityChooser text: '" + shareText + "'"); boolean gotIt = mDevice.wait(Until.hasObject(By.text(shareText)), mTimeout); if (gotIt) { |