Steve McKay | bbeba52 | 2016-01-13 17:17:39 -0800 | [diff] [blame^] | 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 android.net.Uri; |
| 20 | import android.test.suitebuilder.annotation.MediumTest; |
| 21 | |
| 22 | import com.android.documentsui.model.DocumentInfo; |
| 23 | import com.android.documentsui.model.DocumentStack; |
| 24 | |
| 25 | import com.google.common.collect.Lists; |
| 26 | |
| 27 | import java.util.List; |
| 28 | |
| 29 | @MediumTest |
| 30 | public class MoveJobTest extends BaseCopyJobTest { |
| 31 | |
| 32 | public void testMoveFiles() throws Exception { |
| 33 | runCopyFilesTest(); |
| 34 | |
| 35 | mDocs.assertChildCount(mSrcRoot, 0); |
| 36 | } |
| 37 | |
| 38 | public void testMoveVirtualTypedFile() throws Exception { |
| 39 | runCopyVirtualTypedFileTest(); |
| 40 | |
| 41 | mDocs.assertChildCount(mSrcRoot, 0); |
| 42 | } |
| 43 | |
| 44 | public void testMoveVirtualNonTypedFile() throws Exception { |
| 45 | runCopyVirtualNonTypedFileTest(); |
| 46 | |
| 47 | // should have failed, source not deleted |
| 48 | mDocs.assertChildCount(mSrcRoot, 1); |
| 49 | } |
| 50 | |
| 51 | public void testMoveEmptyDir() throws Exception { |
| 52 | runCopyEmptyDirTest(); |
| 53 | |
| 54 | mDocs.assertChildCount(mSrcRoot, 0); |
| 55 | } |
| 56 | |
| 57 | public void testMoveDirRecursively() throws Exception { |
| 58 | runCopyDirRecursivelyTest(); |
| 59 | |
| 60 | mDocs.assertChildCount(mSrcRoot, 0); |
| 61 | } |
| 62 | |
| 63 | public void testNoMoveDirToSelf() throws Exception { |
| 64 | runNoCopyDirToSelfTest(); |
| 65 | |
| 66 | // should have failed, source not deleted |
| 67 | mDocs.assertChildCount(mSrcRoot, 1); |
| 68 | } |
| 69 | |
| 70 | public void testNoMoveDirToDescendent() throws Exception { |
| 71 | runNoCopyDirToDescendentTest(); |
| 72 | |
| 73 | // should have failed, source not deleted |
| 74 | mDocs.assertChildCount(mSrcRoot, 1); |
| 75 | } |
| 76 | |
| 77 | public void testMoveFileWithReadErrors() throws Exception { |
| 78 | runCopyFileWithReadErrorsTest(); |
| 79 | |
| 80 | // should have failed, source not deleted |
| 81 | mDocs.assertChildCount(mSrcRoot, 1); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | CopyJob createJob(List<Uri> srcs, Uri destination) throws Exception { |
| 86 | DocumentStack stack = new DocumentStack(); |
| 87 | stack.push(DocumentInfo.fromUri(mResolver, destination)); |
| 88 | |
| 89 | List<DocumentInfo> srcDocs = Lists.newArrayList(); |
| 90 | for (Uri src : srcs) { |
| 91 | srcDocs.add(DocumentInfo.fromUri(mResolver, src)); |
| 92 | } |
| 93 | |
| 94 | return new MoveJob( |
| 95 | mContext, mContext, mJobListener, FileOperations.createJobId(), stack, srcDocs); |
| 96 | } |
| 97 | } |