Steve McKay | 0179257 | 2015-10-23 11:46:01 -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 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 19 | import static com.android.documentsui.StubProvider.ROOT_0_ID; |
| 20 | import static com.android.documentsui.StubProvider.ROOT_1_ID; |
| 21 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 22 | import android.os.RemoteException; |
Steve McKay | 53c774b | 2015-11-12 10:54:31 +0900 | [diff] [blame] | 23 | import android.test.suitebuilder.annotation.LargeTest; |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 24 | import android.view.KeyEvent; |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 25 | |
Aga Wronska | b9eeee1 | 2016-02-24 12:57:21 -0800 | [diff] [blame] | 26 | import com.android.documentsui.model.RootInfo; |
| 27 | |
Steve McKay | 53c774b | 2015-11-12 10:54:31 +0900 | [diff] [blame] | 28 | @LargeTest |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 29 | public class FilesActivityUiTest extends ActivityTest<FilesActivity> { |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 30 | |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 31 | public FilesActivityUiTest() { |
| 32 | super(FilesActivity.class); |
| 33 | } |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 34 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 35 | @Override |
Aga Wronska | b9eeee1 | 2016-02-24 12:57:21 -0800 | [diff] [blame] | 36 | protected RootInfo getInitialRoot() { |
| 37 | return null; |
| 38 | } |
| 39 | |
| 40 | @Override |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 41 | public void initTestFiles() throws RemoteException { |
| 42 | mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); |
| 43 | mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); |
| 44 | mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 45 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 46 | mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); |
| 47 | mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | public void testRootsListed() throws Exception { |
| 51 | initTestFiles(); |
| 52 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 53 | bots.roots.openRoot(ROOT_0_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 54 | |
| 55 | // Should also have Drive, but that requires pre-configuration of devices |
| 56 | // We omit for now. |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 57 | bots.roots.assertHasRoots( |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 58 | "Images", |
| 59 | "Videos", |
| 60 | "Audio", |
| 61 | "Downloads", |
Steve McKay | a6bbeab | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 62 | "Documents", |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 63 | ROOT_0_ID, |
| 64 | ROOT_1_ID); |
| 65 | } |
| 66 | |
| 67 | public void testFilesListed() throws Exception { |
| 68 | initTestFiles(); |
| 69 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 70 | bots.roots.openRoot(ROOT_0_ID); |
| 71 | bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Steve McKay | a6bbeab | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 74 | public void testLoadsHomeDirectoryByDefault() throws Exception { |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 75 | initTestFiles(); |
| 76 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 77 | device.waitForIdle(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 78 | bots.main.assertWindowTitle("Documents"); |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 81 | public void testRootClickSetsWindowTitle() throws Exception { |
| 82 | initTestFiles(); |
| 83 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 84 | bots.roots.openRoot("Downloads"); |
| 85 | bots.main.assertWindowTitle("Downloads"); |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 86 | } |
| 87 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 88 | public void testFilesList_LiveUpdate() throws Exception { |
| 89 | initTestFiles(); |
| 90 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 91 | bots.roots.openRoot(ROOT_0_ID); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 92 | mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); |
Tomasz Mikolajewski | b005e14 | 2016-02-02 19:26:09 +0900 | [diff] [blame] | 93 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 94 | bots.directory.waitForDocument("Ham & Cheese.sandwich"); |
| 95 | bots.directory.assertDocumentsPresent( |
| 96 | "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); |
| 97 | } |
| 98 | |
| 99 | public void testCreateDirectory() throws Exception { |
| 100 | initTestFiles(); |
| 101 | |
Aga Wronska | 568b3b3 | 2016-02-23 10:49:29 -0800 | [diff] [blame] | 102 | bots.roots.openRoot(ROOT_0_ID); |
| 103 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 104 | bots.main.openOverflowMenu(); |
| 105 | bots.main.menuNewFolder().click(); |
| 106 | bots.main.setDialogText("Kung Fu Panda"); |
| 107 | |
| 108 | bots.keyboard.pressEnter(); |
| 109 | |
| 110 | bots.directory.assertDocumentsPresent("Kung Fu Panda"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | public void testDeleteDocument() throws Exception { |
| 114 | initTestFiles(); |
| 115 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 116 | bots.roots.openRoot(ROOT_0_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 117 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 118 | bots.directory.clickDocument("file1.png"); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 119 | device.waitForIdle(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 120 | bots.main.menuDelete().click(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 121 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 122 | bots.main.findDialogOkButton().click(); |
| 123 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 124 | bots.directory.assertDocumentsAbsent("file1.png"); |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 125 | } |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 126 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 127 | public void testDeleteDocument_Cancel() throws Exception { |
| 128 | initTestFiles(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 129 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 130 | bots.roots.openRoot(ROOT_0_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 131 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 132 | bots.directory.clickDocument("file1.png"); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 133 | device.waitForIdle(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 134 | bots.main.menuDelete().click(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 135 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 136 | bots.main.findDialogCancelButton().click(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 137 | |
Steve McKay | 7a3b811 | 2016-02-23 10:06:50 -0800 | [diff] [blame] | 138 | bots.directory.assertDocumentsPresent("file1.png"); |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 139 | } |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 140 | |
| 141 | // Tests that pressing tab switches focus between the roots and directory listings. |
| 142 | public void testKeyboard_tab() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 143 | bots.main.pressKey(KeyEvent.KEYCODE_TAB); |
| 144 | bots.roots.assertHasFocus(); |
| 145 | bots.main.pressKey(KeyEvent.KEYCODE_TAB); |
| 146 | bots.directory.assertHasFocus(); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // Tests that arrow keys do not switch focus away from the dir list. |
| 150 | public void testKeyboard_arrowsDirList() throws Exception { |
| 151 | for (int i = 0; i < 10; i++) { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 152 | bots.main.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); |
| 153 | bots.directory.assertHasFocus(); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 154 | } |
| 155 | for (int i = 0; i < 10; i++) { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 156 | bots.main.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); |
| 157 | bots.directory.assertHasFocus(); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | |
| 161 | // Tests that arrow keys do not switch focus away from the roots list. |
| 162 | public void testKeyboard_arrowsRootsList() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 163 | bots.main.pressKey(KeyEvent.KEYCODE_TAB); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 164 | for (int i = 0; i < 10; i++) { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 165 | bots.main.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); |
| 166 | bots.roots.assertHasFocus(); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 167 | } |
| 168 | for (int i = 0; i < 10; i++) { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 169 | bots.main.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); |
| 170 | bots.roots.assertHasFocus(); |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 171 | } |
| 172 | } |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 173 | } |