• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.gestures;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.content.pm.PackageManager;
23 import android.provider.Settings;
24 
25 import com.android.settings.core.BasePreferenceController;
26 
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.robolectric.RobolectricTestRunner;
31 import org.robolectric.RuntimeEnvironment;
32 import org.robolectric.Shadows;
33 import org.robolectric.shadows.ShadowPackageManager;
34 
35 @RunWith(RobolectricTestRunner.class)
36 public class PowerMenuPreferenceControllerTest {
37     private Context mContext;
38     private PowerMenuPreferenceController mController;
39     private ShadowPackageManager mShadowPackageManager;
40 
41     private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
42     private static final String CONTROLS_ENABLED = Settings.Secure.CONTROLS_ENABLED;
43     private static final String CONTROLS_FEATURE = PackageManager.FEATURE_CONTROLS;
44     private static final String CARDS_ENABLED = Settings.Secure.GLOBAL_ACTIONS_PANEL_ENABLED;
45     private static final String CARDS_AVAILABLE = Settings.Secure.GLOBAL_ACTIONS_PANEL_AVAILABLE;
46 
47     @Before
setUp()48     public void setUp() {
49         mContext = RuntimeEnvironment.application;
50         mShadowPackageManager = Shadows.shadowOf(mContext.getPackageManager());
51         mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
52     }
53 
54     @Test
getAvailabilityStatus_bothAvailable_available()55     public void getAvailabilityStatus_bothAvailable_available() {
56         Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
57         mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
58 
59         assertThat(mController.getAvailabilityStatus()).isEqualTo(
60                 BasePreferenceController.AVAILABLE);
61     }
62 
63     @Test
getAvailabilityStatus_onlyCardsAvailable_available()64     public void getAvailabilityStatus_onlyCardsAvailable_available() {
65         Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 1);
66         mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
67 
68         assertThat(mController.getAvailabilityStatus()).isEqualTo(
69                 BasePreferenceController.AVAILABLE);
70     }
71 
72     @Test
getAvailabilityStatus_onlyControlsAvailable_available()73     public void getAvailabilityStatus_onlyControlsAvailable_available() {
74         Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
75         mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, true);
76 
77         assertThat(mController.getAvailabilityStatus()).isEqualTo(
78                 BasePreferenceController.AVAILABLE);
79     }
80 
81     @Test
getAvailabilityStatus_bothUnavailable_unavailable()82     public void getAvailabilityStatus_bothUnavailable_unavailable() {
83         Settings.Secure.putInt(mContext.getContentResolver(), CARDS_AVAILABLE, 0);
84         mShadowPackageManager.setSystemFeature(CONTROLS_FEATURE, false);
85 
86         assertThat(mController.getAvailabilityStatus()).isEqualTo(
87                 BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
88     }
89 }
90