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.gestures;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.provider.Settings;
23 
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.MockitoAnnotations;
28 import org.robolectric.RobolectricTestRunner;
29 import org.robolectric.RuntimeEnvironment;
30 
31 @RunWith(RobolectricTestRunner.class)
32 public class GlobalActionsPanelPreferenceControllerTest {
33 
34     private Context mContext;
35     private GlobalActionsPanelPreferenceController mController;
36 
37     private static final String KEY_GESTURE_PANEL = "gesture_global_actions_panel";
38 
39     @Before
setUp()40     public void setUp() {
41         MockitoAnnotations.initMocks(this);
42         mContext = RuntimeEnvironment.application;
43         mController = new GlobalActionsPanelPreferenceController(mContext, KEY_GESTURE_PANEL);
44     }
45 
46     @Test
testIsChecked_panelEnabled()47     public void testIsChecked_panelEnabled() {
48         Settings.Secure.putInt(
49                 mContext.getContentResolver(), mController.ENABLED_SETTING, 1);
50         assertThat(mController.isChecked()).isTrue();
51     }
52 
53     @Test
testIsChecked_panelDisabled()54     public void testIsChecked_panelDisabled() {
55         Settings.Secure.putInt(
56                 mContext.getContentResolver(), mController.ENABLED_SETTING, 0);
57         assertThat(mController.isChecked()).isFalse();
58     }
59 
60     @Test
getAvailabilityStatus_panelAvailable()61     public void getAvailabilityStatus_panelAvailable() {
62         Settings.Secure.putInt(
63                 mContext.getContentResolver(), mController.AVAILABLE_SETTING, 1);
64         assertThat(mController.getAvailabilityStatus()).isEqualTo(mController.AVAILABLE);
65     }
66 
67     @Test
getAvailabilityStatus_panelUnavailable()68     public void getAvailabilityStatus_panelUnavailable() {
69         Settings.Secure.putInt(
70                 mContext.getContentResolver(), mController.AVAILABLE_SETTING, 0);
71         assertThat(mController.getAvailabilityStatus())
72                 .isEqualTo(mController.CONDITIONALLY_UNAVAILABLE);
73     }
74 
75     @Test
isSliceable_correctKey()76     public void isSliceable_correctKey() {
77         final GlobalActionsPanelPreferenceController controller =
78                 new GlobalActionsPanelPreferenceController(mContext, mController.TOGGLE_KEY);
79         assertThat(controller.isSliceable()).isTrue();
80     }
81 
82     @Test
isSliceable_incorrectKey()83     public void isSliceable_incorrectKey() {
84         final GlobalActionsPanelPreferenceController controller =
85                 new GlobalActionsPanelPreferenceController(mContext, "bad_key");
86         assertThat(controller.isSliceable()).isFalse();
87     }
88 
89     @Test
isPublicSlice_returnTrue()90     public void isPublicSlice_returnTrue() {
91         assertThat(mController.isPublicSlice()).isTrue();
92     }
93 }
94