blob: 95515dbd6d75b0ec6f007249a8a4e4f0025ba80e [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
Steve McKay53c774b2015-11-12 10:54:31 +090026@LargeTest
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090027public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
Steve McKay01792572015-10-23 11:46:01 -070028
Tomasz Mikolajewski24586892016-02-04 13:48:21 +090029 public FilesActivityUiTest() {
30 super(FilesActivity.class);
31 }
Steve McKay01792572015-10-23 11:46:01 -070032
Steve McKay0c3c6952015-10-26 17:03:55 -070033 @Override
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090034 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 Mikolajewski24586892016-02-04 13:48:21 +090038
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090039 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log");
40 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
Steve McKay0c3c6952015-10-26 17:03:55 -070041 }
42
43 public void testRootsListed() throws Exception {
44 initTestFiles();
45
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090046 bot.openRoot(ROOT_0_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -070047
48 // Should also have Drive, but that requires pre-configuration of devices
49 // We omit for now.
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090050 bot.assertHasRoots(
Steve McKay0c3c6952015-10-26 17:03:55 -070051 "Images",
52 "Videos",
53 "Audio",
54 "Downloads",
Steve McKaya6bbeab2016-02-17 15:02:01 -080055 "Documents",
Steve McKay0c3c6952015-10-26 17:03:55 -070056 ROOT_0_ID,
57 ROOT_1_ID);
58 }
59
60 public void testFilesListed() throws Exception {
61 initTestFiles();
62
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090063 bot.openRoot(ROOT_0_ID);
64 bot.assertHasDocuments("file0.log", "file1.png", "file2.csv");
Steve McKay0c3c6952015-10-26 17:03:55 -070065 }
66
Steve McKaya6bbeab2016-02-17 15:02:01 -080067 public void testLoadsHomeDirectoryByDefault() throws Exception {
Steve McKayb67bfbf2015-12-08 17:02:03 -080068 initTestFiles();
69
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090070 device.waitForIdle();
Steve McKaya6bbeab2016-02-17 15:02:01 -080071 bot.assertWindowTitle("Documents");
Steve McKayb67bfbf2015-12-08 17:02:03 -080072 }
73
Steve McKayc6a4cd82015-11-18 14:56:50 -080074 public void testRootClickSetsWindowTitle() throws Exception {
75 initTestFiles();
76
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090077 bot.openRoot("Downloads");
78 bot.assertWindowTitle("Downloads");
Steve McKayc6a4cd82015-11-18 14:56:50 -080079 }
80
Steve McKay0c3c6952015-10-26 17:03:55 -070081 public void testFilesList_LiveUpdate() throws Exception {
82 initTestFiles();
83
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090084 bot.openRoot(ROOT_0_ID);
85 mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich");
Tomasz Mikolajewskib005e142016-02-02 19:26:09 +090086
Tomasz Mikolajewski65d9a512016-02-08 15:36:04 +090087 bot.waitForDocument("Ham & Cheese.sandwich");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090088 bot.assertHasDocuments("file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich");
Steve McKay0c3c6952015-10-26 17:03:55 -070089 }
90
91 public void testDeleteDocument() throws Exception {
92 initTestFiles();
93
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090094 bot.openRoot(ROOT_0_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -070095
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090096 bot.clickDocument("file1.png");
97 device.waitForIdle();
98 bot.menuDelete().click();
Steve McKay0c3c6952015-10-26 17:03:55 -070099
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900100 bot.waitForDeleteSnackbar();
101 assertFalse(bot.hasDocuments("file1.png"));
Steve McKay0c3c6952015-10-26 17:03:55 -0700102
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900103 bot.waitForDeleteSnackbarGone();
104 assertFalse(bot.hasDocuments("file1.png"));
Steve McKay0c3c6952015-10-26 17:03:55 -0700105
106 // Now delete from another root.
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900107 bot.openRoot(ROOT_1_ID);
Steve McKay0c3c6952015-10-26 17:03:55 -0700108
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900109 bot.clickDocument("poodles.text");
110 device.waitForIdle();
111 bot.menuDelete().click();
Steve McKay0c3c6952015-10-26 17:03:55 -0700112
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900113 bot.waitForDeleteSnackbar();
114 assertFalse(bot.hasDocuments("poodles.text"));
Steve McKay0c3c6952015-10-26 17:03:55 -0700115
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900116 bot.waitForDeleteSnackbarGone();
117 assertFalse(bot.hasDocuments("poodles.text"));
Steve McKay01792572015-10-23 11:46:01 -0700118 }
Ben Kwa2036dad2016-02-10 07:46:35 -0800119
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 McKay01792572015-10-23 11:46:01 -0700152}