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

Commit ba477939 authored by Felipe Leme's avatar Felipe Leme
Browse files

Improved test case by checking for dangling service.

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
parent 67b39bfa
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) {