1 /* 2 * Copyright (C) 2016 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.gestures; 18 19 import android.content.Context; 20 import android.provider.Settings; 21 22 import com.android.settings.SettingsRobolectricTestRunner; 23 import com.android.settings.TestConfig; 24 25 import com.android.settings.search2.InlineSwitchPayload; 26 import com.android.settings.search2.ResultPayload; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 import org.mockito.Answers; 31 import org.mockito.Mock; 32 import org.mockito.MockitoAnnotations; 33 import org.robolectric.annotation.Config; 34 import org.robolectric.shadows.ShadowApplication; 35 36 import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED; 37 import static com.google.common.truth.Truth.assertThat; 38 import static org.mockito.Mockito.when; 39 40 @RunWith(SettingsRobolectricTestRunner.class) 41 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 42 public class SwipeToNotificationPreferenceControllerTest { 43 44 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 45 private Context mContext; 46 47 private SwipeToNotificationPreferenceController mController; 48 private static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint"; 49 50 @Before setUp()51 public void setUp() { 52 MockitoAnnotations.initMocks(this); 53 mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN); 54 } 55 56 @Test isAvailable_configIsTrue_shouldReturnTrue()57 public void isAvailable_configIsTrue_shouldReturnTrue() { 58 when(mContext.getResources(). 59 getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys)) 60 .thenReturn(true); 61 62 assertThat(mController.isAvailable()).isTrue(); 63 } 64 65 @Test isAvailable_configIsFalse_shouldReturnFalse()66 public void isAvailable_configIsFalse_shouldReturnFalse() { 67 when(mContext.getResources(). 68 getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys)) 69 .thenReturn(false); 70 71 assertThat(mController.isAvailable()).isFalse(); 72 } 73 74 @Test testSwitchEnabled_configIsSet_shouldReturnTrue()75 public void testSwitchEnabled_configIsSet_shouldReturnTrue() { 76 // Set the setting to be enabled. 77 final Context context = ShadowApplication.getInstance().getApplicationContext(); 78 Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1); 79 mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN); 80 81 assertThat(mController.isSwitchPrefEnabled()).isTrue(); 82 } 83 84 @Test testSwitchEnabled_configIsNotSet_shouldReturnFalse()85 public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() { 86 // Set the setting to be disabled. 87 final Context context = ShadowApplication.getInstance().getApplicationContext(); 88 Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0); 89 mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN); 90 91 assertThat(mController.isSwitchPrefEnabled()).isFalse(); 92 } 93 } 94