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 17 package com.android.settings; 18 19 import static android.support.test.espresso.Espresso.onView; 20 import static android.support.test.espresso.assertion.ViewAssertions.matches; 21 import static android.support.test.espresso.matcher.RootMatchers.isDialog; 22 import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; 23 import static android.support.test.espresso.matcher.ViewMatchers.withId; 24 import static junit.framework.Assert.fail; 25 26 import android.app.Instrumentation; 27 import android.content.Context; 28 import android.content.Intent; 29 import android.content.pm.ResolveInfo; 30 import android.support.test.InstrumentationRegistry; 31 import android.support.test.filters.SmallTest; 32 import android.support.test.runner.AndroidJUnit4; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 38 @RunWith(AndroidJUnit4.class) 39 @SmallTest 40 public class RegulatoryInfoDisplayActivityTest { 41 42 private Instrumentation mInstrumentation; 43 private Intent mRegulatoryInfoIntent; 44 45 @Before 46 public void setUp() { 47 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 48 mRegulatoryInfoIntent = new Intent("android.settings.SHOW_REGULATORY_INFO") 49 .addCategory(Intent.CATEGORY_DEFAULT) 50 .setPackage(mInstrumentation.getTargetContext().getPackageName()); 51 } 52 53 @Test 54 public void resolveRegulatoryInfoIntent_intentShouldMatchConfig() { 55 // Load intent from PackageManager and load config from Settings app 56 final Context context = mInstrumentation.getTargetContext(); 57 58 final boolean hasRegulatoryInfo = context.getResources() 59 .getBoolean(R.bool.config_show_regulatory_info); 60 final ResolveInfo resolveInfo = mInstrumentation.getTargetContext().getPackageManager() 61 .resolveActivity(mRegulatoryInfoIntent, 0 /* flags */); 62 63 // Check config and intent both enable or both disabled. 64 if (hasRegulatoryInfo && resolveInfo == null) { 65 fail("Config enables regulatory info but there is no handling intent"); 66 return; 67 } 68 if (!hasRegulatoryInfo && resolveInfo != null) { 69 fail("Config disables regulatory info but there is at least one handling intent"); 70 return; 71 } 72 } 73 74 @Test 75 public void launchRegulatoryInfo_shouldNotCrash() { 76 final Context context = mInstrumentation.getTargetContext(); 77 final boolean hasRegulatoryInfo = context.getResources() 78 .getBoolean(R.bool.config_show_regulatory_info); 79 80 if (!hasRegulatoryInfo) { 81 return; 82 } 83 // Launch intent 84 mInstrumentation.startActivitySync(mRegulatoryInfoIntent); 85 86 onView(withId(R.id.regulatoryInfo)) 87 .inRoot(isDialog()) 88 .check(matches(isDisplayed())); 89 } 90 91 } 92