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