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 createJob(newArrayList(testFile1, testFile2), 41 DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId)).run(); 42 mJobListener.waitForFinished(); 43 44 mDocs.assertChildCount(mSrcRoot, 0); 45 } 46 testDeleteFiles_NoSrcParent()47 public void testDeleteFiles_NoSrcParent() throws Exception { 48 Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt"); 49 mDocs.writeDocument(testFile1, HAM_BYTES); 50 51 Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt"); 52 mDocs.writeDocument(testFile2, FRUITY_BYTES); 53 54 createJob(newArrayList(testFile1, testFile2), null).run(); 55 mJobListener.waitForFinished(); 56 57 mDocs.assertChildCount(mSrcRoot, 0); 58 } 59 60 /** 61 * Creates a job with a stack consisting to the default src directory. 62 */ createJob(List<Uri> srcs, Uri srcParent)63 private DeleteJob createJob(List<Uri> srcs, Uri srcParent) throws Exception { 64 Uri stack = DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId); 65 return createJob(OPERATION_DELETE, srcs, srcParent, stack); 66 } 67 } 68