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