1 /* 2 * Copyright (C) 2021 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.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON; 20 import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import static org.mockito.Mockito.when; 25 26 import android.content.Context; 27 import android.content.res.Resources; 28 import android.icu.text.MessageFormat; 29 import android.text.Html; 30 31 import androidx.preference.PreferenceScreen; 32 import androidx.test.core.app.ApplicationProvider; 33 34 import com.android.settings.R; 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.mockito.Mock; 41 import org.mockito.Spy; 42 import org.mockito.junit.MockitoJUnit; 43 import org.mockito.junit.MockitoRule; 44 import org.robolectric.RobolectricTestRunner; 45 46 /** Tests for {@link AccessibilityButtonFooterPreferenceController}. */ 47 @RunWith(RobolectricTestRunner.class) 48 public class AccessibilityButtonFooterPreferenceControllerTest { 49 50 @Rule 51 public final MockitoRule mockito = MockitoJUnit.rule(); 52 @Spy 53 private final Context mContext = ApplicationProvider.getApplicationContext(); 54 @Spy 55 private final Resources mResources = mContext.getResources(); 56 @Mock 57 private PreferenceScreen mScreen; 58 private AccessibilityButtonFooterPreferenceController mController; 59 private AccessibilityFooterPreference mPreference; 60 61 @Before setUp()62 public void setUp() { 63 mController = new AccessibilityButtonFooterPreferenceController(mContext, "test_key"); 64 mPreference = new AccessibilityFooterPreference(mContext); 65 mPreference.setKey("test_key"); 66 67 when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); 68 when(mContext.getResources()).thenReturn(mResources); 69 } 70 71 @Test displayPreference_navigationGestureEnabled_setCorrectTitle()72 public void displayPreference_navigationGestureEnabled_setCorrectTitle() { 73 when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode)) 74 .thenReturn(NAV_BAR_MODE_GESTURAL); 75 76 mController.displayPreference(mScreen); 77 78 assertThat(mPreference.getTitle().toString()).isEqualTo( 79 Html.fromHtml( 80 MessageFormat.format(mContext.getString( 81 R.string.accessibility_button_gesture_description), 1, 2, 3), 82 Html.FROM_HTML_MODE_COMPACT).toString()); 83 } 84 85 @Test displayPreference_navigationGestureDisabled_setCorrectTitle()86 public void displayPreference_navigationGestureDisabled_setCorrectTitle() { 87 when(mResources.getInteger( 88 com.android.internal.R.integer.config_navBarInteractionMode)).thenReturn( 89 NAV_BAR_MODE_2BUTTON); 90 91 mController.displayPreference(mScreen); 92 93 assertThat(mPreference.getTitle().toString()).isEqualTo( 94 Html.fromHtml( 95 MessageFormat.format( 96 mContext.getString( 97 R.string.accessibility_button_description), 1, 2, 3), 98 Html.FROM_HTML_MODE_COMPACT).toString()); 99 } 100 } 101