Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 19 | import static org.junit.Assert.assertFalse; |
| 20 | import static org.junit.Assert.assertTrue; |
| 21 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.provider.DocumentsContract; |
| 24 | |
| 25 | import androidx.test.filters.LargeTest; |
| 26 | |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 27 | import com.android.documentsui.base.Shared; |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 28 | import com.android.documentsui.bots.UiBot; |
| 29 | import com.android.documentsui.picker.PickActivity; |
| 30 | |
| 31 | @LargeTest |
| 32 | public class PickerPreviewTextUiTest extends ActivityTest<PickActivity>{ |
| 33 | |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 34 | private boolean mHasQuickViewer; |
| 35 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 36 | public PickerPreviewTextUiTest() { |
| 37 | super(PickActivity.class); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void setUp() throws Exception { |
| 42 | super.setUp(); |
| 43 | initTestFiles(); |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 44 | |
| 45 | mHasQuickViewer = Shared.hasQuickViewer(context); |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
| 49 | protected void launchActivity() { |
| 50 | final Intent intent = context.getPackageManager().getLaunchIntentForPackage( |
Bill Lin | 3432919 | 2019-03-05 22:22:20 +0800 | [diff] [blame] | 51 | UiBot.targetPackageName); |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 52 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 53 | intent.setAction(Intent.ACTION_GET_CONTENT); |
| 54 | if (getInitialRoot() != null) { |
| 55 | intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, getInitialRoot().getUri()); |
| 56 | } |
| 57 | intent.setType("text/*"); |
| 58 | setActivityIntent(intent); |
| 59 | getActivity(); // Launch the activity. |
| 60 | } |
| 61 | |
| 62 | public void testPreviewInvisible_disabled_gridMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 63 | if (!mHasQuickViewer) { |
| 64 | return; |
| 65 | } |
| 66 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 67 | bots.main.switchToGridMode(); |
| 68 | assertFalse(bots.directory.findDocument(fileName2).isEnabled()); |
| 69 | assertFalse(bots.directory.hasDocumentPreview(fileName2)); |
| 70 | } |
| 71 | |
| 72 | public void testPreviewInvisible_disabled_listMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 73 | if (!mHasQuickViewer) { |
| 74 | return; |
| 75 | } |
| 76 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 77 | bots.main.switchToListMode(); |
| 78 | assertFalse(bots.directory.findDocument(fileName2).isEnabled()); |
| 79 | assertFalse(bots.directory.hasDocumentPreview(fileName2)); |
| 80 | } |
| 81 | |
| 82 | public void testPreviewInvisible_directory_gridMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 83 | if (!mHasQuickViewer) { |
| 84 | return; |
| 85 | } |
| 86 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 87 | bots.main.switchToGridMode(); |
| 88 | assertTrue(bots.directory.findDocument(dirName1).isEnabled()); |
| 89 | assertFalse(bots.directory.hasDocumentPreview(dirName1)); |
| 90 | } |
| 91 | |
| 92 | public void testPreviewInvisible_directory_listMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 93 | if (!mHasQuickViewer) { |
| 94 | return; |
| 95 | } |
| 96 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 97 | bots.main.switchToListMode(); |
| 98 | assertTrue(bots.directory.findDocument(dirName1).isEnabled()); |
| 99 | assertFalse(bots.directory.hasDocumentPreview(dirName1)); |
| 100 | } |
| 101 | |
| 102 | public void testPreviewVisible_enabled_gridMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 103 | if (!mHasQuickViewer) { |
| 104 | return; |
| 105 | } |
| 106 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 107 | bots.main.switchToGridMode(); |
| 108 | assertTrue(bots.directory.findDocument(fileName1).isEnabled()); |
| 109 | assertTrue(bots.directory.hasDocumentPreview(fileName1)); |
| 110 | } |
| 111 | |
| 112 | public void testPreviewVisible_enabled_listMode() throws Exception { |
Tony Huang | ee512b3 | 2019-01-25 12:07:00 +0800 | [diff] [blame] | 113 | if (!mHasQuickViewer) { |
| 114 | return; |
| 115 | } |
| 116 | |
Tony Huang | 7a7e7df | 2018-11-06 17:16:47 +0800 | [diff] [blame] | 117 | bots.main.switchToListMode(); |
| 118 | assertTrue(bots.directory.findDocument(fileName1).isEnabled()); |
| 119 | assertTrue(bots.directory.hasDocumentPreview(fileName1)); |
| 120 | } |
| 121 | } |