OSDN Git Service

Disable lowBatteryTip and ReducedBatteryTip
[android-x86/packages-apps-Settings.git] / tests / robotests / src / com / android / settings / fuelgauge / batterytip / BatteryTipPolicyTest.java
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.fuelgauge.batterytip;
18
19 import static com.google.common.truth.Truth.assertThat;
20
21 import static org.mockito.Matchers.eq;
22 import static org.mockito.Mockito.doReturn;
23 import static org.mockito.Mockito.spy;
24
25 import android.content.Context;
26 import android.provider.Settings;
27
28 import com.android.settings.TestConfig;
29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.robolectric.RuntimeEnvironment;
35 import org.robolectric.annotation.Config;
36
37 @RunWith(SettingsRobolectricTestRunner.class)
38 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
39 public class BatteryTipPolicyTest {
40     private static final String BATTERY_TIP_CONSTANTS_VALUE = "battery_tip_enabled=true"
41             + ",summary_enabled=false"
42             + ",battery_saver_tip_enabled=false"
43             + ",high_usage_enabled=true"
44             + ",high_usage_app_count=5"
45             + ",app_restriction_enabled=true"
46             + ",reduced_battery_enabled=true"
47             + ",reduced_battery_percent=30"
48             + ",low_battery_enabled=false"
49             + ",low_battery_hour=10";
50     private Context mContext;
51
52     @Before
53     public void setUp() {
54         mContext = RuntimeEnvironment.application;
55     }
56
57     @Test
58     public void testInit_usesConfigValues() {
59         Settings.Global.putString(mContext.getContentResolver(),
60                 Settings.Global.BATTERY_TIP_CONSTANTS, BATTERY_TIP_CONSTANTS_VALUE);
61
62         final BatteryTipPolicy batteryTipPolicy = new BatteryTipPolicy(mContext);
63
64         assertThat(batteryTipPolicy.batteryTipEnabled).isTrue();
65         assertThat(batteryTipPolicy.summaryEnabled).isFalse();
66         assertThat(batteryTipPolicy.batterySaverTipEnabled).isFalse();
67         assertThat(batteryTipPolicy.highUsageEnabled).isTrue();
68         assertThat(batteryTipPolicy.highUsageAppCount).isEqualTo(5);
69         assertThat(batteryTipPolicy.appRestrictionEnabled).isTrue();
70         assertThat(batteryTipPolicy.reducedBatteryEnabled).isTrue();
71         assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(30);
72         assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
73         assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(10);
74     }
75
76     @Test
77     public void testInit_defaultValues() {
78         Settings.Global.putString(mContext.getContentResolver(),
79                 Settings.Global.BATTERY_TIP_CONSTANTS, "");
80
81         final BatteryTipPolicy batteryTipPolicy = new BatteryTipPolicy(mContext);
82
83         assertThat(batteryTipPolicy.batteryTipEnabled).isTrue();
84         assertThat(batteryTipPolicy.summaryEnabled).isTrue();
85         assertThat(batteryTipPolicy.batterySaverTipEnabled).isTrue();
86         assertThat(batteryTipPolicy.highUsageEnabled).isTrue();
87         assertThat(batteryTipPolicy.highUsageAppCount).isEqualTo(3);
88         assertThat(batteryTipPolicy.appRestrictionEnabled).isTrue();
89         assertThat(batteryTipPolicy.reducedBatteryEnabled).isFalse();
90         assertThat(batteryTipPolicy.reducedBatteryPercent).isEqualTo(50);
91         assertThat(batteryTipPolicy.lowBatteryEnabled).isFalse();
92         assertThat(batteryTipPolicy.lowBatteryHour).isEqualTo(16);
93     }
94
95 }