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

Commit 19a9703e authored by Austin Tankiang's avatar Austin Tankiang
Browse files

Improve cancellation tests related to pending jobs

This catches the bugs fixed in ag/32964004 by having the tests cancel
jobs via the service rather than directly on the job, and also adding a
test to test cancelling jobs with jobs queued up.

Bug: 400352714
Test: atest -c 'DocumentsUIGoogleTests:com.android.documentsui.services.FileOperationServiceTest'
Flag: com.android.documentsui.flags.visual_signals_ro
Change-Id: I73d3b0245ec257feaf1f4d2ff133e67e0215d0a3
parent 6d5fd4a9
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()