1 /* 2 * Copyright 2025 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.accessibility; 18 19 import static android.view.accessibility.AccessibilityManager.AUTOCLICK_REVERT_TO_LEFT_CLICK_DEFAULT; 20 21 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; 22 import static com.android.settings.accessibility.AccessibilityUtil.State.ON; 23 24 import static com.google.common.truth.Truth.assertThat; 25 26 import android.content.Context; 27 import android.platform.test.annotations.DisableFlags; 28 import android.platform.test.annotations.EnableFlags; 29 import android.platform.test.flag.junit.SetFlagsRule; 30 import android.provider.Settings; 31 32 import androidx.test.core.app.ApplicationProvider; 33 34 import com.android.settings.core.BasePreferenceController; 35 36 import org.junit.Before; 37 import org.junit.Rule; 38 import org.junit.Test; 39 import org.junit.runner.RunWith; 40 import org.robolectric.RobolectricTestRunner; 41 42 /** Tests for {@link ToggleAutoclickRevertToLeftClickController}. */ 43 @RunWith(RobolectricTestRunner.class) 44 public class ToggleAutoclickRevertToLeftClickControllerTest { 45 46 private static final String PREFERENCE_KEY = 47 "accessibility_control_autoclick_revert_to_left_click"; 48 49 @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 50 private final Context mContext = ApplicationProvider.getApplicationContext(); 51 private ToggleAutoclickRevertToLeftClickController mController; 52 53 @Before setUp()54 public void setUp() { 55 mController = 56 new ToggleAutoclickRevertToLeftClickController(mContext, PREFERENCE_KEY); 57 } 58 59 @Test 60 @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) getAvailabilityStatus_availableWhenFlagOn()61 public void getAvailabilityStatus_availableWhenFlagOn() { 62 assertThat(mController.getAvailabilityStatus()) 63 .isEqualTo(BasePreferenceController.AVAILABLE); 64 } 65 66 @Test 67 @DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) getAvailabilityStatus_conditionallyUnavailableWhenFlagOn()68 public void getAvailabilityStatus_conditionallyUnavailableWhenFlagOn() { 69 assertThat(mController.getAvailabilityStatus()) 70 .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE); 71 } 72 73 @Test isChecked_matchesSetting()74 public void isChecked_matchesSetting() { 75 assertThat(mController.isChecked()).isEqualTo(readSetting() == ON); 76 } 77 78 @Test setChecked_true_updatesSetting()79 public void setChecked_true_updatesSetting() { 80 mController.setChecked(true); 81 assertThat(readSetting()).isEqualTo(ON); 82 } 83 84 @Test setChecked_false_updatesSetting()85 public void setChecked_false_updatesSetting() { 86 mController.setChecked(false); 87 assertThat(readSetting()).isEqualTo(OFF); 88 } 89 readSetting()90 private int readSetting() { 91 return Settings.Secure.getInt(mContext.getContentResolver(), 92 Settings.Secure.ACCESSIBILITY_AUTOCLICK_REVERT_TO_LEFT_CLICK, 93 AUTOCLICK_REVERT_TO_LEFT_CLICK_DEFAULT ? ON : OFF); 94 } 95 } 96