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 | |
Steve McKay | 53c774b | 2015-11-12 10:54:31 +0900 | [diff] [blame] | 26 | @LargeTest |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 27 | public class FilesActivityUiTest extends ActivityTest<FilesActivity> { |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 28 | |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 29 | public FilesActivityUiTest() { |
| 30 | super(FilesActivity.class); |
| 31 | } |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 32 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 33 | @Override |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 34 | public void initTestFiles() throws RemoteException { |
| 35 | mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); |
| 36 | mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); |
| 37 | mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 38 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 39 | mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); |
| 40 | mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | public void testRootsListed() throws Exception { |
| 44 | initTestFiles(); |
| 45 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 46 | bot.openRoot(ROOT_0_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 47 | |
| 48 | // Should also have Drive, but that requires pre-configuration of devices |
| 49 | // We omit for now. |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 50 | bot.assertHasRoots( |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 51 | "Images", |
| 52 | "Videos", |
| 53 | "Audio", |
| 54 | "Downloads", |
Steve McKay | a6bbeab | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 55 | "Documents", |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 56 | ROOT_0_ID, |
| 57 | ROOT_1_ID); |
| 58 | } |
| 59 | |
| 60 | public void testFilesListed() throws Exception { |
| 61 | initTestFiles(); |
| 62 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 63 | bot.openRoot(ROOT_0_ID); |
| 64 | bot.assertHasDocuments("file0.log", "file1.png", "file2.csv"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Steve McKay | a6bbeab | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 67 | public void testLoadsHomeDirectoryByDefault() throws Exception { |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 68 | initTestFiles(); |
| 69 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 70 | device.waitForIdle(); |
Steve McKay | a6bbeab | 2016-02-17 15:02:01 -0800 | [diff] [blame] | 71 | bot.assertWindowTitle("Documents"); |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 74 | public void testRootClickSetsWindowTitle() throws Exception { |
| 75 | initTestFiles(); |
| 76 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 77 | bot.openRoot("Downloads"); |
| 78 | bot.assertWindowTitle("Downloads"); |
Steve McKay | c6a4cd8 | 2015-11-18 14:56:50 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 81 | public void testFilesList_LiveUpdate() throws Exception { |
| 82 | initTestFiles(); |
| 83 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 84 | bot.openRoot(ROOT_0_ID); |
| 85 | mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); |
Tomasz Mikolajewski | b005e14 | 2016-02-02 19:26:09 +0900 | [diff] [blame] | 86 | |
Tomasz Mikolajewski | 65d9a51 | 2016-02-08 15:36:04 +0900 | [diff] [blame] | 87 | bot.waitForDocument("Ham & Cheese.sandwich"); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 88 | bot.assertHasDocuments("file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | public void testDeleteDocument() throws Exception { |
| 92 | initTestFiles(); |
| 93 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 94 | bot.openRoot(ROOT_0_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 95 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 96 | bot.clickDocument("file1.png"); |
| 97 | device.waitForIdle(); |
| 98 | bot.menuDelete().click(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 99 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 100 | bot.waitForDeleteSnackbar(); |
| 101 | assertFalse(bot.hasDocuments("file1.png")); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 102 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 103 | bot.waitForDeleteSnackbarGone(); |
| 104 | assertFalse(bot.hasDocuments("file1.png")); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 105 | |
| 106 | // Now delete from another root. |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 107 | bot.openRoot(ROOT_1_ID); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 108 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 109 | bot.clickDocument("poodles.text"); |
| 110 | device.waitForIdle(); |
| 111 | bot.menuDelete().click(); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 112 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 113 | bot.waitForDeleteSnackbar(); |
| 114 | assertFalse(bot.hasDocuments("poodles.text")); |
Steve McKay | 0c3c695 | 2015-10-26 17:03:55 -0700 | [diff] [blame] | 115 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 116 | bot.waitForDeleteSnackbarGone(); |
| 117 | assertFalse(bot.hasDocuments("poodles.text")); |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 118 | } |
Ben Kwa | 2036dad | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 119 | |
| 120 | // Tests that pressing tab switches focus between the roots and directory listings. |
| 121 | public void testKeyboard_tab() throws Exception { |
| 122 | bot.pressKey(KeyEvent.KEYCODE_TAB); |
| 123 | bot.assertHasFocus("com.android.documentsui:id/roots_list"); |
| 124 | bot.pressKey(KeyEvent.KEYCODE_TAB); |
| 125 | bot.assertHasFocus("com.android.documentsui:id/dir_list"); |
| 126 | } |
| 127 | |
| 128 | // Tests that arrow keys do not switch focus away from the dir list. |
| 129 | public void testKeyboard_arrowsDirList() throws Exception { |
| 130 | for (int i = 0; i < 10; i++) { |
| 131 | bot.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); |
| 132 | bot.assertHasFocus("com.android.documentsui:id/dir_list"); |
| 133 | } |
| 134 | for (int i = 0; i < 10; i++) { |
| 135 | bot.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); |
| 136 | bot.assertHasFocus("com.android.documentsui:id/dir_list"); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // Tests that arrow keys do not switch focus away from the roots list. |
| 141 | public void testKeyboard_arrowsRootsList() throws Exception { |
| 142 | bot.pressKey(KeyEvent.KEYCODE_TAB); |
| 143 | for (int i = 0; i < 10; i++) { |
| 144 | bot.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT); |
| 145 | bot.assertHasFocus("com.android.documentsui:id/roots_list"); |
| 146 | } |
| 147 | for (int i = 0; i < 10; i++) { |
| 148 | bot.pressKey(KeyEvent.KEYCODE_DPAD_LEFT); |
| 149 | bot.assertHasFocus("com.android.documentsui:id/roots_list"); |
| 150 | } |
| 151 | } |
Steve McKay | 0179257 | 2015-10-23 11:46:01 -0700 | [diff] [blame] | 152 | } |