• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.provider.Settings.Secure.ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR;
20  import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON;
21  import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
22  
23  import static com.android.settings.core.BasePreferenceController.AVAILABLE;
24  import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
25  
26  import static com.google.common.truth.Truth.assertThat;
27  
28  import static org.mockito.Mockito.when;
29  
30  import android.content.ContentResolver;
31  import android.content.Context;
32  import android.content.res.Resources;
33  import android.provider.Settings;
34  
35  import androidx.preference.ListPreference;
36  import androidx.test.core.app.ApplicationProvider;
37  
38  import org.junit.Before;
39  import org.junit.Rule;
40  import org.junit.Test;
41  import org.junit.runner.RunWith;
42  import org.mockito.Spy;
43  import org.mockito.junit.MockitoJUnit;
44  import org.mockito.junit.MockitoRule;
45  import org.robolectric.RobolectricTestRunner;
46  
47  /** Tests for {@link AccessibilityButtonLocationPreferenceController}. */
48  @RunWith(RobolectricTestRunner.class)
49  public class AccessibilityButtonLocationPreferenceControllerTest {
50  
51      @Rule
52      public final MockitoRule mockito = MockitoJUnit.rule();
53  
54      @Spy
55      private final Context mContext = ApplicationProvider.getApplicationContext();
56      @Spy
57      private final Resources mResources = mContext.getResources();
58      private final ContentResolver mContentResolver = mContext.getContentResolver();
59      private final ListPreference mListPreference = new ListPreference(mContext);
60      private AccessibilityButtonLocationPreferenceController mController;
61  
62  
63      @Before
setUp()64      public void setUp() {
65          mController = new AccessibilityButtonLocationPreferenceController(mContext,
66                  "test_key");
67          when(mContext.getResources()).thenReturn(mResources);
68      }
69  
70      @Test
getAvailabilityStatus_navigationGestureEnabled_returnConditionallyUnavailable()71      public void getAvailabilityStatus_navigationGestureEnabled_returnConditionallyUnavailable() {
72          when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
73                  .thenReturn(NAV_BAR_MODE_GESTURAL);
74  
75          assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
76      }
77  
78      @Test
getAvailabilityStatus_navigationGestureDisabled_returnAvailable()79      public void getAvailabilityStatus_navigationGestureDisabled_returnAvailable() {
80          when(mResources.getInteger(com.android.internal.R.integer.config_navBarInteractionMode))
81                  .thenReturn(NAV_BAR_MODE_2BUTTON);
82  
83          assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
84      }
85  
86      @Test
updateState_a11yBtnModeNavigationBar_navigationBarValue()87      public void updateState_a11yBtnModeNavigationBar_navigationBarValue() {
88          Settings.Secure.putInt(mContentResolver, Settings.Secure.ACCESSIBILITY_BUTTON_MODE,
89                  ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
90  
91          mController.updateState(mListPreference);
92  
93          final String navigationBarValue = String.valueOf(ACCESSIBILITY_BUTTON_MODE_NAVIGATION_BAR);
94          assertThat(mListPreference.getValue()).isEqualTo(navigationBarValue);
95      }
96  }
97