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 import android.support.test.filters.MediumTest;
26 
27 import java.util.List;
28 
29 @MediumTest
30 public class DeleteJobTest extends AbstractJobTest<DeleteJob> {
31 
testDeleteFiles()32     public void testDeleteFiles() throws Exception {
33         Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt");
34         mDocs.writeDocument(testFile1, HAM_BYTES);
35 
36         Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt");
37         mDocs.writeDocument(testFile2, FRUITY_BYTES);
38 
39         createJob(newArrayList(testFile1, testFile2),
40                 DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId)).run();
41         mJobListener.waitForFinished();
42 
43         mDocs.assertChildCount(mSrcRoot, 0);
44     }
45 
testDeleteFiles_NoSrcParent()46     public void testDeleteFiles_NoSrcParent() throws Exception {
47         Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt");
48         mDocs.writeDocument(testFile1, HAM_BYTES);
49 
50         Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt");
51         mDocs.writeDocument(testFile2, FRUITY_BYTES);
52 
53         createJob(newArrayList(testFile1, testFile2), null).run();
54         mJobListener.waitForFinished();
55 
56         mDocs.assertChildCount(mSrcRoot, 0);
57     }
58 
59     /**
60      * Creates a job with a stack consisting to the default src directory.
61      */
createJob(List<Uri> srcs, Uri srcParent)62     private final DeleteJob createJob(List<Uri> srcs, Uri srcParent) throws Exception {
63         Uri stack = DocumentsContract.buildDocumentUri(AUTHORITY, mSrcRoot.documentId);
64         return createJob(OPERATION_DELETE, srcs, srcParent, stack);
65     }
66 }
67