1 /* 2 * Copyright (C) 2015 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.flags.Flags.FLAG_HIDE_ROOTS_ON_DESKTOP_RO; 20 import static com.android.documentsui.flags.Flags.FLAG_USE_SEARCH_V2_READ_ONLY; 21 import static com.android.documentsui.flags.Flags.FLAG_USE_MATERIAL3; 22 23 import android.app.Instrumentation; 24 import android.net.Uri; 25 import android.os.RemoteException; 26 import android.platform.test.annotations.RequiresFlagsDisabled; 27 import android.platform.test.annotations.RequiresFlagsEnabled; 28 import android.platform.test.flag.junit.CheckFlagsRule; 29 import android.platform.test.flag.junit.DeviceFlagsValueProvider; 30 31 import androidx.test.ext.junit.runners.AndroidJUnit4; 32 import androidx.test.filters.LargeTest; 33 34 import com.android.documentsui.files.FilesActivity; 35 import com.android.documentsui.filters.HugeLongTest; 36 import com.android.documentsui.inspector.InspectorActivity; 37 38 import org.junit.After; 39 import org.junit.Before; 40 import org.junit.Rule; 41 import org.junit.Test; 42 import org.junit.runner.RunWith; 43 44 @LargeTest 45 @RunWith(AndroidJUnit4.class) 46 public class FilesActivityUiTest extends ActivityTestJunit4<FilesActivity> { 47 48 @Rule 49 public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); 50 51 @Before setUp()52 public void setUp() throws Exception { 53 super.setUp(); 54 initTestFiles(); 55 } 56 57 @After tearDown()58 public void tearDown() throws Exception { 59 super.tearDown(); 60 } 61 62 @Override initTestFiles()63 public void initTestFiles() throws RemoteException { 64 Uri uri = mDocsHelper.createFolder(rootDir0, dirName1); 65 mDocsHelper.createFolder(uri, childDir1); 66 67 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); 68 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); 69 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); 70 71 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); 72 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); 73 } 74 75 // Recents is a strange meta root that gathers entries from other providers. 76 // It is special cased in a variety of ways, which is why we just want 77 // to be able to click on it. 78 @Test testClickRecent()79 public void testClickRecent() throws Exception { 80 bots.roots.openRoot("Recent"); 81 82 boolean showSearchBar = 83 context.getResources().getBoolean(R.bool.show_search_bar); 84 if (showSearchBar) { 85 bots.main.assertSearchBarShow(); 86 } else { 87 bots.main.assertWindowTitle("Recent"); 88 } 89 } 90 91 @Test 92 @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP_RO) testRootClick_SetsWindowTitle()93 public void testRootClick_SetsWindowTitle() throws Exception { 94 bots.roots.openRoot("Images"); 95 bots.main.assertWindowTitle("Images"); 96 } 97 filesListed()98 private void filesListed() throws Exception { 99 bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); 100 } 101 102 @Test 103 @RequiresFlagsDisabled(FLAG_USE_SEARCH_V2_READ_ONLY) testFilesListed()104 public void testFilesListed() throws Exception { 105 filesListed(); 106 } 107 108 @Test 109 @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY, FLAG_USE_MATERIAL3}) testFilesListed_searchV2()110 public void testFilesListed_searchV2() throws Exception { 111 filesListed(); 112 } 113 filesListed_LiveUpdates()114 private void filesListed_LiveUpdates() throws Exception { 115 mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); 116 117 bots.directory.waitForDocument("Ham & Cheese.sandwich"); 118 bots.directory.assertDocumentsPresent( 119 "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); 120 } 121 122 @Test 123 @RequiresFlagsDisabled(FLAG_USE_SEARCH_V2_READ_ONLY) testFilesList_LiveUpdate()124 public void testFilesList_LiveUpdate() throws Exception { 125 filesListed_LiveUpdates(); 126 } 127 128 @Test 129 @RequiresFlagsEnabled({FLAG_USE_SEARCH_V2_READ_ONLY, FLAG_USE_MATERIAL3}) testFilesList_LiveUpdate_searchV2()130 public void testFilesList_LiveUpdate_searchV2() throws Exception { 131 filesListed_LiveUpdates(); 132 } 133 134 @Test testNavigate_byBreadcrumb()135 public void testNavigate_byBreadcrumb() throws Exception { 136 bots.directory.openDocument(dirName1); 137 bots.directory.waitForDocument(childDir1); // wait for known content 138 bots.directory.assertDocumentsPresent(childDir1); 139 140 device.waitForIdle(); 141 bots.breadcrumb.assertItemsPresent(dirName1, "TEST_ROOT_0"); 142 143 bots.breadcrumb.clickItem("TEST_ROOT_0"); 144 bots.directory.waitForDocument(dirName1); 145 } 146 147 @Test testNavigate_inFixedLayout_whileHasSelection()148 public void testNavigate_inFixedLayout_whileHasSelection() throws Exception { 149 if (bots.main.inFixedLayout()) { 150 bots.roots.openRoot(rootDir0.title); 151 device.waitForIdle(); 152 bots.directory.selectDocument("file0.log", 1); 153 154 // ensure no exception is thrown while navigating to a different root 155 bots.roots.openRoot(rootDir1.title); 156 } 157 } 158 159 @Test testNavigationToInspector()160 public void testNavigationToInspector() throws Exception { 161 if(!features.isInspectorEnabled()) { 162 return; 163 } 164 Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor( 165 InspectorActivity.class.getName(), null, false); 166 bots.directory.selectDocument("file0.log"); 167 bots.main.clickActionItem("Get info"); 168 monitor.waitForActivityWithTimeout(TIMEOUT); 169 } 170 171 @Test 172 @HugeLongTest 173 @RequiresFlagsDisabled(FLAG_HIDE_ROOTS_ON_DESKTOP_RO) testRootChange_UpdatesSortHeader()174 public void testRootChange_UpdatesSortHeader() throws Exception { 175 176 // switch to separate display modes for two separate roots. Each 177 // mode has its own distinct sort header. This should be remembered 178 // by files app. 179 bots.roots.openRoot("Images"); 180 bots.main.switchToGridMode(); 181 bots.roots.openRoot("Videos"); 182 bots.main.switchToListMode(); 183 184 // Now switch back and assert the correct mode sort header mode 185 // is restored when we load the root with that display mode. 186 bots.roots.openRoot("Images"); 187 bots.sort.assertHeaderHide(); 188 if (bots.main.inFixedLayout()) { 189 bots.roots.openRoot("Videos"); 190 bots.sort.assertHeaderShow(); 191 } else { 192 bots.roots.openRoot("Videos"); 193 bots.sort.assertHeaderHide(); 194 } 195 } 196 } 197