1 /* 2 * Copyright (C) 2012 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 android.preference2.cts; 18 19 import com.android.cts.preference2.R; 20 21 import android.preference.CheckBoxPreference; 22 import android.preference.EditTextPreference; 23 import android.preference.Preference; 24 import android.preference.PreferenceGroup; 25 import android.preference.PreferenceManager; 26 import android.preference.PreferenceScreen; 27 import android.preference2.cts.PreferenceFragmentActivity.PrefFragment; 28 import android.test.ActivityInstrumentationTestCase2; 29 30 public class PreferenceGroupTest 31 extends ActivityInstrumentationTestCase2<PreferenceFromCodeActivity> { 32 33 private PreferenceFromCodeActivity mActivity; 34 private PreferenceGroup mPreferenceGroup; 35 PreferenceGroupTest()36 public PreferenceGroupTest() { 37 super(PreferenceFromCodeActivity.class); 38 } 39 40 @Override setUp()41 protected void setUp() throws Exception { 42 super.setUp(); 43 mActivity = getActivity(); 44 mPreferenceGroup = (PreferenceGroup) mActivity.findPreference("pref-group"); 45 CheckBoxPreference checkboxPref = new CheckBoxPreference(mActivity); 46 checkboxPref.setKey("checkbox_preference_group"); 47 checkboxPref.setIcon(R.drawable.ic_launcher); 48 checkboxPref.setTitle(R.string.title_checkbox_preference); 49 checkboxPref.setSummary(R.string.summary_checkbox_preference); 50 checkboxPref.setSummaryOn(R.string.summary_on_checkbox_preference); 51 checkboxPref.setSummaryOff(R.string.summary_off_checkbox_preference); 52 checkboxPref.setChecked(true); 53 mPreferenceGroup.addPreference(checkboxPref); 54 } 55 testAddPreference()56 public void testAddPreference() { 57 Preference preference = mActivity.findPreference("pref-group"); 58 assertNotNull(preference); 59 } 60 testFindPreference()61 public void testFindPreference() { 62 Preference preference = mPreferenceGroup.findPreference("checkbox_preference_group"); 63 assertNotNull(preference); 64 } 65 testPreferenceCount()66 public void testPreferenceCount() { 67 assertEquals(1, mPreferenceGroup.getPreferenceCount()); 68 } 69 testSetOrderingAsAdded()70 public void testSetOrderingAsAdded() { 71 mPreferenceGroup.setOrderingAsAdded(false); 72 assertFalse(mPreferenceGroup.isOrderingAsAdded()); 73 } 74 testRemoveAll()75 public void testRemoveAll() { 76 mPreferenceGroup.removeAll(); 77 assertEquals(0, mPreferenceGroup.getPreferenceCount()); 78 } 79 testRemovePreference()80 public void testRemovePreference() { 81 Preference preference = mPreferenceGroup.findPreference("checkbox_preference_group"); 82 mPreferenceGroup.removePreference(preference); 83 assertEquals(0, mPreferenceGroup.getPreferenceCount()); 84 } 85 testIsOnSameScreenAsChildren()86 public void testIsOnSameScreenAsChildren() { 87 CustomPreferenceGroup mCustomPreferenceGroup = (CustomPreferenceGroup) 88 mActivity.findPreference("custom-pref-group"); 89 assertTrue(mCustomPreferenceGroup.isOnSameScreenAsChildren()); 90 } 91 testOnPrepareAddPreference( )92 public void testOnPrepareAddPreference( ) { 93 CustomPreferenceGroup mCustomPreferenceGroup = (CustomPreferenceGroup) 94 mActivity.findPreference("custom-pref-group"); 95 CheckBoxPreference checkboxPref = new CheckBoxPreference(mActivity); 96 checkboxPref.setKey("checkbox_preference-2"); 97 mCustomPreferenceGroup.addPreference(checkboxPref); 98 assertTrue(mCustomPreferenceGroup.mOnPrepareCalled); 99 } 100 } 101