OSDN Git Service

Improved test case by checking for dangling service.
authorFelipe Leme <felipeal@google.com>
Wed, 9 Dec 2015 19:04:59 +0000 (11:04 -0800)
committerFelipe Leme <felipeal@google.com>
Wed, 9 Dec 2015 19:28:11 +0000 (11:28 -0800)
This check will make it easier to refactor how the bugreport is shared, which is a requirement for showing the bugreport details window.

BUG: 25794470
Change-Id: If29f0515586c6680a44e0d52c4fc587808e668aa

packages/Shell/tests/src/com/android/shell/BugreportReceiverTest.java
packages/Shell/tests/src/com/android/shell/UiBot.java

index 0e31cdf..44018a0 100644 (file)
@@ -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(
index 5e8bab1..7d37137 100644 (file)
@@ -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) {