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 
24 import com.android.documentsui.picker.PickActivity;
25 
26 @LargeTest
27 public class PickerPreviewTextUiTest extends ActivityTest<PickActivity>{
28 
PickerPreviewTextUiTest()29     public PickerPreviewTextUiTest() {
30         super(PickActivity.class);
31     }
32 
33     @Override
setUp()34     public void setUp() throws Exception {
35         super.setUp();
36         initTestFiles();
37     }
38 
39     @Override
launchActivity()40     protected void launchActivity() {
41         final Intent intent = new Intent(context, PickActivity.class);
42         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
43         intent.setAction(Intent.ACTION_GET_CONTENT);
44         if (getInitialRoot() != null) {
45             intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, getInitialRoot().getUri());
46         }
47         intent.setType("text/*");
48         setActivityIntent(intent);
49         getActivity();  // Launch the activity.
50     }
51 
testPreviewInvisible_directory_listMode()52     public void testPreviewInvisible_directory_listMode() throws Exception {
53         bots.main.switchToListMode();
54         assertTrue(bots.directory.findDocument(dirName1).isEnabled());
55         assertFalse(bots.directory.hasDocumentPreview(dirName1));
56     }
57 
testPreviewVisible_enabled_gridMode()58     public void testPreviewVisible_enabled_gridMode() throws Exception {
59         bots.main.switchToGridMode();
60         assertTrue(bots.directory.findDocument(fileName1).isEnabled());
61         assertTrue(bots.directory.hasDocumentPreview(fileName1));
62     }
63 
testPreviewVisible_enabled_listMode()64     public void testPreviewVisible_enabled_listMode() throws Exception {
65         bots.main.switchToListMode();
66         assertTrue(bots.directory.findDocument(fileName1).isEnabled());
67         assertTrue(bots.directory.hasDocumentPreview(fileName1));
68     }
69 }
70