• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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_MOVE;
20 
21 import static com.google.common.collect.Lists.newArrayList;
22 
23 import android.net.Uri;
24 import android.provider.DocumentsContract.Document;
25 
26 import androidx.test.filters.MediumTest;
27 
28 @MediumTest
29 public class MoveJobTest extends AbstractCopyJobTest<MoveJob> {
30 
MoveJobTest()31     public MoveJobTest() {
32         super(OPERATION_MOVE);
33     }
34 
testMoveFiles()35     public void testMoveFiles() throws Exception {
36         runCopyFilesTest();
37 
38         mDocs.assertChildCount(mSrcRoot, 0);
39     }
40 
testMoveFiles_NoSrcParent()41     public void testMoveFiles_NoSrcParent() throws Exception {
42         Uri testFile1 = mDocs.createDocument(mSrcRoot, "text/plain", "test1.txt");
43         mDocs.writeDocument(testFile1, HAM_BYTES);
44 
45         Uri testFile2 = mDocs.createDocument(mSrcRoot, "text/plain", "test2.txt");
46         mDocs.writeDocument(testFile2, FRUITY_BYTES);
47 
48         createJob(newArrayList(testFile1, testFile2), null).run();
49         waitForJobFinished();
50 
51         mDocs.assertChildCount(mDestRoot, 2);
52         mDocs.assertHasFile(mDestRoot, "test1.txt");
53         mDocs.assertHasFile(mDestRoot, "test2.txt");
54         mDocs.assertFileContents(mDestRoot.documentId, "test1.txt", HAM_BYTES);
55         mDocs.assertFileContents(mDestRoot.documentId, "test2.txt", FRUITY_BYTES);
56     }
57 
testMoveVirtualTypedFile()58     public void testMoveVirtualTypedFile() throws Exception {
59         mDocs.createFolder(mSrcRoot, "hello");
60         Uri testFile = mDocs.createVirtualFile(
61                 mSrcRoot, "/hello/virtual.sth", "virtual/mime-type",
62                 FRUITY_BYTES, "application/pdf", "text/html");
63         createJob(newArrayList(testFile)).run();
64 
65         waitForJobFinished();
66 
67         // Should have failed, source not deleted. Moving by bytes for virtual files
68         // is not supported.
69         mDocs.assertChildCount(mDestRoot, 0);
70         mDocs.assertChildCount(mSrcRoot, 1);
71     }
72 
testMoveVirtualNonTypedFile()73     public void testMoveVirtualNonTypedFile() throws Exception {
74         runCopyVirtualNonTypedFileTest();
75 
76         // Should have failed, source not deleted.
77         mDocs.assertChildCount(mSrcRoot, 1);
78     }
79 
testMove_BackendSideVirtualTypedFile_Fallback()80     public void testMove_BackendSideVirtualTypedFile_Fallback() throws Exception {
81         Uri testFile = mDocs.createDocumentWithFlags(
82                 mSrcRoot.documentId, "virtual/mime-type", "tokyo.sth",
83                 Document.FLAG_VIRTUAL_DOCUMENT | Document.FLAG_SUPPORTS_COPY
84                         | Document.FLAG_SUPPORTS_MOVE, "application/pdf");
85 
86         createJob(newArrayList(testFile)).run();
87         waitForJobFinished();
88 
89         // Should have failed, source not deleted. Moving by bytes for virtual files
90         // is not supported.
91         mDocs.assertChildCount(mDestRoot, 0);
92         mDocs.assertChildCount(mSrcRoot, 1);
93     }
94 
testMoveEmptyDir()95     public void testMoveEmptyDir() throws Exception {
96         runCopyEmptyDirTest();
97 
98         mDocs.assertChildCount(mSrcRoot, 0);
99     }
100 
testMoveDirRecursively()101     public void testMoveDirRecursively() throws Exception {
102         runCopyDirRecursivelyTest();
103 
104         mDocs.assertChildCount(mSrcRoot, 0);
105     }
106 
testMoveDirRecursively_loadingInFirstCursor()107     public void testMoveDirRecursively_loadingInFirstCursor() throws Exception {
108         mDocs.setLoadingDuration(500);
109         testMoveDirRecursively();
110     }
111 
testNoMoveDirToSelf()112     public void testNoMoveDirToSelf() throws Exception {
113         runNoCopyDirToSelfTest();
114 
115         // should have failed, source not deleted
116         mDocs.assertChildCount(mSrcRoot, 1);
117     }
118 
testNoMoveDirToDescendent()119     public void testNoMoveDirToDescendent() throws Exception {
120         runNoCopyDirToDescendentTest();
121 
122         // should have failed, source not deleted
123         mDocs.assertChildCount(mSrcRoot, 1);
124     }
125 
testMoveFileWithReadErrors()126     public void testMoveFileWithReadErrors() throws Exception {
127         runCopyFileWithReadErrorsTest();
128 
129         // should have failed, source not deleted
130         mDocs.assertChildCount(mSrcRoot, 1);
131     }
132 
133     // TODO: Add test cases for moving when multi-parented.
134 }
135