blob: 498471e6828b57414453d2bc6429c085da6e4907 [file] [log] [blame]
Steve McKay01792572015-10-23 11:46:01 -07001/*
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
17package com.android.documentsui;
18
Steve McKay0c3c6952015-10-26 17:03:55 -070019import static com.android.documentsui.StubProvider.ROOT_0_ID;
20import static com.android.documentsui.StubProvider.ROOT_1_ID;
21
Steve McKay0c3c6952015-10-26 17:03:55 -070022import android.os.RemoteException;
Steve McKay53c774b2015-11-12 10:54:31 +090023import android.test.suitebuilder.annotation.LargeTest;
Ben Kwa2036dad2016-02-10 07:46:35 -080024import android.view.KeyEvent;
Steve McKay01792572015-10-23 11:46:01 -070025
Aga Wronskab9eeee12016-02-24 12:57:21 -080026import com.android.documentsui.model.RootInfo;
27
Steve McKay53c774b2015-11-12 10:54:31 +090028@LargeTest
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090029public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
Steve McKay01792572015-10-23 11:46:01 -070030
Tomasz Mikolajewski24586892016-02-04 13:48:21 +090031 public FilesActivityUiTest() {
32 super(FilesActivity.class);
33 }
Steve McKay01792572015-10-23 11:46:01 -070034
Steve McKay0c3c6952015-10-26 17:03:55 -070035 @Override
Aga Wronskab9eeee12016-02-24 12:57:21 -080036 protected RootInfo getInitialRoot() {
37 return null;
38 }
39
40 @Override
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090041 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 Mikolajewski24586892016-02-04 13:48:21 +090045
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090046 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log");
47 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
Steve McKay0c3c6952015-10-26 17:03:55 -070048 }
49
50 public void testRootsListed() throws Exception {
51 initTestFiles();
52
Steve McKayb9a20d12016-02-19 12:57:05 -080053 bots.roots.openRoot(ROOT_0_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -070054
55 // Should also have Drive, but that requires pre-configuration of devices
56 // We omit for now.
Steve McKayb9a20d12016-02-19 12:57:05 -080057 bots.roots.assertHasRoots(
Steve McKay0c3c6952015-10-26 17:03:55 -070058 "Images",
59 "Videos",
60 "Audio",
61 "Downloads",
Steve McKaya6bbeab2016-02-17 15:02:01 -080062 "Documents",
Steve McKay0c3c6952015-10-26 17:03:55 -070063 ROOT_0_ID,
64 ROOT_1_ID);
65 }
66
67 public void testFilesListed() throws Exception {
68 initTestFiles();
69
Steve McKayb9a20d12016-02-19 12:57:05 -080070 bots.roots.openRoot(ROOT_0_ID);
71 bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv");
Steve McKay0c3c6952015-10-26 17:03:55 -070072 }
73
Steve McKaya6bbeab2016-02-17 15:02:01 -080074 public void testLoadsHomeDirectoryByDefault() throws Exception {
Steve McKayb67bfbf2015-12-08 17:02:03 -080075 initTestFiles();
76
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090077 device.waitForIdle();
Steve McKayb9a20d12016-02-19 12:57:05 -080078 bots.main.assertWindowTitle("Documents");
Steve McKayb67bfbf2015-12-08 17:02:03 -080079 }
80
Steve McKayc6a4cd82015-11-18 14:56:50 -080081 public void testRootClickSetsWindowTitle() throws Exception {
82 initTestFiles();
83
Steve McKayb9a20d12016-02-19 12:57:05 -080084 bots.roots.openRoot("Downloads");
85 bots.main.assertWindowTitle("Downloads");
Steve McKayc6a4cd82015-11-18 14:56:50 -080086 }
87
Steve McKay0c3c6952015-10-26 17:03:55 -070088 public void testFilesList_LiveUpdate() throws Exception {
89 initTestFiles();
90
Steve McKayb9a20d12016-02-19 12:57:05 -080091 bots.roots.openRoot(ROOT_0_ID);
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090092 mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich");
Tomasz Mikolajewskib005e142016-02-02 19:26:09 +090093
Steve McKayb9a20d12016-02-19 12:57:05 -080094 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 Wronska568b3b32016-02-23 10:49:29 -0800102 bots.roots.openRoot(ROOT_0_ID);
103
Steve McKayb9a20d12016-02-19 12:57:05 -0800104 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 McKay0c3c6952015-10-26 17:03:55 -0700111 }
112
113 public void testDeleteDocument() throws Exception {
114 initTestFiles();
115
Steve McKayb9a20d12016-02-19 12:57:05 -0800116 bots.roots.openRoot(ROOT_0_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -0700117
Steve McKayb9a20d12016-02-19 12:57:05 -0800118 bots.directory.clickDocument("file1.png");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900119 device.waitForIdle();
Steve McKayb9a20d12016-02-19 12:57:05 -0800120 bots.main.menuDelete().click();
Steve McKay0c3c6952015-10-26 17:03:55 -0700121
Steve McKay7a3b8112016-02-23 10:06:50 -0800122 bots.main.findDialogOkButton().click();
123
Steve McKayb9a20d12016-02-19 12:57:05 -0800124 bots.directory.assertDocumentsAbsent("file1.png");
Steve McKay7a3b8112016-02-23 10:06:50 -0800125 }
Steve McKay0c3c6952015-10-26 17:03:55 -0700126
Steve McKay7a3b8112016-02-23 10:06:50 -0800127 public void testDeleteDocument_Cancel() throws Exception {
128 initTestFiles();
Steve McKay0c3c6952015-10-26 17:03:55 -0700129
Steve McKay7a3b8112016-02-23 10:06:50 -0800130 bots.roots.openRoot(ROOT_0_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -0700131
Steve McKay7a3b8112016-02-23 10:06:50 -0800132 bots.directory.clickDocument("file1.png");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900133 device.waitForIdle();
Steve McKayb9a20d12016-02-19 12:57:05 -0800134 bots.main.menuDelete().click();
Steve McKay0c3c6952015-10-26 17:03:55 -0700135
Steve McKay7a3b8112016-02-23 10:06:50 -0800136 bots.main.findDialogCancelButton().click();
Steve McKay0c3c6952015-10-26 17:03:55 -0700137
Steve McKay7a3b8112016-02-23 10:06:50 -0800138 bots.directory.assertDocumentsPresent("file1.png");
Steve McKay01792572015-10-23 11:46:01 -0700139 }
Ben Kwa2036dad2016-02-10 07:46:35 -0800140
141 // Tests that pressing tab switches focus between the roots and directory listings.
142 public void testKeyboard_tab() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -0800143 bots.main.pressKey(KeyEvent.KEYCODE_TAB);
144 bots.roots.assertHasFocus();
145 bots.main.pressKey(KeyEvent.KEYCODE_TAB);
146 bots.directory.assertHasFocus();
Ben Kwa2036dad2016-02-10 07:46:35 -0800147 }
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 McKayb9a20d12016-02-19 12:57:05 -0800152 bots.main.pressKey(KeyEvent.KEYCODE_DPAD_LEFT);
153 bots.directory.assertHasFocus();
Ben Kwa2036dad2016-02-10 07:46:35 -0800154 }
155 for (int i = 0; i < 10; i++) {
Steve McKayb9a20d12016-02-19 12:57:05 -0800156 bots.main.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT);
157 bots.directory.assertHasFocus();
Ben Kwa2036dad2016-02-10 07:46:35 -0800158 }
159 }
160
161 // Tests that arrow keys do not switch focus away from the roots list.
162 public void testKeyboard_arrowsRootsList() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -0800163 bots.main.pressKey(KeyEvent.KEYCODE_TAB);
Ben Kwa2036dad2016-02-10 07:46:35 -0800164 for (int i = 0; i < 10; i++) {
Steve McKayb9a20d12016-02-19 12:57:05 -0800165 bots.main.pressKey(KeyEvent.KEYCODE_DPAD_RIGHT);
166 bots.roots.assertHasFocus();
Ben Kwa2036dad2016-02-10 07:46:35 -0800167 }
168 for (int i = 0; i < 10; i++) {
Steve McKayb9a20d12016-02-19 12:57:05 -0800169 bots.main.pressKey(KeyEvent.KEYCODE_DPAD_LEFT);
170 bots.roots.assertHasFocus();
Ben Kwa2036dad2016-02-10 07:46:35 -0800171 }
172 }
Steve McKay01792572015-10-23 11:46:01 -0700173}