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 @RunWith(AndroidJUnit4.class) 35 public class FontWeightAdjustmentPreferenceControllerTest { 36 private static final int ON = FontWeightAdjustmentPreferenceController.BOLD_TEXT_ADJUSTMENT; 37 private static final int OFF = 0; 38 39 private Context mContext; 40 private SwitchPreference mPreference; 41 private FontWeightAdjustmentPreferenceController mController; 42 43 @Before setUp()44 public void setUp() { 45 mContext = ApplicationProvider.getApplicationContext(); 46 mPreference = new SwitchPreference(mContext); 47 mController = new FontWeightAdjustmentPreferenceController( 48 mContext, "font_weight_adjustment"); 49 } 50 51 @Test getAvailabilityStatus_byDefault_shouldReturnAvailable()52 public void getAvailabilityStatus_byDefault_shouldReturnAvailable() { 53 assertThat(mController.getAvailabilityStatus()).isEqualTo( 54 BasePreferenceController.AVAILABLE); 55 } 56 57 @Test isChecked_enabledBoldText_shouldReturnTrue()58 public void isChecked_enabledBoldText_shouldReturnTrue() { 59 Settings.Secure.putInt(mContext.getContentResolver(), 60 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, ON); 61 62 mController.updateState(mPreference); 63 64 assertThat(mController.isChecked()).isTrue(); 65 assertThat(mPreference.isChecked()).isTrue(); 66 } 67 68 @Test isChecked_disabledBoldText_shouldReturnFalse()69 public void isChecked_disabledBoldText_shouldReturnFalse() { 70 Settings.Secure.putInt(mContext.getContentResolver(), 71 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF); 72 73 mController.updateState(mPreference); 74 75 assertThat(mController.isChecked()).isFalse(); 76 assertThat(mPreference.isChecked()).isFalse(); 77 } 78 79 @Test setChecked_setTrue_shouldEnableBoldText()80 public void setChecked_setTrue_shouldEnableBoldText() { 81 mController.setChecked(true); 82 83 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 84 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(ON); 85 } 86 87 @Test setChecked_setFalse_shouldDisableBoldText()88 public void setChecked_setFalse_shouldDisableBoldText() { 89 mController.setChecked(false); 90 91 assertThat(Settings.Secure.getInt(mContext.getContentResolver(), 92 Settings.Secure.FONT_WEIGHT_ADJUSTMENT, OFF)).isEqualTo(OFF); 93 } 94 } 95