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