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 29 import androidx.preference.PreferenceScreen; 30 import androidx.test.core.app.ApplicationProvider; 31 32 import com.android.settings.R; 33 34 import org.junit.Before; 35 import org.junit.Rule; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.mockito.Mock; 39 import org.mockito.Spy; 40 import org.mockito.junit.MockitoJUnit; 41 import org.mockito.junit.MockitoRule; 42 import org.robolectric.RobolectricTestRunner; 43 44 /** Tests for {@link AccessibilityButtonFooterPreferenceController}. */ 45 @RunWith(RobolectricTestRunner.class) 46 public class AccessibilityButtonFooterPreferenceControllerTest { 47 48 @Rule 49 public final MockitoRule mockito = MockitoJUnit.rule(); 50 @Spy 51 private final Context mContext = ApplicationProvider.getApplicationContext(); 52 @Spy 53 private final Resources mResources = mContext.getResources(); 54 @Mock 55 private PreferenceScreen mScreen; 56 private AccessibilityButtonFooterPreferenceController mController; 57 private AccessibilityFooterPreference mPreference; 58 59 @Before setUp()60 public void setUp() { 61 mController = new AccessibilityButtonFooterPreferenceController(mContext, "test_key"); 62 mPreference = new AccessibilityFooterPreference(mContext); 63 mPreference.setKey("test_key"); 64 65 when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); 66 when(mContext.getResources()).thenReturn(mResources); 67 } 68 69 @Test displayPreference_navigationGestureEnabled_setCorrectTitle()70 public void displayPreference_navigationGestureEnabled_setCorrectTitle() { 71 when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode)) 72 .thenReturn(NAV_BAR_MODE_GESTURAL); 73 74 mController.displayPreference(mScreen); 75 76 assertThat(mPreference.getTitle()).isEqualTo( 77 mContext.getText(R.string.accessibility_button_gesture_description)); 78 } 79 80 @Test displayPreference_navigationGestureDisabled_setCorrectTitle()81 public void displayPreference_navigationGestureDisabled_setCorrectTitle() { 82 when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode)) 83 .thenReturn(NAV_BAR_MODE_2BUTTON); 84 85 mController.displayPreference(mScreen); 86 87 assertThat(mPreference.getTitle()).isEqualTo( 88 mContext.getText(R.string.accessibility_button_description)); 89 } 90 } 91