blob: 79d7887198b59e857b55c106a8e575de08e6b4b0 [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
Steve McKayb9a20d12016-02-19 12:57:05 -080055 bots.main.assertWindowTitle(ROOT_0_ID);
Steve McKaydbdaa492015-12-02 11:20:54 -080056 }
57
58 public void testFilesListed() throws Exception {
59 initTestFiles();
60
Steve McKayb9a20d12016-02-19 12:57:05 -080061 bots.directory.assertDocumentsPresent("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
Steve McKayb9a20d12016-02-19 12:57:05 -080069 bots.directory.waitForDocument("Ham & Cheese.sandwich");
70 bots.directory.assertDocumentsPresent(
71 "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich");
Steve McKaydbdaa492015-12-02 11:20:54 -080072 }
73
74 public void testDeleteDocument() throws Exception {
75 initTestFiles();
76
Steve McKayb9a20d12016-02-19 12:57:05 -080077 bots.directory.clickDocument("file1.png");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090078 device.waitForIdle();
Steve McKayb9a20d12016-02-19 12:57:05 -080079 bots.main.menuDelete().click();
Steve McKaydbdaa492015-12-02 11:20:54 -080080
Steve McKayb9a20d12016-02-19 12:57:05 -080081 bots.directory.waitForDeleteSnackbar();
82 bots.directory.assertDocumentsAbsent("file1.png");
Steve McKaydbdaa492015-12-02 11:20:54 -080083
Steve McKayb9a20d12016-02-19 12:57:05 -080084 bots.directory.waitForDeleteSnackbarGone();
85 bots.directory.assertDocumentsAbsent("file1.png");
Steve McKaydbdaa492015-12-02 11:20:54 -080086 }
87
88 public void testSupportsShare() throws Exception {
89 initTestFiles();
90
Steve McKayb9a20d12016-02-19 12:57:05 -080091 bots.directory.clickDocument("file1.png");
Tomasz Mikolajewskic7b83222016-02-04 17:46:35 +090092 device.waitForIdle();
Steve McKayb9a20d12016-02-19 12:57:05 -080093 assertNotNull(bots.main.menuShare());
Steve McKaydbdaa492015-12-02 11:20:54 -080094 }
Steve McKay9146ac62016-02-09 12:40:07 -080095
96 public void testClosesOnBack() throws Exception {
97 DownloadsActivity activity = getActivity();
98 device.pressBack();
99 device.wait(Until.gone(By.text(ROOT_0_ID)), TIMEOUT); // wait for the window to go away
100 assertTrue(activity.isDestroyed());
101 }
Steve McKaydbdaa492015-12-02 11:20:54 -0800102}