1 /* 2 * Copyright (C) 2018 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 androidx.test.filters.LargeTest; 20 21 import com.android.documentsui.base.Providers; 22 import com.android.documentsui.base.RootInfo; 23 import com.android.documentsui.base.State; 24 import com.android.documentsui.files.FilesActivity; 25 import com.android.documentsui.filters.HugeLongTest; 26 27 /** 28 * A Ui test will do tests in the internal storage root. It is implemented because some operations 29 * is failed and its result will different from the test on the StubProvider. b/115304092 is a 30 * example which only happen on root from ExternalStorageProvidrer. 31 */ 32 @LargeTest 33 public class InternalStorageUiTest extends ActivityTest<FilesActivity> { 34 35 private static final String fileName = "!Test3345678"; 36 private static final String newFileName = "!9527Test"; 37 private RootInfo rootPrimary; 38 InternalStorageUiTest()39 public InternalStorageUiTest() { 40 super(FilesActivity.class); 41 } 42 43 @Override setUp()44 public void setUp() throws Exception { 45 super.setUp(); 46 47 mClient = mResolver.acquireUnstableContentProviderClient(Providers.AUTHORITY_STORAGE); 48 mDocsHelper = new DocumentsProviderHelper(Providers.AUTHORITY_STORAGE, mClient); 49 rootPrimary = mDocsHelper.getRoot(Providers.ROOT_ID_DEVICE); 50 51 // If Internal Storage is not shown, turn on. 52 State state = ((FilesActivity) getActivity()).getDisplayState(); 53 if (!state.showAdvanced) { 54 bots.main.clickToolbarOverflowItem( 55 context.getResources().getString(R.string.menu_advanced_show)); 56 } 57 58 bots.roots.openRoot(rootPrimary.title); 59 deleteTestFiles(); 60 } 61 62 @Override tearDown()63 public void tearDown() throws Exception { 64 deleteTestFiles(); 65 super.tearDown(); 66 } 67 68 @HugeLongTest testRenameFile()69 public void testRenameFile() throws Exception { 70 createTestFiles(); 71 72 bots.directory.selectDocument(fileName); 73 device.waitForIdle(); 74 75 bots.main.clickRename(); 76 77 bots.main.setDialogText(newFileName); 78 device.waitForIdle(); 79 80 bots.keyboard.pressEnter(); 81 82 bots.directory.assertDocumentsAbsent(fileName); 83 bots.directory.assertDocumentsPresent(newFileName); 84 // Snackbar will not show if no exception. 85 assertNull(bots.directory.getSnackbar(context.getString(R.string.rename_error))); 86 } 87 createTestFiles()88 private void createTestFiles() { 89 mDocsHelper.createFolder(rootPrimary, fileName); 90 } 91 deleteTestFiles()92 private void deleteTestFiles() throws Exception { 93 boolean selected = false; 94 // Delete the added file for not affect user and also avoid error on next test. 95 if (bots.directory.hasDocuments(fileName)) { 96 bots.directory.selectDocument(fileName); 97 device.waitForIdle(); 98 selected = true; 99 } 100 if (bots.directory.hasDocuments(newFileName)) { 101 bots.directory.selectDocument(newFileName); 102 device.waitForIdle(); 103 selected = true; 104 } 105 if (selected) { 106 bots.main.clickDelete(); 107 device.waitForIdle(); 108 bots.main.clickDialogOkButton(); 109 } 110 } 111 } 112