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.os.SystemProperties;
23 import android.os.UserHandle;
24 
25 import com.android.settings.R;
26 import com.android.settings.core.BasePreferenceController;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.RobolectricTestRunner;
32 import org.robolectric.RuntimeEnvironment;
33 
34 @RunWith(RobolectricTestRunner.class)
35 public class OneHandedEnablePreferenceControllerTest {
36 
37     private static final String KEY = "gesture_one_handed_mode_enabled";
38 
39     private Context mContext;
40     private OneHandedEnablePreferenceController mController;
41 
42     @Before
setUp()43     public void setUp() {
44         mContext = RuntimeEnvironment.application;
45         mController = new OneHandedEnablePreferenceController(mContext, KEY);
46         OneHandedSettingsUtils.setUserId(UserHandle.myUserId());
47     }
48 
49     @Test
getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable()50     public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() {
51         SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true");
52 
53         assertThat(mController.getAvailabilityStatus())
54                 .isEqualTo(BasePreferenceController.AVAILABLE);
55     }
56 
57     @Test
getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported()58     public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldUnsupported() {
59         SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false");
60 
61         assertThat(mController.getAvailabilityStatus())
62                 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
63     }
64 
65     @Test
getSummary_enabledOneHanded_shouldDisplayOnSummary()66     public void getSummary_enabledOneHanded_shouldDisplayOnSummary() {
67         OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true);
68 
69         assertThat(mController.getSummary())
70                 .isEqualTo(mContext.getText(R.string.switch_on_text));
71     }
72 
73     @Test
getSummary_disabledOneHanded_shouldDisplayOffSummary()74     public void getSummary_disabledOneHanded_shouldDisplayOffSummary() {
75         OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false);
76 
77         assertThat(mController.getSummary())
78                 .isEqualTo(mContext.getText(R.string.switch_off_text));
79     }
80 }
81