blob: b866033f647e294a1d20cbfc4a66561b329a10a7 [file] [log] [blame]
Aga Wronska0950df12016-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
17package com.android.documentsui;
18
19import static com.android.documentsui.StubProvider.ROOT_0_ID;
Aga Wronska0950df12016-01-26 14:06:29 -080020
Aga Wronska0950df12016-01-26 14:06:29 -080021import android.test.suitebuilder.annotation.LargeTest;
22
23@LargeTest
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090024public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
Aga Wronska0950df12016-01-26 14:06:29 -080025
Aga Wronska0950df12016-01-26 14:06:29 -080026 private final String newName = "kitties.log";
27
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090028 public RenameDocumentUiTest() {
29 super(FilesActivity.class);
30 }
Aga Wronska0950df12016-01-26 14:06:29 -080031
32 @Override
33 public void setUp() throws Exception {
34 super.setUp();
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090035 initTestFiles();
Steve McKayb9a20d12016-02-19 12:57:05 -080036 bots.roots.openRoot(ROOT_0_ID);
Aga Wronska0950df12016-01-26 14:06:29 -080037 }
38
39 public void testRenameEnabled_SingleSelection() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080040 bots.directory.selectDocument(fileName1);
41 bots.main.openOverflowMenu();
42 bots.main.assertMenuEnabled(R.string.menu_rename, true);
Aga Wronska0950df12016-01-26 14:06:29 -080043
44 // Dismiss more options window
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090045 device.pressBack();
Aga Wronska0950df12016-01-26 14:06:29 -080046 }
47
48 public void testNoRenameSupport_SingleSelection() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080049 bots.directory.selectDocument(fileNameNoRename);
50 bots.main.openOverflowMenu();
51 bots.main.assertMenuEnabled(R.string.menu_rename, false);
Aga Wronska0950df12016-01-26 14:06:29 -080052
53 // Dismiss more options window
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090054 device.pressBack();
Aga Wronska0950df12016-01-26 14:06:29 -080055 }
56
57 public void testOneHasRenameSupport_MultipleSelection() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080058 bots.directory.selectDocument(fileName1);
59 bots.directory.selectDocument(fileNameNoRename);
60 bots.main.openOverflowMenu();
61 bots.main.assertMenuEnabled(R.string.menu_rename, false);
Aga Wronska0950df12016-01-26 14:06:29 -080062
63 // Dismiss more options window
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090064 device.pressBack();
Aga Wronska0950df12016-01-26 14:06:29 -080065 }
66
67 public void testRenameDisabled_MultipleSelection() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080068 bots.directory.selectDocument(fileName1);
69 bots.directory.selectDocument(fileName2);
70 bots.main.openOverflowMenu();
71 bots.main.assertMenuEnabled(R.string.menu_rename, false);
Aga Wronska0950df12016-01-26 14:06:29 -080072
73 // Dismiss more options window
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090074 device.pressBack();
Aga Wronska0950df12016-01-26 14:06:29 -080075 }
76
77 public void testRenameFile_OkButton() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080078 bots.directory.selectDocument(fileName1);
79 bots.main.openOverflowMenu();
80 bots.main.menuRename().click();
81 bots.main.setDialogText(newName);
Aga Wronska0950df12016-01-26 14:06:29 -080082
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090083 device.waitForIdle(TIMEOUT);
Steve McKayb9a20d12016-02-19 12:57:05 -080084 bots.main.findRenameDialogOkButton().click();
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090085 device.waitForIdle(TIMEOUT);
Aga Wronska0950df12016-01-26 14:06:29 -080086
Steve McKayb9a20d12016-02-19 12:57:05 -080087 bots.directory.assertDocumentsAbsent(fileName1);
88 bots.directory.assertDocumentsPresent(newName);
89 bots.directory.assertDocumentsCount(4);
Aga Wronska0950df12016-01-26 14:06:29 -080090 }
91
92 public void testRenameFile_Enter() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -080093 bots.directory.selectDocument(fileName1);
94 bots.main.openOverflowMenu();
95 bots.main.menuRename().click();
96 bots.main.setDialogText(newName);
Aga Wronska0950df12016-01-26 14:06:29 -080097
Steve McKayb9a20d12016-02-19 12:57:05 -080098 bots.keyboard.pressEnter();
Aga Wronska0950df12016-01-26 14:06:29 -080099
Steve McKayb9a20d12016-02-19 12:57:05 -0800100 bots.directory.assertDocumentsAbsent(fileName1);
101 bots.directory.assertDocumentsPresent(newName);
102 bots.directory.assertDocumentsCount(4);
Aga Wronska0950df12016-01-26 14:06:29 -0800103 }
104
105 public void testRenameFile_Cancel() throws Exception {
Steve McKayb9a20d12016-02-19 12:57:05 -0800106 bots.directory.selectDocument(fileName1);
107 bots.main.openOverflowMenu();
108 bots.main.menuRename().click();
109 bots.main.setDialogText(newName);
Aga Wronska0950df12016-01-26 14:06:29 -0800110
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900111 device.waitForIdle(TIMEOUT);
Steve McKayb9a20d12016-02-19 12:57:05 -0800112 bots.main.findRenameDialogCancelButton().click();
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +0900113 device.waitForIdle(TIMEOUT);
Aga Wronska0950df12016-01-26 14:06:29 -0800114
Steve McKayb9a20d12016-02-19 12:57:05 -0800115 bots.directory.assertDocumentsPresent(fileName1);
116 bots.directory.assertDocumentsAbsent(newName);
117 bots.directory.assertDocumentsCount(4);
Aga Wronska0950df12016-01-26 14:06:29 -0800118 }
119
120 public void testRenameDir() throws Exception {
121 String oldName = "Dir1";
122 String newName = "Dir123";
123
Steve McKayb9a20d12016-02-19 12:57:05 -0800124 bots.directory.selectDocument(oldName);
125 bots.main.openOverflowMenu();
126 bots.main.menuRename().click();
127 bots.main.setDialogText(newName);
Aga Wronska0950df12016-01-26 14:06:29 -0800128
Steve McKayb9a20d12016-02-19 12:57:05 -0800129 bots.keyboard.pressEnter();
Aga Wronska0950df12016-01-26 14:06:29 -0800130
Steve McKayb9a20d12016-02-19 12:57:05 -0800131 bots.directory.assertDocumentsAbsent(oldName);
132 bots.directory.assertDocumentsPresent(newName);
133 bots.directory.assertDocumentsCount(4);
Aga Wronska0950df12016-01-26 14:06:29 -0800134 }
135
136 public void testRename_NameExists() throws Exception {
137 // Check that document with the new name exists
Steve McKayb9a20d12016-02-19 12:57:05 -0800138 bots.directory.assertDocumentsPresent(fileName2);
139 bots.directory.selectDocument(fileName1);
140 bots.main.openOverflowMenu();
141 bots.main.menuRename().click();
142 bots.main.setDialogText(fileName2);
Aga Wronska0950df12016-01-26 14:06:29 -0800143
Steve McKayb9a20d12016-02-19 12:57:05 -0800144 bots.keyboard.pressEnter();
Aga Wronska0950df12016-01-26 14:06:29 -0800145
Steve McKayb9a20d12016-02-19 12:57:05 -0800146 bots.directory.assertSnackbar(R.string.rename_error);
147 bots.directory.assertDocumentsPresent(fileName1);
148 bots.directory.assertDocumentsPresent(fileName2);
149 bots.directory.assertDocumentsCount(4);
Aga Wronska0950df12016-01-26 14:06:29 -0800150 }
Aga Wronska0950df12016-01-26 14:06:29 -0800151}