1/* 2 * Copyright (C) 2010 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 17package com.android.settings; 18 19import com.android.settings.Settings; 20 21import android.content.Context; 22import android.content.Intent; 23import android.content.pm.ApplicationInfo; 24import android.content.pm.PackageManager; 25import android.content.pm.ResolveInfo; 26import android.test.ActivityInstrumentationTestCase2; 27 28import java.util.List; 29 30/** 31 * Tests for the Settings operator/manufacturer hook. 32 * 33 * Running all tests: 34 * 35 * make SettingsTests 36 * adb push SettingsTests.apk /system/app/SettingsTests.apk 37 * adb shell am instrument \ 38 * -w com.android.settings.tests/android.test.InstrumentationTestRunner 39 */ 40public class SettingsHookTests extends ActivityInstrumentationTestCase2<Settings> { 41 42 private static final String PACKAGE_NAME = "com.android.settings.tests.unit"; 43 44 private static final String KEY_SETTINGS_ROOT = "parent"; 45 private static final String KEY_SETTINGS_OPERATOR = "operator_settings"; 46 private static final String KEY_SETTINGS_MANUFACTURER = "manufacturer_settings"; 47 48 private static final String INTENT_OPERATOR_HOOK = "com.android.settings.OPERATOR_APPLICATION_SETTING"; 49 private static final String INTENT_MANUFACTURER_HOOK = "com.android.settings.MANUFACTURER_APPLICATION_SETTING"; 50 51 private Settings mSettings; 52 53 public SettingsHookTests() { 54 super("com.android.settings", Settings.class); 55 } 56 57 @Override 58 protected void setUp() throws Exception { 59 super.setUp(); 60 mSettings = getActivity(); 61 } 62 63 /** 64 * Test that the operator/manufacturer settings hook test application is 65 * available and that it's installed in the device's system image. 66 */ 67 public void testSettingsHookTestAppAvailable() throws Exception { 68 Context context = mSettings.getApplicationContext(); 69 PackageManager pm = context.getPackageManager(); 70 ApplicationInfo applicationInfo = pm.getApplicationInfo(PACKAGE_NAME, 0); 71 assertTrue((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0); 72 } 73 74 /** 75 * Test that the operator test activity has registered an intent-filter for 76 * an action named 'android.settings.OPERATOR_APPLICATION_SETTING'. 77 */ 78 public void testOperatorIntentFilter() { 79 boolean result = false; 80 Context context = mSettings.getApplicationContext(); 81 PackageManager pm = context.getPackageManager(); 82 Intent intent = new Intent(INTENT_OPERATOR_HOOK); 83 List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); 84 for (ResolveInfo resolveInfo : list) { 85 if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) { 86 result = true; 87 } 88 } 89 assertTrue("Intent-filter not found", result); 90 } 91 92 /** 93 * Test that the manufacturer test activity has registered an intent-filter 94 * for an action named 'android.settings.MANUFACTURER_APPLICATION_SETTING'. 95 */ 96 public void testManufacturerIntentFilter() { 97 boolean result = false; 98 Context context = mSettings.getApplicationContext(); 99 PackageManager pm = context.getPackageManager(); 100 Intent intent = new Intent(INTENT_MANUFACTURER_HOOK); 101 List<ResolveInfo> list = pm.queryIntentActivities(intent, 0); 102 for (ResolveInfo resolveInfo : list) { 103 if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) { 104 result = true; 105 } 106 } 107 assertTrue("Intent-filter not found", result); 108 } 109 110 /** 111 * Test that the operator preference is available in the Settings 112 * application. 113 */ 114 public void testOperatorPreferenceAvailable() { 115// TODO: fix this test case to work with fragments 116// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT); 117// Preference operatorPreference = root.findPreference(KEY_SETTINGS_OPERATOR); 118// assertNotNull(operatorPreference); 119 } 120 121 /** 122 * Test that the manufacturer preference is available in the Settings 123 * application. 124 */ 125 public void testManufacturerPreferenceAvailable() { 126// TODO: fix this test case to work with fragments 127// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT); 128// Preference manufacturerHook = root.findPreference(KEY_SETTINGS_MANUFACTURER); 129// assertNotNull(manufacturerHook); 130 } 131 132} 133