1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.documentsui.services; 18 19 import static com.android.documentsui.services.FileOperationService.OPERATION_DELETE; 20 21 import static com.google.common.collect.Lists.newArrayList; 22 23 import android.net.Uri; 24 import android.provider.DocumentsContract; 25 26 import androidx.test.filters.MediumTest; 27 28 import java.util.List; 29 30 @MediumTest 31 public class DeleteJobTest extends AbstractJobTest<DeleteJob> { 32 testDeleteFiles()33 public void testDeleteFiles() throws Exception { 34 Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt"); 35 mDocs.writeDocument(testFile1, HAM_BYTES); 36 37 Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt"); 38 mDocs.writeDocument(testFile2, FRUITY_BYTES); 39 40 DeleteJob job = createJob(newArrayList(testFile1, testFile2), 41 DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId)); 42 job.run(); 43 mJobListener.waitForFinished(); 44 45 mDocs.assertChildCount(mSrcRoot, 0); 46 47 var progress = job.getJobProgress(); 48 assertEquals(Job.STATE_COMPLETED, progress.state); 49 assertFalse(progress.hasFailures); 50 assertEquals("Deleting 2 files", progress.msg); 51 } 52 testDeleteFiles_NoSrcParent()53 public void testDeleteFiles_NoSrcParent() throws Exception { 54 Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt"); 55 mDocs.writeDocument(testFile1, HAM_BYTES); 56 57 Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt"); 58 mDocs.writeDocument(testFile2, FRUITY_BYTES); 59 60 DeleteJob job = createJob(newArrayList(testFile1, testFile2), null); 61 job.run(); 62 mJobListener.waitForFinished(); 63 64 mDocs.assertChildCount(mSrcRoot, 0); 65 var progress = job.getJobProgress(); 66 assertEquals(Job.STATE_COMPLETED, progress.state); 67 assertFalse(progress.hasFailures); 68 assertEquals("Deleting 2 files", progress.msg); 69 } 70 71 /** 72 * Creates a job with a stack consisting to the default src directory. 73 */ createJob(List<Uri> srcs, Uri srcParent)74 private DeleteJob createJob(List<Uri> srcs, Uri srcParent) throws Exception { 75 Uri stack = DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId); 76 return createJob(OPERATION_DELETE, srcs, srcParent, stack); 77 } 78 } 79