• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
20 
21 import static com.google.common.truth.Truth.assertThat;
22 
23 import android.content.Context;
24 import android.provider.Settings;
25 
26 import androidx.test.core.app.ApplicationProvider;
27 
28 import com.android.settings.R;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RobolectricTestRunner;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class DaltonizerPreferenceControllerTest {
37     private static final String PREF_KEY = "daltonizer_preference";
38     private static final int ON = 1;
39     private static final int OFF = 0;
40 
41     private Context mContext;
42     private DaltonizerPreferenceController mController;
43     private String mDaltonizerSummary;
44 
45     @Before
setUp()46     public void setUp() {
47         mContext = ApplicationProvider.getApplicationContext();
48         mController = new DaltonizerPreferenceController(mContext, PREF_KEY);
49         mDaltonizerSummary = mContext.getString(R.string.daltonizer_feature_summary);
50     }
51 
52     @Test
getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnSummary()53     public void getSummary_enabledColorCorrectionShortcutOff_shouldReturnOnSummary() {
54         setColorCorrectionEnabled(true);
55         setColorCorrectionShortcutEnabled(false);
56 
57         assertThat(mController.getSummary().toString()).isEqualTo(
58                 mContext.getString(R.string.daltonizer_state_on));
59     }
60 
61     @Test
getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnSummary()62     public void getSummary_enabledColorCorrectionShortcutOn_shouldReturnOnSummary() {
63         setColorCorrectionEnabled(true);
64         setColorCorrectionShortcutEnabled(true);
65 
66         assertThat(mController.getSummary().toString()).isEqualTo(
67                 mContext.getString(R.string.daltonizer_state_on));
68     }
69 
70     @Test
getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffSummary()71     public void getSummary_disabledColorCorrectionShortcutOff_shouldReturnOffSummary() {
72         setColorCorrectionEnabled(false);
73         setColorCorrectionShortcutEnabled(false);
74 
75         assertThat(mController.getSummary().toString()).isEqualTo(
76                 mContext.getString(R.string.daltonizer_state_off));
77     }
78 
79     @Test
getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffSummary()80     public void getSummary_disabledColorCorrectionShortcutOn_shouldReturnOffSummary() {
81         setColorCorrectionEnabled(false);
82         setColorCorrectionShortcutEnabled(true);
83 
84         assertThat(mController.getSummary().toString()).isEqualTo(
85                 mContext.getString(R.string.daltonizer_state_off));
86     }
87 
setColorCorrectionEnabled(boolean enabled)88     private void setColorCorrectionEnabled(boolean enabled) {
89         Settings.Secure.putInt(mContext.getContentResolver(),
90                 Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED, enabled ? ON : OFF);
91     }
92 
setColorCorrectionShortcutEnabled(boolean enabled)93     private void setColorCorrectionShortcutEnabled(boolean enabled) {
94         Settings.Secure.putString(mContext.getContentResolver(),
95                 Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS,
96                 enabled ? DALTONIZER_COMPONENT_NAME.flattenToString() : "");
97     }
98 }
99