blob: 459e9b092a004ca31c3ebf149104547c950ba904 [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 PickerPreviewAllTypeUiTest 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 PickerPreviewAllTypeUiTest() {
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("*/*");
53 setActivityIntent(intent);
54 getActivity(); // Launch the activity.
55 }
56
Tony Huangee512b32019-01-25 12:07:00 +080057 public void testPreviewInvisible_noQuickViewer_gridMode() throws Exception {
58 if (mHasQuickViewer) {
59 return;
60 }
61
62 bots.main.switchToGridMode();
63 assertTrue(bots.directory.findDocument(fileName1).isEnabled());
64 assertFalse(bots.directory.hasDocumentPreview(fileName1));
65 }
66
67 public void testPreviewInvisible_noQuickViewer_listMode() throws Exception {
68 if (mHasQuickViewer) {
69 return;
70 }
71
72 bots.main.switchToListMode();
73 assertTrue(bots.directory.findDocument(fileName1).isEnabled());
74 assertFalse(bots.directory.hasDocumentPreview(fileName1));
75 }
76
Tony Huang7a7e7df2018-11-06 17:16:47 +080077 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_allType_girdMode() 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 assertTrue(bots.directory.findDocument(fileName2).isEnabled());
106 assertTrue(bots.directory.hasDocumentPreview(fileName2));
107 }
108
109 public void testPreviewVisible_allType_listMode() throws Exception {
Tony Huangee512b32019-01-25 12:07:00 +0800110 if (!mHasQuickViewer) {
111 return;
112 }
113
Tony Huang7a7e7df2018-11-06 17:16:47 +0800114 bots.main.switchToListMode();
115 assertTrue(bots.directory.findDocument(fileName1).isEnabled());
116 assertTrue(bots.directory.hasDocumentPreview(fileName1));
117 assertTrue(bots.directory.findDocument(fileName2).isEnabled());
118 assertTrue(bots.directory.hasDocumentPreview(fileName2));
119 }
120}