1 /* 2 * Copyright (C) 2015 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.pm.ApplicationInfo; 20 import android.content.pm.PackageManager; 21 import android.text.TextUtils; 22 23 import androidx.test.InstrumentationRegistry; 24 import androidx.test.filters.LargeTest; 25 26 import com.android.documentsui.files.FilesActivity; 27 import com.android.documentsui.filters.HugeLongTest; 28 29 @LargeTest 30 public class DirectoryMessagesUiTest extends ActivityTest<FilesActivity> { 31 DirectoryMessagesUiTest()32 public DirectoryMessagesUiTest() { 33 super(FilesActivity.class); 34 } 35 36 @Override setUp()37 public void setUp() throws Exception { 38 super.setUp(); 39 bots.roots.openRoot("Demo Root"); 40 bots.main.switchToListMode(); 41 } 42 testAuthenticationMessage_visible()43 public void testAuthenticationMessage_visible() throws Exception { 44 // If feature is disabled, this test is a no-op. 45 if (!features.isRemoteActionsEnabled()) { 46 return; 47 } 48 bots.directory.openDocument(DemoProvider.DIR_AUTH); 49 bots.directory.assertHasMessage( 50 "To view this directory, sign in to " + getTestAppName()); 51 bots.directory.assertHasMessageButtonText("SIGN IN"); 52 } 53 54 @HugeLongTest testInfoMessage_visible()55 public void testInfoMessage_visible() throws Exception { 56 bots.directory.openDocument(DemoProvider.DIR_INFO); 57 bots.directory.assertHasMessage(DemoProvider.MSG_INFO); 58 bots.directory.assertHasMessageButtonText("OK"); 59 } 60 61 @HugeLongTest testInfoMessage_dismissable()62 public void testInfoMessage_dismissable() throws Exception { 63 bots.directory.openDocument(DemoProvider.DIR_INFO); 64 bots.directory.assertHasMessage(true); 65 bots.directory.clickMessageButton(); 66 bots.directory.assertHasMessage(false); 67 } 68 69 @HugeLongTest testErrorMessage_visible()70 public void testErrorMessage_visible() throws Exception { 71 bots.directory.openDocument(DemoProvider.DIR_ERROR); 72 bots.directory.assertHasMessage(DemoProvider.MSG_ERROR); 73 bots.directory.assertHasMessageButtonText("OK"); 74 } 75 76 @HugeLongTest testErrorMessage_dismissable()77 public void testErrorMessage_dismissable() throws Exception { 78 bots.directory.openDocument(DemoProvider.DIR_ERROR); 79 bots.directory.assertHasMessage(true); 80 bots.directory.clickMessageButton(); 81 bots.directory.assertHasMessage(false); 82 } 83 84 @HugeLongTest testErrorMessage_supercedesInfoMessage()85 public void testErrorMessage_supercedesInfoMessage() throws Exception { 86 // When both error and info are returned in Directory, only show the error. 87 bots.directory.openDocument(DemoProvider.DIR_ERROR_AND_INFO); 88 bots.directory.assertHasMessage(DemoProvider.MSG_ERROR_AND_INFO); 89 } 90 getTestAppName()91 private String getTestAppName() { 92 final ApplicationInfo ai = 93 InstrumentationRegistry.getInstrumentation().getContext().getApplicationInfo(); 94 final PackageManager pm = context.getPackageManager(); 95 CharSequence result = pm.getApplicationLabel(ai); 96 return TextUtils.isEmpty(result) ? "" : result.toString(); 97 } 98 } 99