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.gestures; 18 19 import static com.android.settings.core.BasePreferenceController.AVAILABLE; 20 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE; 21 22 import static com.google.common.truth.Truth.assertThat; 23 24 import static org.mockito.ArgumentMatchers.anyInt; 25 import static org.mockito.Mockito.when; 26 27 import android.content.Context; 28 import android.hardware.display.AmbientDisplayConfiguration; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 import org.robolectric.RobolectricTestRunner; 36 37 @RunWith(RobolectricTestRunner.class) 38 public class TapScreenGesturePreferenceControllerTest { 39 40 private static final String KEY_WAKE_LOCK_SCREEN = "gesture_tap_screen"; 41 42 @Mock 43 private Context mContext; 44 @Mock 45 private AmbientDisplayConfiguration mAmbientDisplayConfiguration; 46 47 private TapScreenGesturePreferenceController mController; 48 49 @Before setUp()50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 mController = new TapScreenGesturePreferenceController(mContext, KEY_WAKE_LOCK_SCREEN); 53 mController.setConfig(mAmbientDisplayConfiguration); 54 } 55 56 @Test testIsChecked_configIsSet_shouldReturnTrue()57 public void testIsChecked_configIsSet_shouldReturnTrue() { 58 // Set the setting to be enabled. 59 when(mAmbientDisplayConfiguration.tapGestureEnabled(anyInt())).thenReturn(true); 60 assertThat(mController.isChecked()).isTrue(); 61 } 62 63 @Test testIsChecked_configIsNotSet_shouldReturnFalse()64 public void testIsChecked_configIsNotSet_shouldReturnFalse() { 65 // Set the setting to be disabled. 66 when(mAmbientDisplayConfiguration.tapGestureEnabled(anyInt())).thenReturn(false); 67 assertThat(mController.isChecked()).isFalse(); 68 } 69 70 @Test getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE()71 public void getAvailabilityStatus_gestureNotSupported_UNSUPPORTED_ON_DEVICE() { 72 when(mAmbientDisplayConfiguration.tapSensorAvailable()).thenReturn(false); 73 final int availabilityStatus = mController.getAvailabilityStatus(); 74 75 assertThat(availabilityStatus).isEqualTo(UNSUPPORTED_ON_DEVICE); 76 } 77 78 @Test getAvailabilityStatus_gestureSupported_AVAILABLE()79 public void getAvailabilityStatus_gestureSupported_AVAILABLE() { 80 when(mAmbientDisplayConfiguration.tapSensorAvailable()).thenReturn(true); 81 final int availabilityStatus = mController.getAvailabilityStatus(); 82 83 assertThat(availabilityStatus).isEqualTo(AVAILABLE); 84 } 85 86 @Test isSliceable()87 public void isSliceable() { 88 final TapScreenGesturePreferenceController controller = 89 new TapScreenGesturePreferenceController(mContext, KEY_WAKE_LOCK_SCREEN); 90 assertThat(controller.isSliceable()).isTrue(); 91 } 92 93 @Test isPublicSlice_returnTrue()94 public void isPublicSlice_returnTrue() { 95 assertThat(mController.isPublicSlice()).isTrue(); 96 } 97 } 98