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; 18 19 import static com.android.documentsui.StubProvider.ROOT_0_ID; 20 import static com.android.documentsui.StubProvider.ROOT_1_ID; 21 22 import android.net.Uri; 23 import android.os.RemoteException; 24 import android.support.test.filters.LargeTest; 25 import android.support.test.filters.Suppress; 26 import android.view.KeyEvent; 27 28 import com.android.documentsui.files.FilesActivity; 29 30 @LargeTest 31 public class FileManagementUiTest extends ActivityTest<FilesActivity> { 32 FileManagementUiTest()33 public FileManagementUiTest() { 34 super(FilesActivity.class); 35 } 36 37 @Override setUp()38 public void setUp() throws Exception { 39 super.setUp(); 40 initTestFiles(); 41 } 42 43 @Override initTestFiles()44 public void initTestFiles() throws RemoteException { 45 Uri uri = mDocsHelper.createFolder(rootDir0, dirName1); 46 mDocsHelper.createFolder(uri, childDir1); 47 48 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); 49 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); 50 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); 51 52 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); 53 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); 54 } 55 56 @Suppress testCreateDirectory()57 public void testCreateDirectory() throws Exception { 58 bots.main.openOverflowMenu(); 59 device.waitForIdle(); 60 61 bots.main.clickToolbarOverflowItem("New folder"); 62 device.waitForIdle(); 63 64 bots.main.setDialogText("Kung Fu Panda"); 65 device.waitForIdle(); 66 67 bots.keyboard.pressEnter(); 68 69 bots.directory.waitForDocument("Kung Fu Panda"); 70 } 71 testDeleteDocument()72 public void testDeleteDocument() throws Exception { 73 bots.directory.clickDocument("file1.png"); 74 device.waitForIdle(); 75 bots.main.clickToolbarItem(R.id.menu_delete); 76 77 bots.main.clickDialogOkButton(); 78 device.waitForIdle(); 79 80 bots.directory.assertDocumentsAbsent("file1.png"); 81 } 82 testKeyboard_CutDocument()83 public void testKeyboard_CutDocument() throws Exception { 84 bots.directory.clickDocument("file1.png"); 85 device.waitForIdle(); 86 bots.keyboard.pressKey(KeyEvent.KEYCODE_X, KeyEvent.META_CTRL_ON); 87 88 device.waitForIdle(); 89 90 bots.roots.openRoot(ROOT_1_ID); 91 bots.keyboard.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON); 92 93 bots.directory.waitForDocument("file1.png"); 94 bots.directory.assertDocumentsPresent("file1.png"); 95 96 bots.roots.openRoot(ROOT_0_ID); 97 bots.directory.assertDocumentsAbsent("file1.png"); 98 } 99 testKeyboard_CopyDocument()100 public void testKeyboard_CopyDocument() throws Exception { 101 bots.directory.clickDocument("file1.png"); 102 device.waitForIdle(); 103 bots.keyboard.pressKey(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON); 104 105 device.waitForIdle(); 106 107 bots.roots.openRoot(ROOT_1_ID); 108 bots.keyboard.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON); 109 110 bots.directory.waitForDocument("file1.png"); 111 112 bots.roots.openRoot(ROOT_0_ID); 113 bots.directory.waitForDocument("file1.png"); 114 } 115 testDeleteDocument_Cancel()116 public void testDeleteDocument_Cancel() throws Exception { 117 bots.directory.clickDocument("file1.png"); 118 device.waitForIdle(); 119 bots.main.clickToolbarItem(R.id.menu_delete); 120 121 bots.main.clickDialogCancelButton(); 122 123 bots.directory.waitForDocument("file1.png"); 124 } 125 } 126