blob: 44f417dbdcbdb3d8c95f9e808adc8aac790096b6 [file] [log] [blame]
Steve McKay85ec0d62016-06-24 15:05:08 -07001/*
2 * Copyright (C) 2015 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;
20import static com.android.documentsui.StubProvider.ROOT_1_ID;
21
22import android.net.Uri;
23import android.os.RemoteException;
Steve McKay502c3b12016-06-29 16:01:39 -070024import android.support.test.filters.Suppress;
Steve McKay85ec0d62016-06-24 15:05:08 -070025import android.test.suitebuilder.annotation.LargeTest;
26import android.view.KeyEvent;
27
28@LargeTest
29public class FileManagementUiTest extends ActivityTest<FilesActivity> {
30
31 public FileManagementUiTest() {
32 super(FilesActivity.class);
33 }
34
35 @Override
36 public void setUp() throws Exception {
37 super.setUp();
38 initTestFiles();
39 }
40
41 @Override
42 public void initTestFiles() throws RemoteException {
43 Uri uri = mDocsHelper.createFolder(rootDir0, dirName1);
44 mDocsHelper.createFolder(uri, childDir1);
45
46 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");
47 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png");
48 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv");
49
50 mDocsHelper.createDocument(rootDir1, "text/plain", "anotherFile0.log");
51 mDocsHelper.createDocument(rootDir1, "text/plain", "poodles.text");
52 }
53
Steve McKay502c3b12016-06-29 16:01:39 -070054 @Suppress
Steve McKay85ec0d62016-06-24 15:05:08 -070055 public void testCreateDirectory() throws Exception {
56 bots.main.openOverflowMenu();
57 device.waitForIdle();
58
59 bots.main.clickToolbarOverflowItem("New folder");
60 device.waitForIdle();
61
62 bots.main.setDialogText("Kung Fu Panda");
63 device.waitForIdle();
64
65 bots.keyboard.pressEnter();
66
67 bots.directory.waitForDocument("Kung Fu Panda");
68 }
69
Steve McKay85ec0d62016-06-24 15:05:08 -070070 public void testKeyboard_CutDocument() throws Exception {
71 bots.directory.clickDocument("file1.png");
72 device.waitForIdle();
73 bots.keyboard.pressKey(KeyEvent.KEYCODE_X, KeyEvent.META_CTRL_ON);
74
75 device.waitForIdle();
76
77 bots.roots.openRoot(ROOT_1_ID);
78 bots.keyboard.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
79
80 bots.directory.waitForDocument("file1.png");
81 bots.directory.assertDocumentsPresent("file1.png");
82
83 bots.roots.openRoot(ROOT_0_ID);
84 bots.directory.assertDocumentsAbsent("file1.png");
85 }
86
87 public void testKeyboard_CopyDocument() throws Exception {
88 bots.directory.clickDocument("file1.png");
89 device.waitForIdle();
90 bots.keyboard.pressKey(KeyEvent.KEYCODE_C, KeyEvent.META_CTRL_ON);
91
92 device.waitForIdle();
93
94 bots.roots.openRoot(ROOT_1_ID);
95 bots.keyboard.pressKey(KeyEvent.KEYCODE_V, KeyEvent.META_CTRL_ON);
96
97 bots.directory.waitForDocument("file1.png");
98
99 bots.roots.openRoot(ROOT_0_ID);
100 bots.directory.waitForDocument("file1.png");
101 }
102
Ben Linfe5cd2e2016-07-20 18:24:29 -0700103 public void testDeleteDocument_Cancel_ThenOK() throws Exception {
Steve McKay85ec0d62016-06-24 15:05:08 -0700104 bots.directory.clickDocument("file1.png");
105 device.waitForIdle();
106 bots.main.clickToolbarItem(R.id.menu_delete);
107
108 bots.main.clickDialogCancelButton();
109
110 bots.directory.waitForDocument("file1.png");
Ben Linfe5cd2e2016-07-20 18:24:29 -0700111
112 device.waitForIdle();
113 bots.main.clickToolbarItem(R.id.menu_delete);
114
115 bots.main.clickDialogOkButton();
116 device.waitForIdle();
117
118 bots.directory.assertDocumentsAbsent("file1.png");
Steve McKay85ec0d62016-06-24 15:05:08 -0700119 }
120}