GeneralPrefsFragmentTest.java revision 9b4df381c0a1197d8381134181c6c12087a90e2f
19b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler/******************************************************************************* 29b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * Copyright (C) 2014 Google Inc. 39b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * Licensed to The Android Open Source Project. 49b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * 59b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * Licensed under the Apache License, Version 2.0 (the "License"); 69b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * you may not use this file except in compliance with the License. 79b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * You may obtain a copy of the License at 89b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * 99b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * http://www.apache.org/licenses/LICENSE-2.0 109b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * 119b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * Unless required by applicable law or agreed to in writing, software 129b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * distributed under the License is distributed on an "AS IS" BASIS, 139b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 149b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * See the License for the specific language governing permissions and 159b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler * limitations under the License. 169b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler *******************************************************************************/ 179b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 189b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerpackage com.android.mail.ui.settings; 199b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 209b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.app.Activity; 219b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.content.Intent; 229b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.preference.PreferenceActivity; 239b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.test.ActivityInstrumentationTestCase2; 249b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.test.UiThreadTest; 259b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.test.suitebuilder.annotation.MediumTest; 269b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerimport android.test.suitebuilder.annotation.Suppress; 279b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 289b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler// TODO: Insert the unified prefs class here once it's written 299b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler@Suppress 309b4df381c0a1197d8381134181c6c12087a90e2fTony Mantlerpublic class GeneralPrefsFragmentTest 319b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler extends ActivityInstrumentationTestCase2<Activity> { 329b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 339b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler public GeneralPrefsFragmentTest() { 349b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler super(Activity.class); 359b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler } 369b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 379b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler @Override 389b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler protected void setUp() throws Exception { 399b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler super.setUp(); 409b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 419b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final Intent i = new Intent(); 429b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, "com.android.mail.ui.settings."); 439b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler setActivityIntent(i); 449b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler getActivity(); 459b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler } 469b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 479b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler @UiThreadTest 489b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler @MediumTest 499b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler public void testChangeAutoAdvance() throws Throwable { 509b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler // A weak proxy test that a click on auto-advance will actually persist the proper value. 519b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler // A better test would simulate a dialog, dialog click, and check that the value is 529b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler // both displayed and persisted. 539b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler /* 549b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final Activity activity = getActivity(); 559b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final MailPrefs mailPrefs = MailPrefs.get(activity); 569b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 579b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler activity.getFragmentManager().executePendingTransactions(); 589b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 599b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final GeneralPrefsFragment fragment = activity.getGeneralPrefsFragment(); 609b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final ListPreference autoAdvancePref = (ListPreference) fragment 619b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler .findPreference(GeneralPrefsFragment.AUTO_ADVANCE_WIDGET); 629b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 639b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler fragment.onPreferenceChange(autoAdvancePref, UIProvider.AUTO_ADVANCE_MODE_OLDER); 649b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 659b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler assertEquals(AutoAdvance.OLDER, mailPrefs.getAutoAdvanceMode()); 669b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 679b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler fragment.onPreferenceChange(autoAdvancePref, UIProvider.AUTO_ADVANCE_MODE_NEWER); 689b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 699b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler assertEquals(AutoAdvance.NEWER, mailPrefs.getAutoAdvanceMode()); 709b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler */ 719b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler } 729b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 739b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler @UiThreadTest 749b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler @MediumTest 759b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler public void testChangeSnapHeader() throws Throwable { 769b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler /* 779b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final Activity activity = getActivity(); 789b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final MailPrefs mailPrefs = MailPrefs.get(activity); 799b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 809b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler activity.getFragmentManager().executePendingTransactions(); 819b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 829b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final GeneralPrefsFragment fragment = activity.getGeneralPrefsFragment(); 839b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final ListPreference snapPref = (ListPreference) fragment 849b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler .findPreference(GeneralPrefsFragment.SNAP_HEADER_MODE_WIDGET); 859b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 869b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final int neverValue = GeneralPrefsFragment.prefValueToWidgetIndex( 879b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler GeneralPrefsFragment.SNAP_HEADER_VALUES, SnapHeaderValue.NEVER, -1); 889b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler snapPref.setValueIndex(neverValue); 899b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 909b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler assertEquals(SnapHeaderValue.NEVER, mailPrefs.getSnapHeaderMode()); 919b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 929b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler final int alwaysValue = GeneralPrefsFragment.prefValueToWidgetIndex( 939b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler GeneralPrefsFragment.SNAP_HEADER_VALUES, SnapHeaderValue.ALWAYS, -1); 949b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler snapPref.setValueIndex(alwaysValue); 959b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 969b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler assertEquals(SnapHeaderValue.ALWAYS, mailPrefs.getSnapHeaderMode()); 979b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler */ 989b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler } 999b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler 1009b4df381c0a1197d8381134181c6c12087a90e2fTony Mantler} 101