1 /* 2 * Copyright (C) 2016 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.settings.dashboard; 18 19 import android.app.Instrumentation; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.support.test.InstrumentationRegistry; 23 import android.support.test.espresso.matcher.ViewMatchers.Visibility; 24 import android.support.test.filters.SmallTest; 25 import android.support.test.runner.AndroidJUnit4; 26 27 import com.android.settings.R; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 import static android.support.test.espresso.Espresso.onView; 34 import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; 35 import static android.support.test.espresso.assertion.ViewAssertions.matches; 36 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 37 import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; 38 import static android.support.test.espresso.matcher.ViewMatchers.withId; 39 import static com.android.settings.dashboard.FirstIdViewMatcher.withFirstId; 40 41 import static org.hamcrest.Matchers.allOf; 42 43 @RunWith(AndroidJUnit4.class) 44 @SmallTest 45 public class PreferenceThemeTest { 46 47 private Instrumentation mInstrumentation; 48 private Context mTargetContext; 49 private String mTargetPackage; 50 51 @Before 52 public void setUp() throws Exception { 53 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 54 mTargetContext = mInstrumentation.getTargetContext(); 55 mTargetPackage = mTargetContext.getPackageName(); 56 } 57 58 @Test 59 public void startPhoneStatus_preferenceIconSpaceReserved() throws InterruptedException { 60 launchPhoneStatus(); 61 onView(withFirstId(R.id.icon_frame)).check(matches(isDisplayed())); 62 } 63 64 @Test 65 public void startSetupWizardLockScreen_preferenceIconSpaceNotReserved() { 66 launchSetupWizardLockScreen(); 67 // Icons should not be shown, and the frame should not occupy extra space. 68 onView(allOf(withId(R.id.icon_frame), withEffectiveVisibility(Visibility.VISIBLE))) 69 .check(doesNotExist()); 70 onView(withId(R.id.icon_container)).check(doesNotExist()); 71 } 72 73 private void launchPhoneStatus() { 74 final Intent settingsIntent = new Intent("android.settings.DEVICE_INFO_SETTINGS") 75 .addCategory(Intent.CATEGORY_DEFAULT) 76 .setPackage(mTargetPackage) 77 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 78 InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent); 79 } 80 81 private void launchSetupWizardLockScreen() { 82 final Intent settingsIntent = new Intent("com.android.settings.SETUP_LOCK_SCREEN") 83 .addCategory(Intent.CATEGORY_DEFAULT) 84 .setPackage(mTargetPackage) 85 .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 86 InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent); 87 } 88 } 89