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