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 27 import org.junit.Before; 28 import org.junit.Ignore; 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 OneHandedMainSwitchPreferenceControllerTest { 36 37 private static final String KEY = "gesture_one_handed_mode_enabled_main_switch"; 38 39 private Context mContext; 40 private OneHandedSettingsUtils mUtils; 41 private OneHandedMainSwitchPreferenceController mController; 42 43 @Before setUp()44 public void setUp() { 45 mContext = RuntimeEnvironment.application; 46 mUtils = new OneHandedSettingsUtils(mContext); 47 mController = new OneHandedMainSwitchPreferenceController(mContext, KEY); 48 OneHandedSettingsUtils.setUserId(UserHandle.myUserId()); 49 } 50 51 @Test setChecked_setBoolean_checkIsTrueOrFalse()52 public void setChecked_setBoolean_checkIsTrueOrFalse() { 53 mController.setChecked(false); 54 assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isFalse(); 55 56 mController.setChecked(true); 57 assertThat(OneHandedSettingsUtils.isOneHandedModeEnabled(mContext)).isTrue(); 58 } 59 60 @Test isChecked_setOneHandedModeEnabled_shouldReturnTrue()61 public void isChecked_setOneHandedModeEnabled_shouldReturnTrue() { 62 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 63 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 64 OneHandedSettingsUtils.setOneHandedModeEnabled(mContext, true); 65 66 assertThat(mController.isChecked()).isTrue(); 67 } 68 69 @Test getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable()70 public void getAvailabilityStatus_setSupportOneHandedModeProperty_shouldAvailable() { 71 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 72 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 73 74 assertThat(mController.getAvailabilityStatus()) 75 .isEqualTo(BasePreferenceController.AVAILABLE); 76 } 77 78 @Test getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldDisabled()79 public void getAvailabilityStatus_unsetSupportOneHandedModeProperty_shouldDisabled() { 80 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); 81 mUtils.setNavigationBarMode(mContext, "2" /* fully gestural */); 82 83 assertThat(mController.getAvailabilityStatus()) 84 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 85 } 86 87 @Ignore("b/313541907") 88 @Test getAvailabilityStatus_set3ButtonMode_shouldDisabled()89 public void getAvailabilityStatus_set3ButtonMode_shouldDisabled() { 90 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 91 mUtils.setNavigationBarMode(mContext, "0" /* 3-button mode */); 92 93 assertThat(mController.getAvailabilityStatus()) 94 .isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING); 95 } 96 } 97