blob: 863cdd0dcfa1d2bcb713de8c373b42d246419999 [file] [log] [blame]
Aga Wronska18410b72016-01-26 14:06:29 -08001/*
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 McKayae84a182016-09-16 09:36:50 -070017package com.android.documentsui;
Aga Wronska18410b72016-01-26 14:06:29 -080018
Steve McKay85ec0d62016-06-24 15:05:08 -070019import android.support.test.uiautomator.UiObjectNotFoundException;
Garfield Tan25676032016-09-19 13:52:35 -070020
Brett Chabot2027ca02018-12-13 19:06:31 -080021import androidx.test.filters.LargeTest;
22
Steve McKayb6006b22016-09-29 09:23:45 -070023import com.android.documentsui.files.FilesActivity;
Steve McKay16e0c1f2016-09-15 12:41:13 -070024
Aga Wronska18410b72016-01-26 14:06:29 -080025@LargeTest
Steve McKayb6006b22016-09-29 09:23:45 -070026public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
Aga Wronska18410b72016-01-26 14:06:29 -080027
Aga Wronska18410b72016-01-26 14:06:29 -080028 private final String newName = "kitties.log";
29
Tomasz Mikolajewskia2ad8df2016-02-04 17:46:35 +090030 public RenameDocumentUiTest() {
Steve McKayb6006b22016-09-29 09:23:45 -070031 super(FilesActivity.class);
Tomasz Mikolajewskia2ad8df2016-02-04 17:46:35 +090032 }
Aga Wronska18410b72016-01-26 14:06:29 -080033
34 @Override
35 public void setUp() throws Exception {
36 super.setUp();
Tomasz Mikolajewskia2ad8df2016-02-04 17:46:35 +090037 initTestFiles();
Ben Lin4c6e4a22016-05-23 09:49:51 -070038 bots.roots.closeDrawer();
Aga Wronska18410b72016-01-26 14:06:29 -080039 }
40
Ivan Chiangb91cfca2019-08-12 16:56:23 +080041// 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 Wronska18410b72016-01-26 14:06:29 -080078
79 public void testRenameFile_OkButton() throws Exception {
Ben Line5edf042016-09-19 13:54:30 -070080 bots.directory.selectDocument(fileName1, 1);
Steve McKay85ec0d62016-06-24 15:05:08 -070081
82 clickRename();
83
84 device.waitForIdle();
Steve McKay5e1acc92016-02-19 12:57:05 -080085 bots.main.setDialogText(newName);
Aga Wronska18410b72016-01-26 14:06:29 -080086
Steve McKay85ec0d62016-06-24 15:05:08 -070087 device.waitForIdle();
Ben Lin4c6e4a22016-05-23 09:49:51 -070088 bots.main.clickDialogOkButton();
Aga Wronska18410b72016-01-26 14:06:29 -080089
Steve McKay85ec0d62016-06-24 15:05:08 -070090 bots.directory.waitForDocument(newName);
Steve McKay5e1acc92016-02-19 12:57:05 -080091 bots.directory.assertDocumentsAbsent(fileName1);
Steve McKay5e1acc92016-02-19 12:57:05 -080092 bots.directory.assertDocumentsCount(4);
Aga Wronska18410b72016-01-26 14:06:29 -080093 }
94
95 public void testRenameFile_Enter() throws Exception {
Ben Line5edf042016-09-19 13:54:30 -070096 bots.directory.selectDocument(fileName1, 1);
Steve McKay85ec0d62016-06-24 15:05:08 -070097
98 clickRename();
99
100 device.waitForIdle();
Steve McKay5e1acc92016-02-19 12:57:05 -0800101 bots.main.setDialogText(newName);
Aga Wronska18410b72016-01-26 14:06:29 -0800102
Steve McKay85ec0d62016-06-24 15:05:08 -0700103 device.waitForIdle();
Steve McKay5e1acc92016-02-19 12:57:05 -0800104 bots.keyboard.pressEnter();
Aga Wronska18410b72016-01-26 14:06:29 -0800105
Steve McKay85ec0d62016-06-24 15:05:08 -0700106 bots.directory.waitForDocument(newName);
Steve McKay5e1acc92016-02-19 12:57:05 -0800107 bots.directory.assertDocumentsAbsent(fileName1);
Steve McKay5e1acc92016-02-19 12:57:05 -0800108 bots.directory.assertDocumentsCount(4);
Aga Wronska18410b72016-01-26 14:06:29 -0800109 }
110
Jon Mann00656ee2017-03-09 12:05:28 -0800111 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 Wronska18410b72016-01-26 14:06:29 -0800123 public void testRenameFile_Cancel() throws Exception {
Ben Line5edf042016-09-19 13:54:30 -0700124 bots.directory.selectDocument(fileName1, 1);
Steve McKay85ec0d62016-06-24 15:05:08 -0700125
126 clickRename();
127
Steve McKay5e1acc92016-02-19 12:57:05 -0800128 bots.main.setDialogText(newName);
Aga Wronska18410b72016-01-26 14:06:29 -0800129
Ben Lin4c6e4a22016-05-23 09:49:51 -0700130 bots.main.clickDialogCancelButton();
Aga Wronska18410b72016-01-26 14:06:29 -0800131
Steve McKay5e1acc92016-02-19 12:57:05 -0800132 bots.directory.assertDocumentsPresent(fileName1);
133 bots.directory.assertDocumentsAbsent(newName);
134 bots.directory.assertDocumentsCount(4);
Tony Huangf17d20a2019-08-22 17:59:43 +0800135
136 bots.directory.assertSelection(1);
Aga Wronska18410b72016-01-26 14:06:29 -0800137 }
138
139 public void testRenameDir() throws Exception {
140 String oldName = "Dir1";
141 String newName = "Dir123";
Ben Line5edf042016-09-19 13:54:30 -0700142 bots.directory.selectDocument(oldName, 1);
Steve McKay85ec0d62016-06-24 15:05:08 -0700143
144 clickRename();
145
Steve McKay5e1acc92016-02-19 12:57:05 -0800146 bots.main.setDialogText(newName);
Aga Wronska18410b72016-01-26 14:06:29 -0800147
Steve McKay5e1acc92016-02-19 12:57:05 -0800148 bots.keyboard.pressEnter();
Aga Wronska18410b72016-01-26 14:06:29 -0800149
Steve McKay5e1acc92016-02-19 12:57:05 -0800150 bots.directory.assertDocumentsAbsent(oldName);
151 bots.directory.assertDocumentsPresent(newName);
152 bots.directory.assertDocumentsCount(4);
Aga Wronska18410b72016-01-26 14:06:29 -0800153 }
154
155 public void testRename_NameExists() throws Exception {
Jon Mann38f14392017-01-25 13:51:55 -0800156 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 Wronska18410b72016-01-26 14:06:29 -0800180 // Check that document with the new name exists
Steve McKay5e1acc92016-02-19 12:57:05 -0800181 bots.directory.assertDocumentsPresent(fileName2);
Ben Line5edf042016-09-19 13:54:30 -0700182 bots.directory.selectDocument(fileName1, 1);
Steve McKay85ec0d62016-06-24 15:05:08 -0700183
184 clickRename();
185
Jon Mann38f14392017-01-25 13:51:55 -0800186 bots.main.assertDialogText(fileName1);
187 assertFalse(bots.main.findRenameErrorMessage().exists());
Jon Mann38f14392017-01-25 13:51:55 -0800188 bots.main.setDialogText(fileName2);
Jon Mann00656ee2017-03-09 12:05:28 -0800189 bots.keyboard.pressEnter();
Jon Mann38f14392017-01-25 13:51:55 -0800190 assertTrue(bots.main.findRenameErrorMessage().exists());
Aga Wronska18410b72016-01-26 14:06:29 -0800191 }
Steve McKay85ec0d62016-06-24 15:05:08 -0700192
193 private void clickRename() throws UiObjectNotFoundException {
Ben Lind1736fd2016-09-15 10:44:11 -0700194 if (!bots.main.waitForActionModeBarToAppear()) {
195 throw new UiObjectNotFoundException("ActionMode bar not found");
196 }
Steve McKay85ec0d62016-06-24 15:05:08 -0700197 bots.main.clickActionbarOverflowItem("Rename");
198 device.waitForIdle();
199 }
Jon Mann00656ee2017-03-09 12:05:28 -0800200}