• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 import androidx.preference.Preference;
28 
29 import com.android.settings.R;
30 import com.android.settings.core.BasePreferenceController;
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.RobolectricTestRunner;
37 import org.robolectric.RuntimeEnvironment;
38 
39 @RunWith(RobolectricTestRunner.class)
40 public class MagnificationGesturesPreferenceControllerTest {
41 
42     private Context mContext;
43     private MagnificationGesturesPreferenceController mController;
44     private Preference mPreference;
45 
46     @Before
setUp()47     public void setUp() {
48         MockitoAnnotations.initMocks(this);
49         mContext = RuntimeEnvironment.application;
50         mController = new MagnificationGesturesPreferenceController(mContext, "pref_key");
51         mPreference = new Preference(mContext);
52         mController.updateState(mPreference);
53     }
54 
55     @Test
isAlwaysAvailable()56     public void isAlwaysAvailable() {
57         assertThat(mController.getAvailabilityStatus())
58                 .isEqualTo(BasePreferenceController.AVAILABLE);
59     }
60 
61     @Test
updateState_shouldRefreshSummary()62     public void updateState_shouldRefreshSummary() {
63         Settings.Secure.putInt(mContext.getContentResolver(),
64                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
65         mController.updateState(mPreference);
66         assertThat(mPreference.getSummary())
67                 .isEqualTo(mContext.getString(R.string.accessibility_feature_state_on));
68 
69         Settings.Secure.putInt(mContext.getContentResolver(),
70                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
71         mController.updateState(mPreference);
72         assertThat(mPreference.getSummary())
73                 .isEqualTo(mContext.getString(R.string.accessibility_feature_state_off));
74     }
75 
76     @Test
updateState_shouldRefreshSummarySuw()77     public void updateState_shouldRefreshSummarySuw() {
78         mController.setIsFromSUW(true);
79         mController.updateState(mPreference);
80         assertThat(mPreference.getSummary())
81                 .isEqualTo(mContext.getString(R.string.
82                         accessibility_screen_magnification_short_summary));
83     }
84 
85     @Test
isChecked_enabled()86     public void isChecked_enabled() {
87         Settings.Secure.putInt(mContext.getContentResolver(),
88                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, ON);
89 
90         assertThat(mController.isChecked()).isTrue();
91     }
92 
93     @Test
isChecked_disabled()94     public void isChecked_disabled() {
95         Settings.Secure.putInt(mContext.getContentResolver(),
96                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, OFF);
97 
98         assertThat(mController.isChecked()).isFalse();
99     }
100 
101     @Test
setChecked_enabled()102     public void setChecked_enabled() {
103         mController.setChecked(true);
104 
105         assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
106                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1))
107                 .isEqualTo(ON);
108     }
109 
110     @Test
setChecked_disabled()111     public void setChecked_disabled() {
112         mController.setChecked(false);
113 
114         assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
115                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, -1))
116                 .isEqualTo(OFF);
117     }
118 
119     @Test
isSliceableCorrectKey_returnsTrue()120     public void isSliceableCorrectKey_returnsTrue() {
121         final MagnificationGesturesPreferenceController controller =
122                 new MagnificationGesturesPreferenceController(mContext,
123                         "screen_magnification_gestures_preference_screen");
124         assertThat(controller.isSliceable()).isTrue();
125     }
126 
127     @Test
isSliceableIncorrectKey_returnsFalse()128     public void isSliceableIncorrectKey_returnsFalse() {
129         final MagnificationGesturesPreferenceController controller =
130                 new MagnificationGesturesPreferenceController(mContext, "bad_key");
131         assertThat(controller.isSliceable()).isFalse();
132     }
133 }
134