Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui; |
| 18 | |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 19 | import static com.android.documentsui.StubProvider.ROOT_0_ID; |
| 20 | |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
| 22 | import android.os.RemoteException; |
| 23 | import android.provider.DocumentsContract; |
| 24 | import android.support.test.uiautomator.By; |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 25 | import android.support.test.uiautomator.Until; |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 26 | import android.test.suitebuilder.annotation.LargeTest; |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 27 | |
| 28 | @LargeTest |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 29 | public class DownloadsActivityUiTest extends ActivityTest<DownloadsActivity> { |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 30 | |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 31 | public DownloadsActivityUiTest() { |
| 32 | super(DownloadsActivity.class); |
| 33 | } |
| 34 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 35 | @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 McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 39 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 40 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); |
Tomasz Mikolajewski | 2458689 | 2016-02-04 13:48:21 +0900 | [diff] [blame] | 41 | setActivityIntent(intent); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 42 | getActivity(); // Launch the activity. |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | @Override |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 46 | 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 McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | public void testWindowTitle() throws Exception { |
| 53 | initTestFiles(); |
| 54 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 55 | bots.main.assertWindowTitle(ROOT_0_ID); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | public void testFilesListed() throws Exception { |
| 59 | initTestFiles(); |
| 60 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 61 | bots.directory.assertDocumentsPresent("file0.log", "file1.png", "file2.csv"); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | public void testFilesList_LiveUpdate() throws Exception { |
| 65 | initTestFiles(); |
| 66 | |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 67 | mDocsHelper.createDocument(rootDir0, "yummers/sandwich", "Ham & Cheese.sandwich"); |
| 68 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 69 | bots.directory.waitForDocument("Ham & Cheese.sandwich"); |
| 70 | bots.directory.assertDocumentsPresent( |
| 71 | "file0.log", "file1.png", "file2.csv", "Ham & Cheese.sandwich"); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | public void testDeleteDocument() throws Exception { |
| 75 | initTestFiles(); |
| 76 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 77 | bots.directory.clickDocument("file1.png"); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 78 | device.waitForIdle(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 79 | bots.main.menuDelete().click(); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 80 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 81 | bots.directory.waitForDeleteSnackbar(); |
| 82 | bots.directory.assertDocumentsAbsent("file1.png"); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 83 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 84 | bots.directory.waitForDeleteSnackbarGone(); |
| 85 | bots.directory.assertDocumentsAbsent("file1.png"); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | public void testSupportsShare() throws Exception { |
| 89 | initTestFiles(); |
| 90 | |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 91 | bots.directory.clickDocument("file1.png"); |
Tomasz Mikolajewski | c7b8322 | 2016-02-04 17:46:35 +0900 | [diff] [blame] | 92 | device.waitForIdle(); |
Steve McKay | b9a20d1 | 2016-02-19 12:57:05 -0800 | [diff] [blame] | 93 | assertNotNull(bots.main.menuShare()); |
Steve McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 94 | } |
Steve McKay | 9146ac6 | 2016-02-09 12:40:07 -0800 | [diff] [blame] | 95 | |
| 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 McKay | dbdaa49 | 2015-12-02 11:20:54 -0800 | [diff] [blame] | 102 | } |