blob: af6a3c554c06027905b49f73176e555ffe1e1dbc [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
Tony Huangee512b32019-01-25 12:07:00 +080019import static org.junit.Assert.assertFalse;
20import static org.junit.Assert.assertTrue;
21
Tony Huang7a7e7df2018-11-06 17:16:47 +080022import android.content.Intent;
23import android.provider.DocumentsContract;
24
25import androidx.test.filters.LargeTest;
26
Tony Huangee512b32019-01-25 12:07:00 +080027import com.android.documentsui.base.Shared;
Tony Huang7a7e7df2018-11-06 17:16:47 +080028import com.android.documentsui.bots.UiBot;
29import com.android.documentsui.picker.PickActivity;
30
31@LargeTest
32public class PickerPreviewTextUiTest extends ActivityTest<PickActivity>{
33
Tony Huangee512b32019-01-25 12:07:00 +080034 private boolean mHasQuickViewer;
35
Tony Huang7a7e7df2018-11-06 17:16:47 +080036 public PickerPreviewTextUiTest() {
37 super(PickActivity.class);
38 }
39
40 @Override
41 public void setUp() throws Exception {
42 super.setUp();
43 initTestFiles();
Tony Huangee512b32019-01-25 12:07:00 +080044
45 mHasQuickViewer = Shared.hasQuickViewer(context);
Tony Huang7a7e7df2018-11-06 17:16:47 +080046 }
47
48 @Override
49 protected void launchActivity() {
50 final Intent intent = context.getPackageManager().getLaunchIntentForPackage(
Bill Lin34329192019-03-05 22:22:20 +080051 UiBot.targetPackageName);
Tony Huang7a7e7df2018-11-06 17:16:47 +080052 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 Huangee512b32019-01-25 12:07:00 +080063 if (!mHasQuickViewer) {
64 return;
65 }
66
Tony Huang7a7e7df2018-11-06 17:16:47 +080067 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 Huangee512b32019-01-25 12:07:00 +080073 if (!mHasQuickViewer) {
74 return;
75 }
76
Tony Huang7a7e7df2018-11-06 17:16:47 +080077 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 Huangee512b32019-01-25 12:07:00 +080083 if (!mHasQuickViewer) {
84 return;
85 }
86
Tony Huang7a7e7df2018-11-06 17:16:47 +080087 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 Huangee512b32019-01-25 12:07:00 +080093 if (!mHasQuickViewer) {
94 return;
95 }
96
Tony Huang7a7e7df2018-11-06 17:16:47 +080097 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 Huangee512b32019-01-25 12:07:00 +0800103 if (!mHasQuickViewer) {
104 return;
105 }
106
Tony Huang7a7e7df2018-11-06 17:16:47 +0800107 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 Huangee512b32019-01-25 12:07:00 +0800113 if (!mHasQuickViewer) {
114 return;
115 }
116
Tony Huang7a7e7df2018-11-06 17:16:47 +0800117 bots.main.switchToListMode();
118 assertTrue(bots.directory.findDocument(fileName1).isEnabled());
119 assertTrue(bots.directory.hasDocumentPreview(fileName1));
120 }
121}