• 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"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.settings.display;
16 
17 import static com.google.common.truth.Truth.assertThat;
18 
19 import android.content.Context;
20 import android.provider.Settings.Secure;
21 import com.android.internal.app.ColorDisplayController;
22 import com.android.settings.testutils.SettingsRobolectricTestRunner;
23 import com.android.settings.testutils.shadow.SettingsShadowResources;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.robolectric.RuntimeEnvironment;
28 import org.robolectric.annotation.Config;
29 
30 @RunWith(SettingsRobolectricTestRunner.class)
31 @Config(shadows = SettingsShadowResources.class)
32 public class NightDisplayAutoModePreferenceControllerTest {
33 
34     private Context mContext;
35     private NightDisplayAutoModePreferenceController mController;
36 
37     @Before
setUp()38     public void setUp() {
39         mContext = RuntimeEnvironment.application;
40         mController = new NightDisplayAutoModePreferenceController(mContext,
41             "night_display_auto_mode");
42     }
43 
44     @Test
isAvailable_configuredAvailable()45     public void isAvailable_configuredAvailable() {
46         SettingsShadowResources.overrideResource(
47                 com.android.internal.R.bool.config_nightDisplayAvailable, true);
48         assertThat(mController.isAvailable()).isTrue();
49     }
50 
51     @Test
isAvailable_configuredUnavailable()52     public void isAvailable_configuredUnavailable() {
53         SettingsShadowResources.overrideResource(
54                 com.android.internal.R.bool.config_nightDisplayAvailable, false);
55         assertThat(mController.isAvailable()).isFalse();
56     }
57 
58     @Test
onPreferenceChange_changesAutoMode()59     public void onPreferenceChange_changesAutoMode() {
60         mController.onPreferenceChange(null,
61                 String.valueOf(ColorDisplayController.AUTO_MODE_TWILIGHT));
62         assertThat(Secure.getInt(mContext.getContentResolver(), Secure.NIGHT_DISPLAY_AUTO_MODE, -1))
63                 .isEqualTo(ColorDisplayController.AUTO_MODE_TWILIGHT);
64     }
65 }
66