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 android.app.Instrumentation; 20 import android.net.Uri; 21 import android.os.RemoteException; 22 import android.support.test.filters.LargeTest; 23 24 import com.android.documentsui.files.FilesActivity; 25 import com.android.documentsui.inspector.InspectorActivity; 26 27 @LargeTest 28 public class FilesActivityUiTest extends ActivityTest<FilesActivity> { 29 FilesActivityUiTest()30 public FilesActivityUiTest() { 31 super(FilesActivity.class); 32 } 33 34 @Override setUp()35 public void setUp() throws Exception { 36 super.setUp(); 37 initTestFiles(); 38 } 39 40 @Override initTestFiles()41 public void initTestFiles() throws RemoteException { 42 Uri uri = mDocsHelper.createFolder(rootDir0, dirName1); 43 mDocsHelper.createFolder(uri, childDir1); 44 45 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); 46 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); 47 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); 48 49 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); 50 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); 51 } 52 53 // Recents is a strange meta root that gathers entries from other providers. 54 // It is special cased in a variety of ways, which is why we just want 55 // to be able to click on it. testClickRecent()56 public void testClickRecent() throws Exception { 57 bots.roots.openRoot("Recent"); 58 bots.main.assertWindowTitle("Recent"); 59 } 60 testRootClick_SetsWindowTitle()61 public void testRootClick_SetsWindowTitle() throws Exception { 62 bots.roots.openRoot("Images"); 63 bots.main.assertWindowTitle("Images"); 64 } 65 testFilesListed()66 public void testFilesListed() throws Exception { 67 bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); 68 } 69 testFilesList_LiveUpdate()70 public void testFilesList_LiveUpdate() throws Exception { 71 mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); 72 73 bots.directory.waitForDocument("Ham & Cheese.sandwich"); 74 bots.directory.assertDocumentsPresent( 75 "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); 76 } 77 testNavigate_inFixedLayout_byBreadcrumb()78 public void testNavigate_inFixedLayout_byBreadcrumb() throws Exception { 79 bots.directory.openDocument(dirName1); 80 bots.directory.waitForDocument(childDir1); // wait for known content 81 bots.directory.assertDocumentsPresent(childDir1); 82 83 bots.breadcrumb.revealAsNeeded(); 84 device.waitForIdle(); 85 bots.breadcrumb.assertItemsPresent(dirName1, "TEST_ROOT_0"); 86 87 bots.breadcrumb.clickItem("TEST_ROOT_0"); 88 bots.directory.waitForDocument(dirName1); 89 } 90 testNavigate_inFixedLayout_whileHasSelection()91 public void testNavigate_inFixedLayout_whileHasSelection() throws Exception { 92 if (bots.main.inFixedLayout()) { 93 bots.roots.openRoot(rootDir0.title); 94 device.waitForIdle(); 95 bots.directory.selectDocument("file0.log", 1); 96 97 // ensure no exception is thrown while navigating to a different root 98 bots.roots.openRoot(rootDir1.title); 99 } 100 } 101 testNavigationToInspector()102 public void testNavigationToInspector() throws Exception { 103 if(!features.isInspectorEnabled()) { 104 return; 105 } 106 Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor( 107 InspectorActivity.class.getName(), null, false); 108 bots.directory.selectDocument("file0.log"); 109 bots.main.clickActionItem("Get info"); 110 monitor.waitForActivityWithTimeout(TIMEOUT); 111 } 112 testRootChange_UpdatesSortHeader()113 public void testRootChange_UpdatesSortHeader() throws Exception { 114 115 // switch to separate display modes for two separate roots. Each 116 // mode has its own distinct sort header. This should be remembered 117 // by files app. 118 bots.roots.openRoot("Images"); 119 bots.main.switchToGridMode(); 120 bots.roots.openRoot("Videos"); 121 bots.main.switchToListMode(); 122 123 // Now switch back and assert the correct mode sort header mode 124 // is restored when we load the root with that display mode. 125 bots.roots.openRoot("Images"); 126 bots.sortHeader.assertDropdownMode(); 127 if (bots.main.inFixedLayout()) { 128 bots.roots.openRoot("Videos"); 129 bots.sortHeader.assertColumnMode(); 130 } else { 131 bots.roots.openRoot("Videos"); 132 bots.sortHeader.assertDropdownMode(); 133 } 134 } 135 } 136