• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.settings.applications;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.support.test.filters.SmallTest;
21 import android.support.test.uiautomator.UiDevice;
22 import android.support.test.uiautomator.UiObject;
23 import android.support.test.uiautomator.UiObjectNotFoundException;
24 import android.support.test.uiautomator.UiScrollable;
25 import android.support.test.uiautomator.UiSelector;
26 import android.test.InstrumentationTestCase;
27 import android.widget.TextView;
28 
29 import com.android.settings.R;
30 
31 import org.junit.Test;
32 
33 /**
34  * Test for Special App Access preferences.
35  */
36 @SmallTest
37 public class SpecialAppAccessSettingsTest extends InstrumentationTestCase {
38 
39     private UiDevice mDevice;
40     private Context mTargetContext;
41     private String mTargetPackage;
42 
43     @Override
setUp()44     protected void setUp() throws Exception {
45         super.setUp();
46         mDevice = UiDevice.getInstance(getInstrumentation());
47         mTargetContext = getInstrumentation().getTargetContext();
48         mTargetPackage = mTargetContext.getPackageName();
49     }
50 
51     @Test
testSelectPictureInPicture_shouldNotCrash()52     public void testSelectPictureInPicture_shouldNotCrash() throws Exception {
53         launchSpecialApps();
54         final String titlePictureInPictureApp =
55                 mTargetContext.getResources().getString(R.string.picture_in_picture_title);
56 
57         // select Picture-in-Picture
58         mDevice.findObject(new UiSelector().text(titlePictureInPictureApp)).click();
59 
60         // Picture-in-picture settings page should launch and no crash
61         final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId(
62             "com.android.settings:id/action_bar"));
63         final UiObject title = actionBar.getChild(
64             new UiSelector().className(TextView.class.getName()));
65         assertEquals(titlePictureInPictureApp, title.getText());
66     }
67 
launchSpecialApps()68     private void launchSpecialApps() throws Exception  {
69         final Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
70             .addCategory(Intent.CATEGORY_LAUNCHER)
71             .setPackage(mTargetPackage)
72             .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
73         getInstrumentation().getContext().startActivity(settingsIntent);
74         final String titleApps = mTargetContext.getResources().getString(
75             R.string.app_and_notification_dashboard_title);
76         mDevice.findObject(new UiSelector().text(titleApps)).click();
77         final String titleAdvance = mTargetContext.getResources().getString(
78                 R.string.advanced_section_header);
79         mDevice.findObject(new UiSelector().text(titleAdvance)).click();
80         final String titleSpecialApps = mTargetContext.getResources().getString(
81             R.string.special_access);
82 
83         try {
84             // scollbar may or may not be present, depending on how many recents app are there. If
85             // the page is scrollable, scroll to the bottom to show the special app access settings.
86             final UiScrollable settings = new UiScrollable(
87                     new UiSelector().packageName(mTargetContext.getPackageName()).scrollable(true));
88             settings.scrollTextIntoView(titleSpecialApps);
89         } catch (UiObjectNotFoundException e) {
90             // ignore
91         }
92 
93         mDevice.findObject(new UiSelector().text(titleSpecialApps)).click();
94     }
95 
96 }
97