1 /* 2 * Copyright (C) 2021 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.core.BasePreferenceController; 26 import com.android.settingslib.widget.RadioButtonPreference; 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 OneHandedActionPullDownPrefControllerTest { 36 37 private static final String KEY = "gesture_one_handed_action_pull_screen_down"; 38 39 private Context mContext; 40 private OneHandedSettingsUtils mUtils; 41 private OneHandedActionPullDownPrefController mController; 42 private RadioButtonPreference mPreference; 43 44 @Before setUp()45 public void setUp() { 46 mContext = RuntimeEnvironment.application; 47 mUtils = new OneHandedSettingsUtils(mContext); 48 mController = new OneHandedActionPullDownPrefController(mContext, KEY); 49 mPreference = new RadioButtonPreference(mContext); 50 OneHandedSettingsUtils.setUserId(UserHandle.myUserId()); 51 } 52 53 @Test updateState_showNotificationEnabled_shouldUnchecked()54 public void updateState_showNotificationEnabled_shouldUnchecked() { 55 OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, true); 56 57 mController.updateState(mPreference); 58 assertThat(mPreference.isChecked()).isFalse(); 59 } 60 61 @Test updateState_showNotificationDisabled_shouldChecked()62 public void updateState_showNotificationDisabled_shouldChecked() { 63 OneHandedSettingsUtils.setSwipeDownNotificationEnabled(mContext, false); 64 65 mController.updateState(mPreference); 66 assertThat(mPreference.isChecked()).isTrue(); 67 } 68 69 @Test getAvailabilityStatus_setOneHandedModeDisabled_shouldDisabled()70 public void getAvailabilityStatus_setOneHandedModeDisabled_shouldDisabled() { 71 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 72 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false); 73 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 74 75 assertThat(mController.getAvailabilityStatus()) 76 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 77 } 78 79 @Test getAvailabilityStatus_setNavi3ButtonMode_shouldDisabled()80 public void getAvailabilityStatus_setNavi3ButtonMode_shouldDisabled() { 81 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 82 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true); 83 mUtils.setNavigationBarMode(mContext, "0" /* 3 button */); 84 85 assertThat(mController.getAvailabilityStatus()) 86 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 87 } 88 89 @Test getAvailabilityStatus_setNaviGesturalMode_shouldEnabled()90 public void getAvailabilityStatus_setNaviGesturalMode_shouldEnabled() { 91 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 92 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true); 93 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 94 95 assertThat(mController.getAvailabilityStatus()) 96 .isEqualTo(BasePreferenceController.AVAILABLE); 97 } 98 99 @Test getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldDisabled()100 public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldDisabled() { 101 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); 102 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true); 103 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 104 105 assertThat(mController.getAvailabilityStatus()) 106 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 107 } 108 109 @Test getAvailabilityStatus_setShortcutEnabled_shouldEnabled()110 public void getAvailabilityStatus_setShortcutEnabled_shouldEnabled() { 111 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 112 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false); 113 mUtils.setNavigationBarMode(mContext, "0" /* 3-button mode */); 114 mUtils.setShortcutEnabled(mContext, true); 115 116 assertThat(mController.getAvailabilityStatus()) 117 .isEqualTo(BasePreferenceController.AVAILABLE); 118 } 119 120 @Test getAvailabilityStatus_setShortcutDisabled_shouldDisabled()121 public void getAvailabilityStatus_setShortcutDisabled_shouldDisabled() { 122 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 123 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, false); 124 mUtils.setNavigationBarMode(mContext, "0" /* 3-button mode */); 125 mUtils.setShortcutEnabled(mContext, false); 126 127 assertThat(mController.getAvailabilityStatus()) 128 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 129 } 130 } 131