• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.development;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 import static org.mockito.Mockito.verify;
21 import static org.mockito.Mockito.when;
22 
23 import android.content.Context;
24 import android.content.res.Resources;
25 import android.provider.Settings;
26 import android.support.v7.preference.ListPreference;
27 import android.support.v7.preference.PreferenceScreen;
28 
29 import com.android.settings.R;
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.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.robolectric.RuntimeEnvironment;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 public class SecondaryDisplayPreferenceControllerTest {
41 
42     @Mock
43     private ListPreference mPreference;
44     @Mock
45     private PreferenceScreen mScreen;
46 
47     /**
48      * 0: None
49      * 1: 480p
50      * 2: 480p (secure)
51      * 3: 720p
52      * 4: 720p (secure)
53      * 5: 1080p
54      * 6: 1080p (secure)
55      * 7: 4K
56      * 8: 4K (secure)
57      * 9: 4K (upscaled)
58      * 10: 4K (upscaled, secure)
59      * 11: 720p, 1080p (dual screen)
60      */
61     private String[] mListValues;
62     private String[] mListSummaries;
63     private Context mContext;
64     private SecondaryDisplayPreferenceController mController;
65 
66     @Before
setup()67     public void setup() {
68         MockitoAnnotations.initMocks(this);
69         mContext = RuntimeEnvironment.application;
70         final Resources resources = mContext.getResources();
71         mListValues = resources.getStringArray(R.array.overlay_display_devices_values);
72         mListSummaries = resources.getStringArray(R.array.overlay_display_devices_entries);
73         mController = new SecondaryDisplayPreferenceController(mContext);
74         when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
75         mController.displayPreference(mScreen);
76     }
77 
78     @Test
onPreferenceChange_set480p_shouldEnable480p()79     public void onPreferenceChange_set480p_shouldEnable480p() {
80         mController.onPreferenceChange(mPreference, mListValues[1]);
81 
82         final String value = Settings.Global.getString(mContext.getContentResolver(),
83                 Settings.Global.OVERLAY_DISPLAY_DEVICES);
84         assertThat(value).isEqualTo(mListValues[1]);
85     }
86 
87     @Test
onPreferenceChange_set720p_shouldEnable720p()88     public void onPreferenceChange_set720p_shouldEnable720p() {
89         mController.onPreferenceChange(mPreference, mListValues[3]);
90 
91         final String value = Settings.Global.getString(mContext.getContentResolver(),
92                 Settings.Global.OVERLAY_DISPLAY_DEVICES);
93         assertThat(value).isEqualTo(mListValues[3]);
94     }
95 
96     @Test
updateState_set480p_shouldSetPreferenceTo480p()97     public void updateState_set480p_shouldSetPreferenceTo480p() {
98         Settings.Global.putString(mContext.getContentResolver(),
99                 Settings.Global.OVERLAY_DISPLAY_DEVICES, mListValues[1]);
100 
101         mController.updateState(mPreference);
102 
103         verify(mPreference).setValue(mListValues[1]);
104         verify(mPreference).setSummary(mListSummaries[1]);
105     }
106 
107     @Test
updateState_set720p_shouldSetPreferenceTo720p()108     public void updateState_set720p_shouldSetPreferenceTo720p() {
109         Settings.Global.putString(mContext.getContentResolver(),
110                 Settings.Global.OVERLAY_DISPLAY_DEVICES, mListValues[3]);
111 
112         mController.updateState(mPreference);
113 
114         verify(mPreference).setValue(mListValues[3]);
115         verify(mPreference).setSummary(mListSummaries[3]);
116     }
117 
118     @Test
updateState_nothingSet_shouldSetDefaultToNone()119     public void updateState_nothingSet_shouldSetDefaultToNone() {
120         mController.updateState(mPreference);
121 
122         verify(mPreference).setValue(mListValues[0]);
123         verify(mPreference).setSummary(mListSummaries[0]);
124     }
125 
126     @Test
onDeveloperOptionsSwitchDisabled_shouldDisablePreferenceAndSetToNone()127     public void onDeveloperOptionsSwitchDisabled_shouldDisablePreferenceAndSetToNone() {
128         mController.onDeveloperOptionsSwitchDisabled();
129 
130         final String value = Settings.Global.getString(mContext.getContentResolver(),
131                 Settings.Global.OVERLAY_DISPLAY_DEVICES);
132         assertThat(value).isNull();
133         verify(mPreference).setEnabled(false);
134         verify(mPreference).setValue(mListValues[0]);
135         verify(mPreference).setSummary(mListSummaries[0]);
136     }
137 }
138