Home | History | Annotate | Download | only in documentsui
      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 
     31     public SearchViewUiTest() {
     32         super(FilesActivity.class);
     33     }
     34 
     35     @Override
     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 
     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 
     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 
     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 
     70     public void testSearchView_CollapsesOnBack() throws Exception {
     71         bots.search.clickIcon();
     72         device.pressBack();
     73 
     74         bots.search.assertIconVisible(true);
     75         bots.search.assertInputExists(false);
     76     }
     77 
     78     public void testSearchView_ClearsTextOnBack() throws Exception {
     79         bots.search.clickIcon();
     80         bots.search.setInputText("file2");
     81 
     82         device.pressBack();
     83 
     84         // Wait for a file in the default directory to be listed.
     85         bots.directory.waitForDocument(dirName1);
     86 
     87         bots.search.assertIconVisible(true);
     88         bots.search.assertInputExists(false);
     89     }
     90 
     91     public void testSearchView_StateAfterSearch() throws Exception {
     92         bots.search.clickIcon();
     93         bots.search.setInputText("file1");
     94         bots.keyboard.pressEnter();
     95         device.waitForIdle();
     96 
     97         bots.search.assertInputEquals("file1");
     98         bots.search.assertInputFocused(false);
     99     }
    100 
    101     public void testSearch_ResultsFound() throws Exception {
    102         bots.search.clickIcon();
    103         bots.search.setInputText("file1");
    104         bots.keyboard.pressEnter();
    105 
    106         bots.directory.assertDocumentsCountOnList(true, 2);
    107         bots.directory.assertDocumentsPresent(fileName1, fileName2);
    108     }
    109 
    110     public void testSearch_NoResults() throws Exception {
    111         bots.search.clickIcon();
    112         bots.search.setInputText("chocolate");
    113 
    114         bots.keyboard.pressEnter();
    115 
    116         String msg = String.valueOf(context.getString(R.string.no_results));
    117         bots.directory.assertPlaceholderMessageText(String.format(msg, "TEST_ROOT_0"));
    118     }
    119 
    120     @Suppress
    121     public void testSearchResultsFound_ClearsOnBack() throws Exception {
    122         bots.search.clickIcon();
    123         bots.search.setInputText(fileName1);
    124 
    125         bots.keyboard.pressEnter();
    126         device.pressBack();
    127         device.waitForIdle();
    128 
    129         assertDefaultContentOfTestDir0();
    130     }
    131 
    132     @Suppress
    133     public void testSearchNoResults_ClearsOnBack() throws Exception {
    134         bots.search.clickIcon();
    135         bots.search.setInputText("chocolate bunny");
    136 
    137         bots.keyboard.pressEnter();
    138         device.pressBack();
    139         device.waitForIdle();
    140 
    141         assertDefaultContentOfTestDir0();
    142     }
    143 
    144     @Suppress
    145     public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
    146         // Skipping this test for phones since currently there's no way to open the drawer on
    147         // phones after doing a search (it's a back button instead of a hamburger button)
    148         if (!bots.main.inFixedLayout()) {
    149             return;
    150         }
    151 
    152         bots.search.clickIcon();
    153 
    154         bots.search.setInputText(fileName1);
    155 
    156         bots.keyboard.pressEnter();
    157 
    158         bots.roots.openRoot(ROOT_1_ID);
    159         device.waitForIdle();
    160         assertDefaultContentOfTestDir1();
    161 
    162         bots.roots.openRoot(ROOT_0_ID);
    163         device.waitForIdle();
    164 
    165         assertDefaultContentOfTestDir0();
    166     }
    167 }
    168