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.graphics.Point; 20 import android.graphics.Rect; 21 import android.net.Uri; 22 import android.os.RemoteException; 23 import android.support.test.filters.LargeTest; 24 25 import com.android.documentsui.files.FilesActivity; 26 27 import java.util.HashMap; 28 import java.util.Map; 29 30 @LargeTest 31 public class ContextMenuUiTest extends ActivityTest<FilesActivity> { 32 33 private Map<String, Boolean> menuItems; 34 35 public ContextMenuUiTest() { 36 super(FilesActivity.class); 37 } 38 39 @Override 40 public void setUp() throws Exception { 41 super.setUp(); 42 initTestFiles(); 43 bots.roots.closeDrawer(); 44 menuItems = new HashMap<>(); 45 46 menuItems.put("Share", false); 47 menuItems.put("Open", false); 48 menuItems.put("Open with", false); 49 menuItems.put("Cut", false); 50 menuItems.put("Copy", false); 51 menuItems.put("Rename", false); 52 menuItems.put("Delete", false); 53 menuItems.put("Open in new window", false); 54 menuItems.put("Paste into folder", false); 55 menuItems.put("Select all", false); 56 menuItems.put("New folder", false); 57 } 58 59 @Override 60 public void initTestFiles() throws RemoteException { 61 Uri uri = mDocsHelper.createFolder(rootDir0, dirName1); 62 mDocsHelper.createFolder(uri, childDir1); 63 64 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log"); 65 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png"); 66 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv"); 67 68 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log"); 69 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text"); 70 } 71 72 public void testContextMenu_onFile() throws Exception { 73 menuItems.put("Share", true); 74 menuItems.put("Open", true); 75 menuItems.put("Open with", true); 76 menuItems.put("Cut", true); 77 menuItems.put("Copy", true); 78 menuItems.put("Rename", true); 79 menuItems.put("Delete", true); 80 81 bots.directory.rightClickDocument("file1.png"); 82 bots.menu.assertPresentMenuItems(menuItems); 83 } 84 85 public void testContextMenu_onDir() throws Exception { 86 menuItems.put("Cut", true); 87 menuItems.put("Copy", true); 88 menuItems.put("Paste into folder", true); 89 menuItems.put("Open in new window", true); 90 menuItems.put("Delete", true); 91 menuItems.put("Rename", true); 92 bots.directory.rightClickDocument("Dir1"); 93 bots.menu.assertPresentMenuItems(menuItems); 94 } 95 96 public void testContextMenu_onMixedFileDir() throws Exception { 97 menuItems.put("Cut", true); 98 menuItems.put("Copy", true); 99 menuItems.put("Delete", true); 100 bots.directory.selectDocument("file1.png", 1); 101 bots.directory.selectDocument("Dir1", 2); 102 bots.directory.rightClickDocument("Dir1"); 103 bots.menu.assertPresentMenuItems(menuItems); 104 } 105 106 public void testContextMenu_onEmptyArea() throws Exception { 107 menuItems.put("Select all", true); 108 menuItems.put("Paste", true); 109 menuItems.put("New folder", true); 110 Rect dirListBounds = bots.directory.findDocumentsList().getBounds(); 111 bots.directory.rightClickDocument( 112 new Point(dirListBounds.right - 1, dirListBounds.bottom - 1)); //bottom right corner 113 bots.menu.assertPresentMenuItems(menuItems); 114 } 115 } 116