1 /* 2 * Copyright (C) 2020 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 com.android.settings.accessibility.LargePointerIconPreferenceController.OFF; 20 import static com.android.settings.accessibility.LargePointerIconPreferenceController.ON; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import android.content.Context; 25 import android.provider.Settings; 26 27 import androidx.preference.SwitchPreference; 28 import androidx.test.core.app.ApplicationProvider; 29 import androidx.test.ext.junit.runners.AndroidJUnit4; 30 31 import com.android.settings.core.BasePreferenceController; 32 33 import org.junit.Before; 34 import org.junit.Test; 35 import org.junit.runner.RunWith; 36 37 @RunWith(AndroidJUnit4.class) 38 public class LargePointerIconPreferenceControllerTest { 39 40 private static final int UNKNOWN = -1; 41 42 private Context mContext; 43 private SwitchPreference mPreference; 44 private LargePointerIconPreferenceController mController; 45 46 @Before setUp()47 public void setUp() { 48 mContext = ApplicationProvider.getApplicationContext(); 49 mPreference = new SwitchPreference(mContext); 50 mController = new LargePointerIconPreferenceController(mContext, "large_pointer"); 51 } 52 53 @Test getAvailabilityStatus_shouldReturnAvailable()54 public void getAvailabilityStatus_shouldReturnAvailable() { 55 assertThat(mController.getAvailabilityStatus()).isEqualTo( 56 BasePreferenceController.AVAILABLE); 57 } 58 59 @Test isChecked_enabledLargePointer_shouldReturnTrue()60 public void isChecked_enabledLargePointer_shouldReturnTrue() { 61 Settings.Secure.putInt(mContext.getContentResolver(), 62 Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, ON); 63 64 mController.updateState(mPreference); 65 66 assertThat(mController.isChecked()).isTrue(); 67 assertThat(mPreference.isChecked()).isTrue(); 68 } 69 70 @Test isChecked_disabledLargePointer_shouldReturnFalse()71 public void isChecked_disabledLargePointer_shouldReturnFalse() { 72 Settings.Secure.putInt(mContext.getContentResolver(), 73 Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, OFF); 74 75 mController.updateState(mPreference); 76 77 assertThat(mController.isChecked()).isFalse(); 78 assertThat(mPreference.isChecked()).isFalse(); 79 } 80 81 @Test setChecked_enabled_shouldEnableLargePointer()82 public void setChecked_enabled_shouldEnableLargePointer() { 83 mController.setChecked(true); 84 85 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 86 Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, UNKNOWN)).isEqualTo(ON); 87 } 88 89 @Test setChecked_disabled_shouldDisableLargePointer()90 public void setChecked_disabled_shouldDisableLargePointer() { 91 mController.setChecked(false); 92 93 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 94 Settings.Secure.ACCESSIBILITY_LARGE_POINTER_ICON, UNKNOWN)).isEqualTo(OFF); 95 } 96 } 97