1 /* 2 * Copyright (C) 2019 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.AccessibilityUtil.State.OFF; 20 import static com.android.settings.accessibility.AccessibilityUtil.State.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.test.core.app.ApplicationProvider; 28 29 import com.android.settings.R; 30 import com.android.settings.core.BasePreferenceController; 31 32 import org.junit.Before; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.robolectric.RobolectricTestRunner; 36 37 /** Tests for {@link CaptioningPreferenceController}. */ 38 @RunWith(RobolectricTestRunner.class) 39 public class CaptioningPreferenceControllerTest { 40 41 private Context mContext; 42 private CaptioningPreferenceController mController; 43 44 @Before setUp()45 public void setUp() { 46 mContext = ApplicationProvider.getApplicationContext(); 47 mController = new CaptioningPreferenceController(mContext, "captioning_pref"); 48 } 49 50 @Test getAvailabilityStatus_byDefault_shouldReturnAvailable()51 public void getAvailabilityStatus_byDefault_shouldReturnAvailable() { 52 assertThat(mController.getAvailabilityStatus()) 53 .isEqualTo(BasePreferenceController.AVAILABLE); 54 } 55 56 @Test getSummary_enabledCaptions_shouldReturnOnSummary()57 public void getSummary_enabledCaptions_shouldReturnOnSummary() { 58 setCaptioningEnabled(true); 59 60 assertThat(mController.getSummary()).isEqualTo( 61 mContext.getText(R.string.show_captions_enabled)); 62 } 63 64 @Test getSummary_disabledCaptions_shouldReturnOffSummary()65 public void getSummary_disabledCaptions_shouldReturnOffSummary() { 66 setCaptioningEnabled(false); 67 68 assertThat(mController.getSummary()).isEqualTo( 69 mContext.getText(R.string.show_captions_disabled)); 70 } 71 setCaptioningEnabled(boolean enabled)72 private void setCaptioningEnabled(boolean enabled) { 73 Settings.Secure.putInt(mContext.getContentResolver(), 74 Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, enabled ? ON : OFF); 75 } 76 } 77