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.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.provider.Settings; 23 24 import androidx.preference.SwitchPreference; 25 import androidx.test.core.app.ApplicationProvider; 26 import androidx.test.ext.junit.runners.AndroidJUnit4; 27 28 import com.android.settings.core.BasePreferenceController; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 34 /** 35 * Tests for {@link FontWeightAdjustmentPreferenceController}. 36 */ 37 @RunWith(AndroidJUnit4.class) 38 public class FontWeightAdjustmentPreferenceControllerTest { 39 private static final int ON = FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT; 40 private static final int OFF = 0; 41 42 private Context mContext; 43 private SwitchPreference mPreference; 44 private FontWeightAdjustmentPreferenceController mController; 45 46 @Before setUp()47 public void setUp() { 48 mContext = ApplicationProvider.getApplicationContext(); 49 mPreference = new SwitchPreference(mContext); 50 mController = new FontWeightAdjustmentPreferenceController( 51 mContext, "font_weight_adjustment"); 52 } 53 54 @Test getAvailabilityStatus_byDefault_shouldReturnAvailable()55 public void getAvailabilityStatus_byDefault_shouldReturnAvailable() { 56 assertThat(mController.getAvailabilityStatus()).isEqualTo( 57 BasePreferenceController.AVAILABLE); 58 } 59 60 @Test isChecked_enabledBoldText_shouldReturnTrue()61 public void isChecked_enabledBoldText_shouldReturnTrue() { 62 Settings.Secure.putInt(mContext.getContentResolver(), 63 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, ON); 64 65 mController.updateState(mPreference); 66 67 assertThat(mController.isChecked()).isTrue(); 68 assertThat(mPreference.isChecked()).isTrue(); 69 } 70 71 @Test isChecked_disabledBoldText_shouldReturnFalse()72 public void isChecked_disabledBoldText_shouldReturnFalse() { 73 Settings.Secure.putInt(mContext.getContentResolver(), 74 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF); 75 76 mController.updateState(mPreference); 77 78 assertThat(mController.isChecked()).isFalse(); 79 assertThat(mPreference.isChecked()).isFalse(); 80 } 81 82 @Test setChecked_setTrue_shouldEnableBoldText()83 public void setChecked_setTrue_shouldEnableBoldText() { 84 mController.setChecked(true); 85 86 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 87 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(ON); 88 } 89 90 @Test setChecked_setFalse_shouldDisableBoldText()91 public void setChecked_setFalse_shouldDisableBoldText() { 92 mController.setChecked(false); 93 94 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 95 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF); 96 } 97 98 @Test resetState_shouldDisableBoldText()99 public void resetState_shouldDisableBoldText() { 100 mController.setChecked(true); 101 102 mController.resetState(); 103 104 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 105 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF); 106 } 107 } 108