• 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 android.support.test.filters.LargeTest;
23 import android.support.test.filters.Suppress;
24 import android.support.v7.recyclerview.R;
25 
26 import com.android.documentsui.files.FilesActivity;
27 
28 @LargeTest
29 public class SearchViewUiTest extends ActivityTest<FilesActivity> {
30 
SearchViewUiTest()31     public SearchViewUiTest() {
32         super(FilesActivity.class);
33     }
34 
35     @Override
setUp()36     public void setUp() throws Exception {
37       super.setUp();
38       initTestFiles();
39       // Drawer interferes with a lot of search action; going to try to close any opened ones
40       bots.roots.closeDrawer();
41 
42       // wait for a file to be present in default dir.
43       bots.directory.waitForDocument(fileName1);
44     }
45 
testSearchIconVisible()46     public void testSearchIconVisible() throws Exception {
47         // The default root (root 0) supports search
48         bots.search.assertInputExists(false);
49         bots.search.assertIconVisible(true);
50     }
51 
testSearchIconHidden()52     public void testSearchIconHidden() throws Exception {
53         bots.roots.openRoot(ROOT_1_ID);  // root 1 doesn't support search
54 
55         bots.search.assertIconVisible(false);
56         bots.search.assertInputExists(false);
57     }
58 
testSearchView_ExpandsOnClick()59     public void testSearchView_ExpandsOnClick() throws Exception {
60         bots.search.clickIcon();
61         device.waitForIdle();
62 
63         bots.search.assertInputExists(true);
64         bots.search.assertInputFocused(true);
65 
66         // FIXME: Matchers fail the not-present check if we've ever clicked this.
67         // bots.search.assertIconVisible(false);
68     }
69 
testSearchView_CollapsesOnBack()70     public void testSearchView_CollapsesOnBack() throws Exception {
71         bots.search.clickIcon();
72         device.pressBack();
73         device.pressBack();
74 
75         bots.search.assertIconVisible(true);
76         bots.search.assertInputExists(false);
77     }
78 
testSearchView_ClearsTextOnBack()79     public void testSearchView_ClearsTextOnBack() throws Exception {
80         bots.search.clickIcon();
81         bots.search.setInputText("file2");
82 
83         device.pressBack();
84         device.pressBack();
85 
86         // Wait for a file in the default directory to be listed.
87         bots.directory.waitForDocument(dirName1);
88 
89         bots.search.assertIconVisible(true);
90         bots.search.assertInputExists(false);
91     }
92 
testSearchView_StateAfterSearch()93     public void testSearchView_StateAfterSearch() throws Exception {
94         bots.search.clickIcon();
95         bots.search.setInputText("file1");
96         bots.keyboard.pressEnter();
97         device.waitForIdle();
98 
99         bots.search.assertInputEquals("file1");
100     }
101 
testSearch_ResultsFound()102     public void testSearch_ResultsFound() throws Exception {
103         bots.search.clickIcon();
104         bots.search.setInputText("file1");
105         bots.keyboard.pressEnter();
106 
107         bots.directory.assertDocumentsCountOnList(true, 2);
108         bots.directory.assertDocumentsPresent(fileName1, fileName2);
109     }
110 
testSearch_NoResults()111     public void testSearch_NoResults() throws Exception {
112         bots.search.clickIcon();
113         bots.search.setInputText("chocolate");
114 
115         bots.keyboard.pressEnter();
116 
117         String msg = String.valueOf(context.getString(R.string.no_results));
118         bots.directory.assertPlaceholderMessageText(String.format(msg, "TEST_ROOT_0"));
119     }
120 
121     @Suppress
testSearchResultsFound_ClearsOnBack()122     public void testSearchResultsFound_ClearsOnBack() throws Exception {
123         bots.search.clickIcon();
124         bots.search.setInputText(fileName1);
125 
126         bots.keyboard.pressEnter();
127         device.pressBack();
128         device.waitForIdle();
129 
130         assertDefaultContentOfTestDir0();
131     }
132 
133     @Suppress
testSearchNoResults_ClearsOnBack()134     public void testSearchNoResults_ClearsOnBack() throws Exception {
135         bots.search.clickIcon();
136         bots.search.setInputText("chocolate bunny");
137 
138         bots.keyboard.pressEnter();
139         device.pressBack();
140         device.waitForIdle();
141 
142         assertDefaultContentOfTestDir0();
143     }
144 
145     @Suppress
testSearchResultsFound_ClearsOnDirectoryChange()146     public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
147         // Skipping this test for phones since currently there's no way to open the drawer on
148         // phones after doing a search (it's a back button instead of a hamburger button)
149         if (!bots.main.inFixedLayout()) {
150             return;
151         }
152 
153         bots.search.clickIcon();
154 
155         bots.search.setInputText(fileName1);
156 
157         bots.keyboard.pressEnter();
158 
159         bots.roots.openRoot(ROOT_1_ID);
160         device.waitForIdle();
161         assertDefaultContentOfTestDir1();
162 
163         bots.roots.openRoot(ROOT_0_ID);
164         device.waitForIdle();
165 
166         assertDefaultContentOfTestDir0();
167     }
168 }
169