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 24 import androidx.test.filters.LargeTest; 25 26 import com.android.documentsui.files.FilesActivity; 27 28 import java.util.HashMap; 29 import java.util.Map; 30 31 @LargeTest 32 public class ContextMenuUiTest extends ActivityTest<FilesActivity> { 33 34 private Map<String, Boolean> menuItems; 35 ContextMenuUiTest()36 public ContextMenuUiTest() { 37 super(FilesActivity.class); 38 } 39 40 @Override setUp()41 public void setUp() throws Exception { 42 super.setUp(); 43 initTestFiles(); 44 bots.roots.closeDrawer(); 45 menuItems = new HashMap<>(); 46 47 menuItems.put("Share", false); 48 menuItems.put("Open", false); 49 menuItems.put("Open with", false); 50 menuItems.put("Cut", false); 51 menuItems.put("Copy", false); 52 menuItems.put("Rename", false); 53 menuItems.put("Delete", false); 54 menuItems.put("Open in new window", false); 55 menuItems.put("Select all", false); 56 menuItems.put("New folder", false); 57 } 58 59 @Override initTestFiles()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 testContextMenu_onFile()72 public void testContextMenu_onFile() throws Exception { 73 menuItems.put("Share", true); 74 menuItems.put("Open", false); 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 testContextMenu_onDir()85 public void testContextMenu_onDir() throws Exception { 86 menuItems.put("Cut", true); 87 menuItems.put("Copy", true); 88 menuItems.put("Open in new window", true); 89 menuItems.put("Delete", true); 90 menuItems.put("Rename", true); 91 bots.directory.rightClickDocument("Dir1"); 92 bots.menu.assertPresentMenuItems(menuItems); 93 } 94 testContextMenu_onMixedFileDir()95 public void testContextMenu_onMixedFileDir() throws Exception { 96 menuItems.put("Cut", true); 97 menuItems.put("Copy", true); 98 menuItems.put("Delete", true); 99 bots.directory.selectDocument("file1.png", 1); 100 bots.directory.selectDocument("Dir1", 2); 101 bots.directory.rightClickDocument("Dir1"); 102 bots.menu.assertPresentMenuItems(menuItems); 103 } 104 testContextMenu_onEmptyArea()105 public void testContextMenu_onEmptyArea() throws Exception { 106 menuItems.put("Select all", true); 107 menuItems.put("New folder", true); 108 Rect dirListBounds = bots.directory.findDocumentsList().getBounds(); 109 Rect dirBounds = bots.directory.findDocument(dirName1).getBounds(); 110 111 bots.main.switchToGridMode(); 112 // right side of dir1 area 113 bots.directory.rightClickDocument(new Point(dirListBounds.right - 1, dirBounds.centerY())); 114 bots.menu.assertPresentMenuItems(menuItems); 115 } 116 } 117