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.test.suitebuilder.annotation.LargeTest;
     23 import android.test.suitebuilder.annotation.Suppress;
     24 
     25 @LargeTest
     26 public class SearchViewUiTest extends ActivityTest<FilesActivity> {
     27 
     28     public SearchViewUiTest() {
     29         super(FilesActivity.class);
     30     }
     31 
     32     @Suppress
     33     public void testSearchView_ExpandsOnClick() throws Exception {
     34         bots.main.openSearchView();
     35         bots.main.assertSearchTextFiledAndIcon(true, false);
     36     }
     37 
     38     public void testSearchView_CollapsesOnBack() throws Exception {
     39         bots.main.openSearchView();
     40 
     41         device.pressBack();
     42 
     43         bots.main.assertSearchTextFiledAndIcon(false, true);
     44     }
     45 
     46     @Suppress
     47     public void testSearchView_ClearsTextOnBack() throws Exception {
     48         String query = "file2";
     49         bots.main.openSearchView();
     50         bots.main.setSearchQuery(query);
     51 
     52         device.pressBack();
     53 
     54         bots.main.assertSearchTextFiledAndIcon(false, true);
     55     }
     56 
     57     @Suppress
     58     public void testSearch_ResultsFound() throws Exception {
     59         initTestFiles();
     60         assertDefaultContentOfTestDir0();
     61 
     62         String query = "file1";
     63         bots.main.openSearchView();
     64         bots.main.setSearchQuery(query);
     65         bots.main.assertSearchTextField(true, query);
     66 
     67         device.pressEnter();
     68 
     69         bots.directory.assertDocumentsCountOnList(true, 2);
     70         bots.directory.assertDocumentsPresent(fileName1, fileName2);
     71 
     72         bots.main.assertSearchTextField(false, query);
     73     }
     74 
     75     @Suppress
     76     public void testSearchResultsFound_ClearsOnBack() throws Exception {
     77         initTestFiles();
     78         assertDefaultContentOfTestDir0();
     79 
     80         String query = fileName1;
     81         bots.main.openSearchView();
     82         bots.main.setSearchQuery(query);
     83 
     84         device.pressEnter();
     85         device.pressBack();
     86 
     87         assertDefaultContentOfTestDir0();
     88     }
     89 
     90     @Suppress
     91     public void testSearch_NoResults() throws Exception {
     92         initTestFiles();
     93         assertDefaultContentOfTestDir0();
     94 
     95         String query = "chocolate";
     96         bots.main.openSearchView();
     97         bots.main.setSearchQuery(query);
     98 
     99         device.pressEnter();
    100 
    101         bots.directory.assertDocumentsCountOnList(false, 0);
    102 
    103         device.waitForIdle();
    104         String msg = String.valueOf(context.getString(R.string.no_results));
    105         bots.directory.assertMessageTextView(String.format(msg, "TEST_ROOT_0"));
    106 
    107         bots.main.assertSearchTextField(false, query);
    108     }
    109 
    110     @Suppress
    111     public void testSearchNoResults_ClearsOnBack() throws Exception {
    112         initTestFiles();
    113         assertDefaultContentOfTestDir0();
    114 
    115         String query = "chocolate";
    116         bots.main.openSearchView();
    117         bots.main.setSearchQuery(query);
    118 
    119         device.pressEnter();
    120         device.pressBack();
    121 
    122         device.waitForIdle();
    123         assertDefaultContentOfTestDir0();
    124     }
    125 
    126     @Suppress
    127     public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
    128         initTestFiles();
    129         assertDefaultContentOfTestDir0();
    130 
    131         String query = fileName1;
    132         bots.main.openSearchView();
    133         bots.main.setSearchQuery(query);
    134 
    135         device.pressEnter();
    136 
    137         bots.roots.openRoot(ROOT_1_ID);
    138         assertDefaultContentOfTestDir1();
    139 
    140         bots.roots.openRoot(ROOT_0_ID);
    141         assertDefaultContentOfTestDir0();
    142     }
    143 
    144     public void testSearchIconVisible_RootWithSearchSupport() throws Exception {
    145         bots.roots.openRoot(ROOT_0_ID);
    146         bots.main.assertSearchTextFiledAndIcon(false, true);
    147     }
    148 
    149     public void testSearchIconHidden_RootNoSearchSupport() throws Exception {
    150         bots.roots.openRoot(ROOT_1_ID);
    151         bots.main.assertSearchTextFiledAndIcon(false, false);
    152     }
    153 
    154 }
    155