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 testSearchIconVisible()47 public void testSearchIconVisible() throws Exception { 48 // The default root (root 0) supports search 49 bots.search.assertInputExists(false); 50 bots.search.assertFragmentInputExists(false); 51 bots.search.assertIconVisible(true); 52 } 53 54 @HugeLongTest testSearchIconHidden()55 public void testSearchIconHidden() throws Exception { 56 bots.roots.openRoot(ROOT_1_ID); // root 1 doesn't support search 57 58 bots.search.assertIconVisible(false); 59 bots.search.assertInputExists(false); 60 bots.search.assertFragmentInputExists(false); 61 } 62 testSearchView_ExpandsOnClick()63 public void testSearchView_ExpandsOnClick() throws Exception { 64 bots.search.clickIcon(); 65 device.waitForIdle(); 66 67 bots.search.assertFragmentInputExists(true); 68 bots.search.assertFragmentInputFocused(true); 69 70 // FIXME: Matchers fail the not-present check if we've ever clicked this. 71 // bots.search.assertIconVisible(false); 72 } 73 testSearchView_ShouldHideOptionMenuOnExpanding()74 public void testSearchView_ShouldHideOptionMenuOnExpanding() throws Exception { 75 bots.search.clickIcon(); 76 device.waitForIdle(); 77 78 bots.search.assertFragmentInputExists(true); 79 bots.search.assertFragmentInputFocused(true); 80 device.waitForIdle(); 81 82 assertFalse(bots.menu.hasMenuItem("Grid view")); 83 assertFalse(bots.menu.hasMenuItem("List view")); 84 assertFalse(bots.menu.hasMenuItemByDesc("More options")); 85 } 86 testSearchView_CollapsesOnBack()87 public void testSearchView_CollapsesOnBack() throws Exception { 88 bots.search.clickIcon(); 89 device.pressBack(); 90 device.pressBack(); 91 92 bots.search.assertIconVisible(true); 93 bots.search.assertInputExists(false); 94 bots.search.assertFragmentInputExists(false); 95 } 96 testSearchView_ClearsTextOnBack()97 public void testSearchView_ClearsTextOnBack() throws Exception { 98 bots.search.clickIcon(); 99 bots.search.setInputText("file2"); 100 101 device.pressBack(); 102 device.pressBack(); 103 104 // Wait for a file in the default directory to be listed. 105 bots.directory.waitForDocument(dirName1); 106 107 bots.search.assertIconVisible(true); 108 bots.search.assertInputExists(false); 109 bots.search.assertFragmentInputExists(false); 110 } 111 testSearchView_ClearsSearchOnBack()112 public void testSearchView_ClearsSearchOnBack() throws Exception { 113 bots.search.clickIcon(); 114 bots.search.setInputText("file1"); 115 bots.keyboard.pressEnter(); 116 device.waitForIdle(); 117 118 device.pressBack(); 119 120 bots.search.assertIconVisible(true); 121 bots.search.assertInputExists(false); 122 bots.search.assertFragmentInputExists(false); 123 } 124 testSearchView_ClearsAutoSearchOnBack()125 public void testSearchView_ClearsAutoSearchOnBack() throws Exception { 126 bots.search.clickIcon(); 127 bots.search.setInputText("chocolate"); 128 //Wait for auto search result, it should be no results and show holder message. 129 bots.directory.waitForHolderMessage(); 130 131 device.pressBack(); 132 device.pressBack(); 133 134 bots.search.assertIconVisible(true); 135 bots.search.assertInputExists(false); 136 bots.search.assertFragmentInputExists(false); 137 } 138 testSearchView_StateAfterSearch()139 public void testSearchView_StateAfterSearch() throws Exception { 140 bots.search.clickIcon(); 141 bots.search.setInputText("file1"); 142 bots.keyboard.pressEnter(); 143 device.waitForIdle(); 144 145 bots.search.assertInputEquals("file1"); 146 } 147 testSearch_ResultsFound()148 public void testSearch_ResultsFound() throws Exception { 149 bots.search.clickIcon(); 150 bots.search.setInputText("file1"); 151 bots.keyboard.pressEnter(); 152 153 bots.directory.assertDocumentsCountOnList(true, 2); 154 bots.directory.assertDocumentsPresent(fileName1, fileName2); 155 } 156 testSearch_NoResults()157 public void testSearch_NoResults() throws Exception { 158 bots.search.clickIcon(); 159 bots.search.setInputText("chocolate"); 160 161 bots.keyboard.pressEnter(); 162 163 String msg = String.valueOf(context.getString(R.string.no_results)); 164 bots.directory.assertPlaceholderMessageText(String.format(msg, "TEST_ROOT_0")); 165 } 166 167 @Suppress testSearchResultsFound_ClearsOnBack()168 public void testSearchResultsFound_ClearsOnBack() throws Exception { 169 bots.search.clickIcon(); 170 bots.search.setInputText(fileName1); 171 172 bots.keyboard.pressEnter(); 173 device.pressBack(); 174 device.waitForIdle(); 175 176 assertDefaultContentOfTestDir0(); 177 } 178 179 @Suppress testSearchNoResults_ClearsOnBack()180 public void testSearchNoResults_ClearsOnBack() throws Exception { 181 bots.search.clickIcon(); 182 bots.search.setInputText("chocolate bunny"); 183 184 bots.keyboard.pressEnter(); 185 device.pressBack(); 186 device.waitForIdle(); 187 188 assertDefaultContentOfTestDir0(); 189 } 190 191 @Suppress testSearchResultsFound_ClearsOnDirectoryChange()192 public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception { 193 // Skipping this test for phones since currently there's no way to open the drawer on 194 // phones after doing a search (it's a back button instead of a hamburger button) 195 if (!bots.main.inFixedLayout()) { 196 return; 197 } 198 199 bots.search.clickIcon(); 200 201 bots.search.setInputText(fileName1); 202 203 bots.keyboard.pressEnter(); 204 205 bots.roots.openRoot(ROOT_1_ID); 206 device.waitForIdle(); 207 assertDefaultContentOfTestDir1(); 208 209 bots.roots.openRoot(ROOT_0_ID); 210 device.waitForIdle(); 211 212 assertDefaultContentOfTestDir0(); 213 } 214 testSearchHistory_showAfterSearchViewClear()215 public void testSearchHistory_showAfterSearchViewClear() throws Exception { 216 bots.search.clickIcon(); 217 bots.search.setInputText("chocolate"); 218 219 bots.keyboard.pressEnter(); 220 device.waitForIdle(); 221 222 bots.search.clickSearchViewClearButton(); 223 device.waitForIdle(); 224 225 bots.search.assertFragmentInputExists(true); 226 bots.search.assertFragmentInputFocused(true); 227 } 228 testSearchHistory_showAfterFragmentSearchViewClear()229 public void testSearchHistory_showAfterFragmentSearchViewClear() throws Exception { 230 bots.search.clickIcon(); 231 bots.search.setInputText("chocolate"); 232 233 bots.keyboard.pressEnter(); 234 device.waitForIdle(); 235 236 bots.search.clickIcon(); 237 bots.search.clickFragmentSearchViewClearButton(); 238 device.waitForIdle(); 239 240 bots.search.assertFragmentInputExists(true); 241 bots.search.assertFragmentInputFocused(true); 242 } 243 } 244