1 /* 2 * Copyright (C) 2018 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.accessibility; 18 19 import static com.android.settings.accessibility.MagnificationPreferenceFragment.OFF; 20 import static com.android.settings.accessibility.MagnificationPreferenceFragment.ON; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import android.content.Context; 25 import android.provider.Settings; 26 import android.support.v7.preference.Preference; 27 28 import com.android.settings.R; 29 import com.android.settings.core.BasePreferenceController; 30 import com.android.settings.testutils.SettingsRobolectricTestRunner; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.mockito.MockitoAnnotations; 36 import org.robolectric.RuntimeEnvironment; 37 38 @RunWith(SettingsRobolectricTestRunner.class) 39 public class MagnificationGesturesPreferenceControllerTest { 40 41 private Context mContext; 42 private MagnificationGesturesPreferenceController mController; 43 private Preference mPreference; 44 45 @Before setUp()46 public void setUp() { 47 MockitoAnnotations.initMocks(this); 48 mContext = RuntimeEnvironment.application; 49 mController = new MagnificationGesturesPreferenceController(mContext, "pref_key"); 50 mPreference = new Preference(mContext); 51 mController.updateState(mPreference); 52 } 53 54 @Test isAlwaysAvailable()55 public void isAlwaysAvailable() { 56 assertThat(mController.getAvailabilityStatus()) 57 .isEqualTo(BasePreferenceController.AVAILABLE); 58 } 59 60 @Test updateState_shouldRefreshSummary()61 public void updateState_shouldRefreshSummary() { 62 Settings.System.putInt(mContext.getContentResolver(), 63 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON); 64 mController.updateState(mPreference); 65 assertThat(mPreference.getSummary()) 66 .isEqualTo(mContext.getString(R.string.accessibility_feature_state_on)); 67 68 Settings.System.putInt(mContext.getContentResolver(), 69 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF); 70 mController.updateState(mPreference); 71 assertThat(mPreference.getSummary()) 72 .isEqualTo(mContext.getString(R.string.accessibility_feature_state_off)); 73 } 74 75 @Test updateState_shouldRefreshSummarySuw()76 public void updateState_shouldRefreshSummarySuw() { 77 mController.setIsFromSUW(true); 78 mController.updateState(mPreference); 79 assertThat(mPreference.getSummary()) 80 .isEqualTo(mContext.getString(R.string. 81 accessibility_screen_magnification_short_summary)); 82 } 83 84 @Test isChecked_enabled()85 public void isChecked_enabled() { 86 Settings.System.putInt(mContext.getContentResolver(), 87 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON); 88 89 assertThat(mController.isChecked()).isTrue(); 90 } 91 92 @Test isChecked_disabled()93 public void isChecked_disabled() { 94 Settings.System.putInt(mContext.getContentResolver(), 95 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF); 96 97 assertThat(mController.isChecked()).isFalse(); 98 } 99 100 @Test setChecked_enabled()101 public void setChecked_enabled() { 102 mController.setChecked(true); 103 104 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 105 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1)) 106 .isEqualTo(ON); 107 } 108 109 @Test setChecked_disabled()110 public void setChecked_disabled() { 111 mController.setChecked(false); 112 113 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 114 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1)) 115 .isEqualTo(OFF); 116 } 117 118 @Test isSliceableCorrectKey_returnsTrue()119 public void isSliceableCorrectKey_returnsTrue() { 120 final MagnificationGesturesPreferenceController controller = 121 new MagnificationGesturesPreferenceController(mContext, 122 "screen_magnification_gestures_preference_screen"); 123 assertThat(controller.isSliceable()).isTrue(); 124 } 125 126 @Test isSliceableIncorrectKey_returnsFalse()127 public void isSliceableIncorrectKey_returnsFalse() { 128 final MagnificationGesturesPreferenceController controller = 129 new MagnificationGesturesPreferenceController(mContext, "bad_key"); 130 assertThat(controller.isSliceable()).isFalse(); 131 } 132 } 133