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