Aga Wronska | 0950df1 | 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 | |
| 17 | package com.android.documentsui; |
| 18 | |
| 19 | import static com.android.documentsui.StubProvider.ROOT_0_ID; |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 20 | |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 21 | import android.test.suitebuilder.annotation.LargeTest; |
| 22 | |
| 23 | @LargeTest |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 24 | public class RenameDocumentUiTest extends ActivityTest<FilesActivity> { |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 25 | |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 26 | private final String newName = "kitties.log"; |
| 27 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 28 | public RenameDocumentUiTest() { |
| 29 | super(FilesActivity.class); |
| 30 | } |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 31 | |
| 32 | @Override |
| 33 | public void setUp() throws Exception { |
| 34 | super.setUp(); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 35 | initTestFiles(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 36 | bots.roots.openRoot(ROOT_0_ID); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public void testRenameEnabled_SingleSelection() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 40 | bots.directory.selectDocument(fileName1); |
| 41 | bots.main.openOverflowMenu(); |
| 42 | bots.main.assertMenuEnabled(R.string.menu_rename, true); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 43 | |
| 44 | // Dismiss more options window |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 45 | device.pressBack(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | public void testNoRenameSupport_SingleSelection() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 49 | bots.directory.selectDocument(fileNameNoRename); |
| 50 | bots.main.openOverflowMenu(); |
| 51 | bots.main.assertMenuEnabled(R.string.menu_rename, false); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 52 | |
| 53 | // Dismiss more options window |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 54 | device.pressBack(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | public void testOneHasRenameSupport_MultipleSelection() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 58 | bots.directory.selectDocument(fileName1); |
| 59 | bots.directory.selectDocument(fileNameNoRename); |
| 60 | bots.main.openOverflowMenu(); |
| 61 | bots.main.assertMenuEnabled(R.string.menu_rename, false); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 62 | |
| 63 | // Dismiss more options window |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 64 | device.pressBack(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | public void testRenameDisabled_MultipleSelection() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 68 | bots.directory.selectDocument(fileName1); |
| 69 | bots.directory.selectDocument(fileName2); |
| 70 | bots.main.openOverflowMenu(); |
| 71 | bots.main.assertMenuEnabled(R.string.menu_rename, false); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 72 | |
| 73 | // Dismiss more options window |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 74 | device.pressBack(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | public void testRenameFile_OkButton() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 78 | bots.directory.selectDocument(fileName1); |
| 79 | bots.main.openOverflowMenu(); |
| 80 | bots.main.menuRename().click(); |
| 81 | bots.main.setDialogText(newName); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 82 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 83 | device.waitForIdle(TIMEOUT); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 84 | bots.main.findRenameDialogOkButton().click(); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 85 | device.waitForIdle(TIMEOUT); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 86 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 87 | bots.directory.assertDocumentsAbsent(fileName1); |
| 88 | bots.directory.assertDocumentsPresent(newName); |
| 89 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | public void testRenameFile_Enter() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 93 | bots.directory.selectDocument(fileName1); |
| 94 | bots.main.openOverflowMenu(); |
| 95 | bots.main.menuRename().click(); |
| 96 | bots.main.setDialogText(newName); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 97 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 98 | bots.keyboard.pressEnter(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 99 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 100 | bots.directory.assertDocumentsAbsent(fileName1); |
| 101 | bots.directory.assertDocumentsPresent(newName); |
| 102 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | public void testRenameFile_Cancel() throws Exception { |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 106 | bots.directory.selectDocument(fileName1); |
| 107 | bots.main.openOverflowMenu(); |
| 108 | bots.main.menuRename().click(); |
| 109 | bots.main.setDialogText(newName); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 110 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 111 | device.waitForIdle(TIMEOUT); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 112 | bots.main.findRenameDialogCancelButton().click(); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 113 | device.waitForIdle(TIMEOUT); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 114 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 115 | bots.directory.assertDocumentsPresent(fileName1); |
| 116 | bots.directory.assertDocumentsAbsent(newName); |
| 117 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | public void testRenameDir() throws Exception { |
| 121 | String oldName = "Dir1"; |
| 122 | String newName = "Dir123"; |
| 123 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 124 | bots.directory.selectDocument(oldName); |
| 125 | bots.main.openOverflowMenu(); |
| 126 | bots.main.menuRename().click(); |
| 127 | bots.main.setDialogText(newName); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 128 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 129 | bots.keyboard.pressEnter(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 130 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 131 | bots.directory.assertDocumentsAbsent(oldName); |
| 132 | bots.directory.assertDocumentsPresent(newName); |
| 133 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | public void testRename_NameExists() throws Exception { |
| 137 | // Check that document with the new name exists |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 138 | bots.directory.assertDocumentsPresent(fileName2); |
| 139 | bots.directory.selectDocument(fileName1); |
| 140 | bots.main.openOverflowMenu(); |
| 141 | bots.main.menuRename().click(); |
| 142 | bots.main.setDialogText(fileName2); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 143 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 144 | bots.keyboard.pressEnter(); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 145 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 146 | bots.directory.assertSnackbar(R.string.rename_error); |
| 147 | bots.directory.assertDocumentsPresent(fileName1); |
| 148 | bots.directory.assertDocumentsPresent(fileName2); |
| 149 | bots.directory.assertDocumentsCount(4); |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 150 | } |
Aga Wronska | 0950df1 | 2016-01-26 14:06:29 -0800 | [diff] [blame] | 151 | } |