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