blob: c51f9275601224e36fd64df035ed47173a830e35 [file] [log] [blame]
Steve McKaydbdaa492015-12-02 11:20:54 -08001/*
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
Steve McKaydbdaa492015-12-02 11:20:54 -080019import static com.android.documentsui.StubProvider.ROOT_0_ID;
20
Steve McKaydbdaa492015-12-02 11:20:54 -080021import android.content.Intent;
22import android.os.RemoteException;
23import android.provider.DocumentsContract;
24import android.support.test.uiautomator.By;
Steve McKaydbdaa492015-12-02 11:20:54 -080025import android.support.test.uiautomator.Until;
Steve McKaydbdaa492015-12-02 11:20:54 -080026import android.test.suitebuilder.annotation.LargeTest;
Steve McKaydbdaa492015-12-02 11:20:54 -080027
28@LargeTest
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090029public class DownloadsActivityUiTest extends ActivityTest<DownloadsActivity> {
Steve McKaydbdaa492015-12-02 11:20:54 -080030
Tomasz Mikolajewski24586892016-02-04 13:48:21 +090031 public DownloadsActivityUiTest() {
32 super(DownloadsActivity.class);
33 }
34
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090035 @Override
36 void launchActivity() {
37 final Intent intent = new Intent(DocumentsContract.ACTION_MANAGE_ROOT);
38 intent.setDataAndType(rootDir0.getUri(), DocumentsContract.Root.MIME_TYPE_ITEM);
Steve McKaydbdaa492015-12-02 11:20:54 -080039 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
40 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
Tomasz Mikolajewski24586892016-02-04 13:48:21 +090041 setActivityIntent(intent);
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090042 getActivity(); // Launch the activity.
Steve McKaydbdaa492015-12-02 11:20:54 -080043 }
44
45 @Override
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090046 void initTestFiles() throws RemoteException {
47 mDocsHelper.createDocument(rootDir0, "text/plain", "file0.log");
48 mDocsHelper.createDocument(rootDir0, "image/png", "file1.png");
49 mDocsHelper.createDocument(rootDir0, "text/csv", "file2.csv");
Steve McKaydbdaa492015-12-02 11:20:54 -080050 }
51
52 public void testWindowTitle() throws Exception {
53 initTestFiles();
54
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090055 bot.assertWindowTitle(ROOT_0_ID);
Steve McKaydbdaa492015-12-02 11:20:54 -080056 }
57
58 public void testFilesListed() throws Exception {
59 initTestFiles();
60
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090061 bot.assertHasDocuments("file0.log", "file1.png", "file2.csv");
Steve McKaydbdaa492015-12-02 11:20:54 -080062 }
63
64 public void testFilesList_LiveUpdate() throws Exception {
65 initTestFiles();
66
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090067 mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich");
68
Tomasz Mikolajewski65d9a512016-02-08 15:36:04 +090069 bot.waitForDocument("Ham & Cheese.sandwich");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090070 bot.assertHasDocuments("file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich");
Steve McKaydbdaa492015-12-02 11:20:54 -080071 }
72
73 public void testDeleteDocument() throws Exception {
74 initTestFiles();
75
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090076 bot.clickDocument("file1.png");
77 device.waitForIdle();
78 bot.menuDelete().click();
Steve McKaydbdaa492015-12-02 11:20:54 -080079
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090080 bot.waitForDeleteSnackbar();
81 assertFalse(bot.hasDocuments("file1.png"));
Steve McKaydbdaa492015-12-02 11:20:54 -080082
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090083 bot.waitForDeleteSnackbarGone();
84 assertFalse(bot.hasDocuments("file1.png"));
Steve McKaydbdaa492015-12-02 11:20:54 -080085 }
86
87 public void testSupportsShare() throws Exception {
88 initTestFiles();
89
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090090 bot.clickDocument("file1.png");
91 device.waitForIdle();
92 assertNotNull(bot.menuShare());
Steve McKaydbdaa492015-12-02 11:20:54 -080093 }
Steve McKay9146ac62016-02-09 12:40:07 -080094
95 public void testClosesOnBack() throws Exception {
96 DownloadsActivity activity = getActivity();
97 device.pressBack();
98 device.wait(Until.gone(By.text(ROOT_0_ID)), TIMEOUT); // wait for the window to go away
99 assertTrue(activity.isDestroyed());
100 }
Steve McKaydbdaa492015-12-02 11:20:54 -0800101}