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