1 /******************************************************************************* 2 * Copyright (C) 2014 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 *******************************************************************************/ 17 18 package com.android.mail.ui.settings; 19 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.preference.ListPreference; 23 import android.preference.PreferenceActivity; 24 import android.test.ActivityInstrumentationTestCase2; 25 import android.test.UiThreadTest; 26 import android.test.suitebuilder.annotation.MediumTest; 27 28 import com.android.mail.preferences.MailPrefs; 29 import com.android.mail.providers.UIProvider; 30 import com.android.mail.providers.UIProvider.AutoAdvance; 31 32 public class GeneralPrefsFragmentTest 33 extends ActivityInstrumentationTestCase2<MailPreferenceActivity> { 34 35 private static final String PREFS_NAME_TEST = "UnifiedEmailTest"; 36 37 public GeneralPrefsFragmentTest() { 38 super(MailPreferenceActivity.class); 39 } 40 41 @Override 42 protected void setUp() throws Exception { 43 super.setUp(); 44 45 final Intent i = new Intent(); 46 i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, 47 "com.android.mail.ui.settings.GeneralPrefsFragment"); 48 final Bundle b = new Bundle(1); 49 b.putBoolean(GeneralPrefsFragment.CALLED_FROM_TEST, true); 50 i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, b); 51 setActivityIntent(i); 52 final MailPreferenceActivity activity = getActivity(); 53 getInstrumentation().waitForIdleSync(); 54 getInstrumentation().runOnMainSync(new Runnable() { 55 @Override 56 public void run() { 57 activity.getFragmentManager().executePendingTransactions(); 58 } 59 }); 60 final GeneralPrefsFragment fragment = activity.getGeneralPrefsFragment(); 61 fragment.mMailPrefs = new MailPrefs(activity, PREFS_NAME_TEST); 62 } 63 64 @UiThreadTest 65 @MediumTest 66 public void testChangeAutoAdvance() throws Throwable { 67 final MailPreferenceActivity activity = getActivity(); 68 final GeneralPrefsFragment fragment = activity.getGeneralPrefsFragment(); 69 final MailPrefs mailPrefs = fragment.mMailPrefs; 70 final ListPreference autoAdvancePref = (ListPreference) fragment 71 .findPreference(GeneralPrefsFragment.AUTO_ADVANCE_WIDGET); 72 73 fragment.onPreferenceChange(autoAdvancePref, UIProvider.AUTO_ADVANCE_MODE_OLDER); 74 assertEquals(mailPrefs.getAutoAdvanceMode(), AutoAdvance.OLDER); 75 76 fragment.onPreferenceChange(autoAdvancePref, UIProvider.AUTO_ADVANCE_MODE_NEWER); 77 assertEquals(mailPrefs.getAutoAdvanceMode(), AutoAdvance.NEWER); 78 } 79 80 } 81