blob: f5ac051469890e2b1dd2747f91f3e06387e5d9f2 [file] [log] [blame]
Tony Huang7a7e7df2018-11-06 17:16:47 +08001/*
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
17package com.android.documentsui;
18
19import android.content.Intent;
20import android.provider.DocumentsContract;
21
22import androidx.test.filters.LargeTest;
23
Tony Huangee512b32019-01-25 12:07:00 +080024import com.android.documentsui.base.Shared;
Tony Huang7a7e7df2018-11-06 17:16:47 +080025import com.android.documentsui.picker.PickActivity;
26
27@LargeTest
28public class PickerPreviewTextUiTest extends ActivityTest<PickActivity>{
29
Tony Huangee512b32019-01-25 12:07:00 +080030 private boolean mHasQuickViewer;
31
Tony Huang7a7e7df2018-11-06 17:16:47 +080032 public PickerPreviewTextUiTest() {
33 super(PickActivity.class);
34 }
35
36 @Override
37 public void setUp() throws Exception {
38 super.setUp();
39 initTestFiles();
Tony Huangee512b32019-01-25 12:07:00 +080040
41 mHasQuickViewer = Shared.hasQuickViewer(context);
Tony Huang7a7e7df2018-11-06 17:16:47 +080042 }
43
44 @Override
45 protected void launchActivity() {
Tony Huang8430f5d2019-10-30 14:50:41 +080046 final Intent intent = new Intent(context, PickActivity.class);
Tony Huang7a7e7df2018-11-06 17:16:47 +080047 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 Huangee512b32019-01-25 12:07:00 +080058 if (!mHasQuickViewer) {
59 return;
60 }
61
Tony Huang7a7e7df2018-11-06 17:16:47 +080062 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 Huangee512b32019-01-25 12:07:00 +080068 if (!mHasQuickViewer) {
69 return;
70 }
71
Tony Huang7a7e7df2018-11-06 17:16:47 +080072 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 Huangee512b32019-01-25 12:07:00 +080078 if (!mHasQuickViewer) {
79 return;
80 }
81
Tony Huang7a7e7df2018-11-06 17:16:47 +080082 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 Huangee512b32019-01-25 12:07:00 +080088 if (!mHasQuickViewer) {
89 return;
90 }
91
Tony Huang7a7e7df2018-11-06 17:16:47 +080092 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 Huangee512b32019-01-25 12:07:00 +080098 if (!mHasQuickViewer) {
99 return;
100 }
101
Tony Huang7a7e7df2018-11-06 17:16:47 +0800102 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 Huangee512b32019-01-25 12:07:00 +0800108 if (!mHasQuickViewer) {
109 return;
110 }
111
Tony Huang7a7e7df2018-11-06 17:16:47 +0800112 bots.main.switchToListMode();
113 assertTrue(bots.directory.findDocument(fileName1).isEnabled());
114 assertTrue(bots.directory.hasDocumentPreview(fileName1));
115 }
116}