1 /* 2 * Copyright 2024 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.inputmethod; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.hardware.input.InputSettings; 23 import android.os.UserHandle; 24 import android.platform.test.annotations.DisableFlags; 25 import android.platform.test.annotations.EnableFlags; 26 import android.platform.test.flag.junit.SetFlagsRule; 27 import android.provider.Settings; 28 29 import androidx.test.core.app.ApplicationProvider; 30 31 import com.android.hardware.input.Flags; 32 import com.android.settings.core.BasePreferenceController; 33 34 import org.junit.Before; 35 import org.junit.Rule; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.robolectric.RobolectricTestRunner; 39 import org.robolectric.annotation.Config; 40 41 /** Tests for {@link MouseReverseVerticalScrollingPreferenceController} */ 42 @RunWith(RobolectricTestRunner.class) 43 @Config(shadows = { 44 com.android.settings.testutils.shadow.ShadowSystemSettings.class, 45 }) 46 public class MouseSwapPrimaryButtonPreferenceControllerTest { 47 @Rule 48 public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 49 50 private static final String PREFERENCE_KEY = "mouse_swap_primary_button"; 51 private static final String SETTING_KEY = Settings.System.MOUSE_SWAP_PRIMARY_BUTTON; 52 53 private Context mContext; 54 private MouseSwapPrimaryButtonPreferenceController mController; 55 56 @Before setUp()57 public void setUp() { 58 mContext = ApplicationProvider.getApplicationContext(); 59 mController = new MouseSwapPrimaryButtonPreferenceController( 60 mContext, PREFERENCE_KEY); 61 } 62 63 @Test 64 @EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) getAvailabilityStatus_expected()65 public void getAvailabilityStatus_expected() { 66 assertThat(mController.getAvailabilityStatus()) 67 .isEqualTo(BasePreferenceController.AVAILABLE); 68 } 69 70 @Test 71 @DisableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) getAvailabilityStatus_flagIsDisabled_notSupport()72 public void getAvailabilityStatus_flagIsDisabled_notSupport() { 73 assertThat(mController.getAvailabilityStatus()) 74 .isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE); 75 } 76 77 @Test 78 @EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) setChecked_true_shouldReturn1()79 public void setChecked_true_shouldReturn1() { 80 mController.setChecked(true); 81 82 boolean isEnabled = InputSettings.isMouseSwapPrimaryButtonEnabled(mContext); 83 assertThat(isEnabled).isTrue(); 84 } 85 86 @Test 87 @EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) setChecked_false_shouldReturn0()88 public void setChecked_false_shouldReturn0() { 89 mController.setChecked(false); 90 91 boolean isEnabled = InputSettings.isMouseSwapPrimaryButtonEnabled(mContext); 92 assertThat(isEnabled).isFalse(); 93 } 94 95 @Test 96 @EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) isChecked_providerPutInt1_returnTrue()97 public void isChecked_providerPutInt1_returnTrue() { 98 Settings.System.putIntForUser( 99 mContext.getContentResolver(), 100 SETTING_KEY, 101 1, 102 UserHandle.USER_CURRENT); 103 104 boolean result = mController.isChecked(); 105 106 assertThat(result).isTrue(); 107 } 108 109 @Test 110 @EnableFlags(Flags.FLAG_MOUSE_SWAP_PRIMARY_BUTTON) isChecked_providerPutInt0_returnFalse()111 public void isChecked_providerPutInt0_returnFalse() { 112 Settings.System.putIntForUser( 113 mContext.getContentResolver(), 114 SETTING_KEY, 115 0, 116 UserHandle.USER_CURRENT); 117 118 boolean result = mController.isChecked(); 119 120 assertThat(result).isFalse(); 121 } 122 } 123