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