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.UiSelector; 24 import android.test.InstrumentationTestCase; 25 import android.widget.TextView; 26 27 import com.android.settings.R; 28 29 import org.junit.Test; 30 31 /** 32 * Test for Advanced App preferences. 33 */ 34 @SmallTest 35 public class AdvancedAppSettingsTest extends InstrumentationTestCase { 36 37 private UiDevice mDevice; 38 private Context mTargetContext; 39 private String mTargetPackage; 40 41 @Override 42 protected void setUp() throws Exception { 43 super.setUp(); 44 mDevice = UiDevice.getInstance(getInstrumentation()); 45 mTargetContext = getInstrumentation().getTargetContext(); 46 mTargetPackage = mTargetContext.getPackageName(); 47 } 48 49 @Test 50 public void testSelectDefaultHome_shouldLaunchHomePicker() throws Exception { 51 launchDefaultApps(); 52 final String titleHomeApp = mTargetContext.getResources().getString(R.string.home_app); 53 mDevice.findObject(new UiSelector().text(titleHomeApp)).click(); 54 final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId( 55 "com.android.settings:id/action_bar")); 56 final UiObject title = actionBar.getChild( 57 new UiSelector().className(TextView.class.getName())); 58 assertEquals(titleHomeApp, title.getText()); 59 } 60 61 private void launchDefaultApps() throws Exception { 62 final Intent settingsIntent = new Intent(Intent.ACTION_MAIN) 63 .addCategory(Intent.CATEGORY_LAUNCHER) 64 .setPackage(mTargetPackage) 65 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 66 getInstrumentation().getContext().startActivity(settingsIntent); 67 final String titleApps = mTargetContext.getResources().getString( 68 R.string.app_and_notification_dashboard_title); 69 mDevice.findObject(new UiSelector().text(titleApps)).click(); 70 final String titleDefaultApps = mTargetContext.getResources().getString( 71 R.string.app_default_dashboard_title); 72 mDevice.findObject(new UiSelector().text(titleDefaultApps)).click(); 73 } 74 75 } 76