Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d7963806 authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Improved test case by checking for dangling service."

parents ac751885 ba477939
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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(
+2 −1
Original line number Diff line number Diff line
@@ -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) {