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