Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 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 | |
Steve McKay | ae84a18 | 2016-09-16 09:36:50 -0700 | [diff] [blame] | 17 | package com.android.documentsui; |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 18 | |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 19 | import android.support.test.uiautomator.UiObjectNotFoundException; |
Garfield Tan | 2567603 | 2016-09-19 13:52:35 -0700 | [diff] [blame] | 20 | |
Brett Chabot | 2027ca0 | 2018-12-13 19:06:31 -0800 | [diff] [blame] | 21 | import androidx.test.filters.LargeTest; |
| 22 | |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 23 | import com.android.documentsui.files.FilesActivity; |
Steve McKay | 16e0c1f | 2016-09-15 12:41:13 -0700 | [diff] [blame] | 24 | |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 25 | @LargeTest |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 26 | public class RenameDocumentUiTest extends ActivityTest<FilesActivity> { |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 27 | |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 28 | private final String newName = "kitties.log"; |
| 29 | |
Tomasz Mikolajewski | a2ad8df | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 30 | public RenameDocumentUiTest() { |
Steve McKay | b6006b2 | 2016-09-29 09:23:45 -0700 | [diff] [blame] | 31 | super(FilesActivity.class); |
Tomasz Mikolajewski | a2ad8df | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 32 | } |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 33 | |
| 34 | @Override |
| 35 | public void setUp() throws Exception { |
| 36 | super.setUp(); |
Tomasz Mikolajewski | a2ad8df | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 37 | initTestFiles(); |
Ben Lin | 4c6e4a2 | 2016-05-23 09:49:51 -0700 | [diff] [blame] | 38 | bots.roots.closeDrawer(); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 39 | } |
| 40 | |
Ivan Chiang | b91cfca | 2019-08-12 16:56:23 +0800 | [diff] [blame] | 41 | // public void testRenameEnabled_SingleSelection() throws Exception { |
| 42 | // bots.directory.selectDocument(fileName1, 1); |
| 43 | // bots.main.openOverflowMenu(); |
| 44 | // bots.main.assertMenuEnabled(R.string.menu_rename, true); |
| 45 | // |
| 46 | // // Dismiss more options window |
| 47 | // device.pressBack(); |
| 48 | // } |
| 49 | // |
| 50 | // public void testNoRenameSupport_SingleSelection() throws Exception { |
| 51 | // bots.directory.selectDocument(fileNameNoRename, 1); |
| 52 | // bots.main.openOverflowMenu(); |
| 53 | // bots.main.assertMenuEnabled(R.string.menu_rename, false); |
| 54 | // |
| 55 | // // Dismiss more options window |
| 56 | // device.pressBack(); |
| 57 | // } |
| 58 | // |
| 59 | // public void testOneHasRenameSupport_MultipleSelection() throws Exception { |
| 60 | // bots.directory.selectDocument(fileName1, 1); |
| 61 | // bots.directory.selectDocument(fileNameNoRename, 2); |
| 62 | // bots.main.openOverflowMenu(); |
| 63 | // bots.main.assertMenuEnabled(R.string.menu_rename, false); |
| 64 | // |
| 65 | // // Dismiss more options window |
| 66 | // device.pressBack(); |
| 67 | // } |
| 68 | // |
| 69 | // public void testRenameDisabled_MultipleSelection() throws Exception { |
| 70 | // bots.directory.selectDocument(fileName1, 1); |
| 71 | // bots.directory.selectDocument(fileName2, 2); |
| 72 | // bots.main.openOverflowMenu(); |
| 73 | // bots.main.assertMenuEnabled(R.string.menu_rename, false); |
| 74 | // |
| 75 | // // Dismiss more options window |
| 76 | // device.pressBack(); |
| 77 | // } |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 78 | |
| 79 | public void testRenameFile_OkButton() throws Exception { |
Ben Lin | e5edf04 | 2016-09-19 13:54:30 -0700 | [diff] [blame] | 80 | bots.directory.selectDocument(fileName1, 1); |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 81 | |
| 82 | clickRename(); |
| 83 | |
| 84 | device.waitForIdle(); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 85 | bots.main.setDialogText(newName); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 86 | |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 87 | device.waitForIdle(); |
Ben Lin | 4c6e4a2 | 2016-05-23 09:49:51 -0700 | [diff] [blame] | 88 | bots.main.clickDialogOkButton(); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 89 | |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 90 | bots.directory.waitForDocument(newName); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 91 | bots.directory.assertDocumentsAbsent(fileName1); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 92 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | public void testRenameFile_Enter() throws Exception { |
Ben Lin | e5edf04 | 2016-09-19 13:54:30 -0700 | [diff] [blame] | 96 | bots.directory.selectDocument(fileName1, 1); |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 97 | |
| 98 | clickRename(); |
| 99 | |
| 100 | device.waitForIdle(); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 101 | bots.main.setDialogText(newName); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 102 | |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 103 | device.waitForIdle(); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 104 | bots.keyboard.pressEnter(); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 105 | |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 106 | bots.directory.waitForDocument(newName); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 107 | bots.directory.assertDocumentsAbsent(fileName1); |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 108 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Jon Mann | 00656ee | 2017-03-09 12:05:28 -0800 | [diff] [blame] | 111 | public void testRenameWithoutChangeIsNoOp() throws Exception { |
| 112 | bots.directory.selectDocument(fileName1, 1); |
| 113 | |
| 114 | clickRename(); |
| 115 | |
| 116 | device.waitForIdle(); |
| 117 | bots.keyboard.pressEnter(); |
| 118 | |
| 119 | bots.directory.waitForDocument(fileName1); |
| 120 | bots.directory.assertDocumentsCount(4); |
| 121 | } |
| 122 | |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 123 | public void testRenameFile_Cancel() throws Exception { |
Ben Lin | e5edf04 | 2016-09-19 13:54:30 -0700 | [diff] [blame] | 124 | bots.directory.selectDocument(fileName1, 1); |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 125 | |
| 126 | clickRename(); |
| 127 | |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 128 | bots.main.setDialogText(newName); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 129 | |
Ben Lin | 4c6e4a2 | 2016-05-23 09:49:51 -0700 | [diff] [blame] | 130 | bots.main.clickDialogCancelButton(); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 131 | |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 132 | bots.directory.assertDocumentsPresent(fileName1); |
| 133 | bots.directory.assertDocumentsAbsent(newName); |
| 134 | bots.directory.assertDocumentsCount(4); |
Tony Huang | f17d20a | 2019-08-22 17:59:43 +0800 | [diff] [blame] | 135 | |
| 136 | bots.directory.assertSelection(1); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | public void testRenameDir() throws Exception { |
| 140 | String oldName = "Dir1"; |
| 141 | String newName = "Dir123"; |
Ben Lin | e5edf04 | 2016-09-19 13:54:30 -0700 | [diff] [blame] | 142 | bots.directory.selectDocument(oldName, 1); |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 143 | |
| 144 | clickRename(); |
| 145 | |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 146 | bots.main.setDialogText(newName); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 147 | |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 148 | bots.keyboard.pressEnter(); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 149 | |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 150 | bots.directory.assertDocumentsAbsent(oldName); |
| 151 | bots.directory.assertDocumentsPresent(newName); |
| 152 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | public void testRename_NameExists() throws Exception { |
Jon Mann | 38f1439 | 2017-01-25 13:51:55 -0800 | [diff] [blame] | 156 | renameWithConflict(); |
| 157 | |
| 158 | bots.main.clickDialogCancelButton(); |
| 159 | |
| 160 | bots.directory.assertDocumentsPresent(fileName1); |
| 161 | bots.directory.assertDocumentsPresent(fileName2); |
| 162 | bots.directory.assertDocumentsCount(4); |
| 163 | } |
| 164 | |
| 165 | public void testRename_RecoverAfterConflict() throws Exception { |
| 166 | renameWithConflict(); |
| 167 | device.waitForIdle(); |
| 168 | |
| 169 | bots.main.setDialogText(newName); |
| 170 | |
| 171 | device.waitForIdle(); |
| 172 | bots.main.clickDialogOkButton(); |
| 173 | |
| 174 | bots.directory.waitForDocument(newName); |
| 175 | bots.directory.assertDocumentsAbsent(fileName1); |
| 176 | bots.directory.assertDocumentsCount(4); |
| 177 | } |
| 178 | |
| 179 | private void renameWithConflict() throws Exception { |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 180 | // Check that document with the new name exists |
Steve McKay | 5e1acc9 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 181 | bots.directory.assertDocumentsPresent(fileName2); |
Ben Lin | e5edf04 | 2016-09-19 13:54:30 -0700 | [diff] [blame] | 182 | bots.directory.selectDocument(fileName1, 1); |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 183 | |
| 184 | clickRename(); |
| 185 | |
Jon Mann | 38f1439 | 2017-01-25 13:51:55 -0800 | [diff] [blame] | 186 | bots.main.assertDialogText(fileName1); |
| 187 | assertFalse(bots.main.findRenameErrorMessage().exists()); |
Jon Mann | 38f1439 | 2017-01-25 13:51:55 -0800 | [diff] [blame] | 188 | bots.main.setDialogText(fileName2); |
Jon Mann | 00656ee | 2017-03-09 12:05:28 -0800 | [diff] [blame] | 189 | bots.keyboard.pressEnter(); |
Jon Mann | 38f1439 | 2017-01-25 13:51:55 -0800 | [diff] [blame] | 190 | assertTrue(bots.main.findRenameErrorMessage().exists()); |
Aga Wronska | 18410b7 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 191 | } |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 192 | |
| 193 | private void clickRename() throws UiObjectNotFoundException { |
Ben Lin | d1736fd | 2016-09-15 10:44:11 -0700 | [diff] [blame] | 194 | if (!bots.main.waitForActionModeBarToAppear()) { |
| 195 | throw new UiObjectNotFoundException("ActionMode bar not found"); |
| 196 | } |
Steve McKay | 85ec0d6 | 2016-06-24 15:05:08 -0700 | [diff] [blame] | 197 | bots.main.clickActionbarOverflowItem("Rename"); |
| 198 | device.waitForIdle(); |
| 199 | } |
Jon Mann | 00656ee | 2017-03-09 12:05:28 -0800 | [diff] [blame] | 200 | } |