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 android.app.Instrumentation;
20 import android.net.Uri;
21 import android.os.RemoteException;
22 
23 import androidx.test.filters.LargeTest;
24 
25 import com.android.documentsui.files.FilesActivity;
26 import com.android.documentsui.filters.HugeLongTest;
27 import com.android.documentsui.inspector.InspectorActivity;
28 
29 @LargeTest
30 public class FilesActivityUiTest extends ActivityTest<FilesActivity> {
31 
FilesActivityUiTest()32     public FilesActivityUiTest() {
33         super(FilesActivity.class);
34     }
35 
36     @Override
setUp()37     public void setUp() throws Exception {
38         super.setUp();
39         initTestFiles();
40     }
41 
42     @Override
initTestFiles()43     public void initTestFiles() throws RemoteException {
44         Uri uri = mDocsHelper.createFolder(rootDir0, dirName1);
45         mDocsHelper.createFolder(uri, childDir1);
46 
47         mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");
48         mDocsHelper.createDocument(rootDir0, "image/png", "file1.png");
49         mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv");
50 
51         mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log");
52         mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
53     }
54 
55     // Recents is a strange meta root that gathers entries from other providers.
56     // It is special cased in a variety of ways, which is why we just want
57     // to be able to click on it.
testClickRecent()58     public void testClickRecent() throws Exception {
59         bots.roots.openRoot("Recent");
60 
61         boolean showSearchBar =
62                 context.getResources().getBoolean(R.bool.show_search_bar);
63         if (showSearchBar) {
64             bots.main.assertSearchBarShow();
65         } else {
66             bots.main.assertWindowTitle("Recent");
67         }
68     }
69 
testRootClick_SetsWindowTitle()70     public void testRootClick_SetsWindowTitle() throws Exception {
71         bots.roots.openRoot("Images");
72         bots.main.assertWindowTitle("Images");
73     }
74 
testFilesListed()75     public void testFilesListed() throws Exception {
76         bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv");
77     }
78 
testFilesList_LiveUpdate()79     public void testFilesList_LiveUpdate() throws Exception {
80         mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich");
81 
82         bots.directory.waitForDocument("Ham & Cheese.sandwich");
83         bots.directory.assertDocumentsPresent(
84                 "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich");
85     }
86 
testNavigate_byBreadcrumb()87     public void testNavigate_byBreadcrumb() throws Exception {
88         bots.directory.openDocument(dirName1);
89         bots.directory.waitForDocument(childDir1);  // wait for known content
90         bots.directory.assertDocumentsPresent(childDir1);
91 
92         device.waitForIdle();
93         bots.breadcrumb.assertItemsPresent(dirName1, "TEST_ROOT_0");
94 
95         bots.breadcrumb.clickItem("TEST_ROOT_0");
96         bots.directory.waitForDocument(dirName1);
97     }
98 
testNavigate_inFixedLayout_whileHasSelection()99     public void testNavigate_inFixedLayout_whileHasSelection() throws Exception {
100         if (bots.main.inFixedLayout()) {
101             bots.roots.openRoot(rootDir0.title);
102             device.waitForIdle();
103             bots.directory.selectDocument("file0.log", 1);
104 
105             // ensure no exception is thrown while navigating to a different root
106             bots.roots.openRoot(rootDir1.title);
107         }
108     }
109 
testNavigationToInspector()110     public void testNavigationToInspector() throws Exception {
111         if(!features.isInspectorEnabled()) {
112             return;
113         }
114         Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
115                 InspectorActivity.class.getName(), null, false);
116         bots.directory.selectDocument("file0.log");
117         bots.main.clickActionItem("Get info");
118         monitor.waitForActivityWithTimeout(TIMEOUT);
119     }
120 
121     @HugeLongTest
testRootChange_UpdatesSortHeader()122     public void testRootChange_UpdatesSortHeader() throws Exception {
123 
124         // switch to separate display modes for two separate roots. Each
125         // mode has its own distinct sort header. This should be remembered
126         // by files app.
127         bots.roots.openRoot("Images");
128         bots.main.switchToGridMode();
129         bots.roots.openRoot("Videos");
130         bots.main.switchToListMode();
131 
132         // Now switch back and assert the correct mode sort header mode
133         // is restored when we load the root with that display mode.
134         bots.roots.openRoot("Images");
135         bots.sort.assertHeaderHide();
136         if (bots.main.inFixedLayout()) {
137             bots.roots.openRoot("Videos");
138             bots.sort.assertHeaderShow();
139         } else {
140             bots.roots.openRoot("Videos");
141             bots.sort.assertHeaderHide();
142         }
143     }
144 }
145