From 7a76e9493f85265ddaa5f9b6e0cbe85296892b01 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Mon, 30 Jan 2017 17:11:21 -0800 Subject: [PATCH] Specify the fragment to launch when default home is clicked. Add the fragment attribute to the default home preference so that it will launch the DefaultHomePicker when it is clicked. Change-Id: I6a06dc2fab6a4a5b8bae4e9ec0144e18d2934666 Fixes: 34795157 Test: make SettingsTests and run test --- res/xml/app_default_settings.xml | 1 + .../applications/AdvancedAppSettingsTest.java | 75 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java diff --git a/res/xml/app_default_settings.xml b/res/xml/app_default_settings.xml index 27200e7dba7..9842402e629 100644 --- a/res/xml/app_default_settings.xml +++ b/res/xml/app_default_settings.xml @@ -46,6 +46,7 @@ android:key="default_home" android:title="@string/home_app" android:summary="@string/no_default_home" + android:fragment="com.android.settings.applications.defaultapps.DefaultHomePicker" settings:keywords="@string/keywords_home" android:order="-17"/> diff --git a/tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java b/tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java new file mode 100644 index 00000000000..1831b592e8c --- /dev/null +++ b/tests/app/src/com/android/settings/applications/AdvancedAppSettingsTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.settings.applications; + +import android.content.Context; +import android.content.Intent; +import android.support.test.filters.SmallTest; +import android.support.test.uiautomator.UiDevice; +import android.support.test.uiautomator.UiObject; +import android.support.test.uiautomator.UiSelector; +import android.test.InstrumentationTestCase; +import android.widget.TextView; + +import com.android.settings.R; + +import org.junit.Test; + +/** + * Test for Advanced App preferences. + */ +@SmallTest +public class AdvancedAppSettingsTest extends InstrumentationTestCase { + + private UiDevice mDevice; + private Context mTargetContext; + private String mTargetPackage; + + @Override + protected void setUp() throws Exception { + super.setUp(); + mDevice = UiDevice.getInstance(getInstrumentation()); + mTargetContext = getInstrumentation().getTargetContext(); + mTargetPackage = mTargetContext.getPackageName(); + } + + @Test + public void testSelectDefaultHome_shouldLaunchHomePicker() throws Exception { + launchDefaultApps(); + final String titleHomeApp = mTargetContext.getResources().getString(R.string.home_app); + mDevice.findObject(new UiSelector().text(titleHomeApp)).click(); + final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId( + "com.android.settings:id/action_bar")); + final UiObject title = actionBar.getChild( + new UiSelector().className(TextView.class.getName())); + assertEquals(titleHomeApp, title.getText()); + } + + private void launchDefaultApps() throws Exception { + final Intent settingsIntent = new Intent(Intent.ACTION_MAIN) + .addCategory(Intent.CATEGORY_LAUNCHER) + .setPackage(mTargetPackage) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getInstrumentation().getContext().startActivity(settingsIntent); + final String titleApps = mTargetContext.getResources().getString( + R.string.app_and_notification_dashboard_title); + mDevice.findObject(new UiSelector().text(titleApps)).click(); + final String titleDefaultApps = mTargetContext.getResources().getString( + R.string.app_default_dashboard_title); + mDevice.findObject(new UiSelector().text(titleDefaultApps)).click(); + } + +}