• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 static com.android.documentsui.StubProvider.ROOT_0_ID;
20 import static com.android.documentsui.StubProvider.ROOT_1_ID;
21 
22 import androidx.recyclerview.R;
23 import androidx.test.filters.LargeTest;
24 import androidx.test.filters.Suppress;
25 
26 import com.android.documentsui.files.FilesActivity;
27 import com.android.documentsui.filters.HugeLongTest;
28 
29 @LargeTest
30 public class SearchViewUiTest extends ActivityTest<FilesActivity> {
31 
SearchViewUiTest()32     public SearchViewUiTest() {
33         super(FilesActivity.class);
34     }
35 
36     @Override
setUp()37     public void setUp() throws Exception {
38       super.setUp();
39       initTestFiles();
40       // Drawer interferes with a lot of search action; going to try to close any opened ones
41       bots.roots.closeDrawer();
42 
43       // wait for a file to be present in default dir.
44       bots.directory.waitForDocument(fileName1);
45     }
46 
47     @Override
tearDown()48     public void tearDown() throws Exception {
49         // manually close activity to avoid SearchFragment show when Activity close. ref b/142840883
50         device.waitForIdle();
51         device.pressBack();
52         device.pressBack();
53         device.pressBack();
54         super.tearDown();
55     }
56 
testSearchIconVisible()57     public void testSearchIconVisible() throws Exception {
58         // The default root (root 0) supports search
59         bots.search.assertInputExists(false);
60         bots.search.assertIconVisible(true);
61     }
62 
63     @HugeLongTest
testSearchIconHidden()64     public void testSearchIconHidden() throws Exception {
65         bots.roots.openRoot(ROOT_1_ID);  // root 1 doesn't support search
66 
67         bots.search.assertIconVisible(false);
68         bots.search.assertInputExists(false);
69     }
70 
testSearchView_ExpandsOnClick()71     public void testSearchView_ExpandsOnClick() throws Exception {
72         bots.search.clickIcon();
73         device.waitForIdle();
74 
75         bots.search.assertInputExists(true);
76         bots.search.assertInputFocused(true);
77 
78         // FIXME: Matchers fail the not-present check if we've ever clicked this.
79         // bots.search.assertIconVisible(false);
80     }
81 
testSearchView_ShouldHideOptionMenuOnExpanding()82     public void testSearchView_ShouldHideOptionMenuOnExpanding() throws Exception {
83         bots.search.clickIcon();
84         device.waitForIdle();
85 
86         bots.search.assertInputExists(true);
87         bots.search.assertInputFocused(true);
88         device.waitForIdle();
89 
90         assertFalse(bots.menu.hasMenuItem("Grid view"));
91         assertFalse(bots.menu.hasMenuItem("List view"));
92         assertFalse(bots.menu.hasMenuItemByDesc("More options"));
93     }
94 
testSearchView_CollapsesOnBack()95     public void testSearchView_CollapsesOnBack() throws Exception {
96         bots.search.clickIcon();
97         device.pressBack();
98 
99         bots.search.assertIconVisible(true);
100         bots.search.assertInputExists(false);
101     }
102 
testSearchFragment_DismissedOnCloseAfterCancel()103     public void testSearchFragment_DismissedOnCloseAfterCancel() throws Exception {
104         bots.search.clickIcon();
105         bots.search.setInputText("query text");
106 
107         // Cancel search
108         device.pressBack();
109         device.waitForIdle();
110 
111         // Close search
112         device.pressBack();
113         device.waitForIdle();
114 
115         bots.search.assertIconVisible(true);
116         bots.search.assertInputExists(false);
117         bots.search.assertSearchHistoryVisible(false);
118     }
119 
testSearchView_ClearsTextOnBack()120     public void testSearchView_ClearsTextOnBack() throws Exception {
121         bots.search.clickIcon();
122         bots.search.setInputText("file2");
123 
124         device.pressBack();
125         device.pressBack();
126 
127         // Wait for a file in the default directory to be listed.
128         bots.directory.waitForDocument(dirName1);
129 
130         bots.search.assertIconVisible(true);
131         bots.search.assertInputExists(false);
132     }
133 
testSearchView_ClearsSearchOnBack()134     public void testSearchView_ClearsSearchOnBack() throws Exception {
135         bots.search.clickIcon();
136         bots.search.setInputText("file1");
137         bots.keyboard.pressEnter();
138         device.waitForIdle();
139 
140         device.pressBack();
141 
142         bots.search.assertIconVisible(true);
143         bots.search.assertInputExists(false);
144     }
145 
testSearchView_ClearsAutoSearchOnBack()146     public void testSearchView_ClearsAutoSearchOnBack() throws Exception {
147         bots.search.clickIcon();
148         bots.search.setInputText("chocolate");
149         //Wait for auto search result, it should be no results and show holder message.
150         bots.directory.waitForHolderMessage();
151 
152         device.pressBack();
153         device.pressBack();
154 
155         bots.search.assertIconVisible(true);
156         bots.search.assertInputExists(false);
157     }
158 
testSearchView_StateAfterSearch()159     public void testSearchView_StateAfterSearch() throws Exception {
160         bots.search.clickIcon();
161         bots.search.setInputText("file1");
162         bots.keyboard.pressEnter();
163         device.waitForIdle();
164 
165         bots.search.assertInputEquals("file1");
166     }
167 
testSearch_ResultsFound()168     public void testSearch_ResultsFound() throws Exception {
169         bots.search.clickIcon();
170         bots.search.setInputText("file1");
171         bots.keyboard.pressEnter();
172 
173         bots.directory.assertDocumentsCountOnList(true, 2);
174         bots.directory.assertDocumentsPresent(fileName1, fileName2);
175     }
176 
testSearch_NoResults()177     public void testSearch_NoResults() throws Exception {
178         bots.search.clickIcon();
179         bots.search.setInputText("chocolate");
180 
181         bots.keyboard.pressEnter();
182 
183         String msg = String.valueOf(context.getString(R.string.no_results));
184         bots.directory.assertPlaceholderMessageText(String.format(msg, "TEST_ROOT_0"));
185     }
186 
187     @Suppress
testSearchResultsFound_ClearsOnBack()188     public void testSearchResultsFound_ClearsOnBack() throws Exception {
189         bots.search.clickIcon();
190         bots.search.setInputText(fileName1);
191 
192         bots.keyboard.pressEnter();
193         device.pressBack();
194         device.waitForIdle();
195 
196         assertDefaultContentOfTestDir0();
197     }
198 
199     @Suppress
testSearchNoResults_ClearsOnBack()200     public void testSearchNoResults_ClearsOnBack() throws Exception {
201         bots.search.clickIcon();
202         bots.search.setInputText("chocolate bunny");
203 
204         bots.keyboard.pressEnter();
205         device.pressBack();
206         device.waitForIdle();
207 
208         assertDefaultContentOfTestDir0();
209     }
210 
211     @Suppress
testSearchResultsFound_ClearsOnDirectoryChange()212     public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
213         // Skipping this test for phones since currently there's no way to open the drawer on
214         // phones after doing a search (it's a back button instead of a hamburger button)
215         if (!bots.main.inFixedLayout()) {
216             return;
217         }
218 
219         bots.search.clickIcon();
220 
221         bots.search.setInputText(fileName1);
222 
223         bots.keyboard.pressEnter();
224 
225         bots.roots.openRoot(ROOT_1_ID);
226         device.waitForIdle();
227         assertDefaultContentOfTestDir1();
228 
229         bots.roots.openRoot(ROOT_0_ID);
230         device.waitForIdle();
231 
232         assertDefaultContentOfTestDir0();
233     }
234 
testSearchHistory_showAfterSearchViewClear()235     public void testSearchHistory_showAfterSearchViewClear() throws Exception {
236         bots.search.clickIcon();
237         bots.search.setInputText("chocolate");
238 
239         bots.keyboard.pressEnter();
240         device.waitForIdle();
241 
242         bots.search.clickSearchViewClearButton();
243         device.waitForIdle();
244 
245         bots.search.assertInputExists(true);
246         bots.search.assertInputFocused(true);
247         bots.search.assertSearchHistoryVisible(true);
248     }
249 
testSearchView_focusClearedAfterSelectingSearchHistory()250     public void testSearchView_focusClearedAfterSelectingSearchHistory() throws Exception {
251         String queryText = "history";
252         bots.search.clickIcon();
253         bots.search.setInputText(queryText);
254         bots.keyboard.pressEnter();
255         device.waitForIdle();
256 
257         bots.search.clickSearchViewClearButton();
258         device.waitForIdle();
259         bots.search.assertInputFocused(true);
260         bots.search.assertSearchHistoryVisible(true);
261 
262         bots.search.clickSearchHistory(queryText);
263         bots.search.assertInputFocused(false);
264         bots.search.assertSearchHistoryVisible(false);
265     }
266 }
267