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

Commit 67b1a972 authored by Austin Tankiang's avatar Austin Tankiang Committed by Android (Google) Code Review
Browse files

Merge "Improve cancellation tests related to pending jobs" into main

parents 42a85838 19a9703e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public class TestJob extends Job {

    @Override
    Notification getProgressNotification() {
        assertStarted();
        ++mNumOfNotifications;
        double completed = mStarted ? 1F : 0F;
        return mProgressBuilder
+25 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui.services;

import static com.android.documentsui.services.FileOperationService.EXTRA_CANCEL;
import static com.android.documentsui.services.FileOperationService.EXTRA_JOB_ID;
import static com.android.documentsui.services.FileOperationService.OPERATION_COPY;
import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE;
import static com.android.documentsui.services.FileOperations.createBaseIntent;
@@ -321,18 +323,32 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi
        mTestNotificationManager.assertHasNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, job2.id);

        job1.cancel();
        startService(createCancelIntent(job1.id));
        mService.onFinished(job1);
        mTestNotificationManager.assertHasNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, null);
        mTestNotificationManager.assertNoNotification(
                FileOperationService.NOTIFICATION_ID_PROGRESS, job2.id);

        job2.cancel();
        startService(createCancelIntent(job2.id));
        mService.onFinished(job2);
        mTestNotificationManager.assertNumberOfNotifications(0);
    }

    public void testCancelJobWithQueuedJobs() throws Exception {
        startService(createCopyIntent(Arrays.asList(ALPHA_DOC), BETA_DOC));
        startService(createCopyIntent(Arrays.asList(GAMMA_DOC), DELTA_DOC));
        Job job1 = mCopyJobs.get(0);
        Job job2 = mCopyJobs.get(1);

        mService.onStart(job1);
        startService(createCancelIntent(job1.id));
        mService.onFinished(job1);

        startService(createCancelIntent(job2.id));
        mTestNotificationManager.assertNumberOfNotifications(0);
    }

    private Intent createCopyIntent(List<DocumentInfo> files, DocumentInfo dest)
            throws Exception {
        DocumentStack stack = new DocumentStack();
@@ -363,6 +379,13 @@ public class FileOperationServiceTest extends ServiceTestCase<FileOperationServi
        return createBaseIntent(getContext(), createJobId(), operation);
    }

    private Intent createCancelIntent(String jobId) {
        Intent intent = new Intent(getContext(), FileOperationService.class);
        intent.putExtra(EXTRA_CANCEL, true);
        intent.putExtra(EXTRA_JOB_ID, jobId);
        return intent;
    }

    private static DocumentInfo createDoc(String name) {
        // Doesn't need to be valid content Uri, just some urly looking thing.
        Uri uri = new Uri.Builder()