1 /* 2 * Copyright (C) 2020 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 com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.provider.Settings; 23 24 import androidx.test.core.app.ApplicationProvider; 25 import androidx.test.ext.junit.runners.AndroidJUnit4; 26 27 import com.android.settings.core.BasePreferenceController; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 @RunWith(AndroidJUnit4.class) 34 public class SelectLongPressTimeoutPreferenceControllerTest { 35 private static final int VALID_VALUE = 1500; 36 private static final int INVALID_VALUE = 0; 37 private static final int DEFAULT_VALUE = 400; 38 39 private Context mContext; 40 private SelectLongPressTimeoutPreferenceController mController; 41 42 @Before setUp()43 public void setUp() { 44 mContext = ApplicationProvider.getApplicationContext(); 45 mController = new SelectLongPressTimeoutPreferenceController(mContext, "press_timeout"); 46 } 47 48 @Test getAvailabilityStatus_byDefault_shouldReturnAvailable()49 public void getAvailabilityStatus_byDefault_shouldReturnAvailable() { 50 assertThat(mController.getAvailabilityStatus()) 51 .isEqualTo(BasePreferenceController.AVAILABLE); 52 } 53 54 @Test getSummary_byDefault_shouldReturnShort()55 public void getSummary_byDefault_shouldReturnShort() { 56 Settings.Secure.putInt(mContext.getContentResolver(), 57 Settings.Secure.LONG_PRESS_TIMEOUT, DEFAULT_VALUE); 58 final String expected = "Short"; 59 60 assertThat(mController.getSummary()).isEqualTo(expected); 61 } 62 63 @Test getSummary_validValue_shouldReturnLong()64 public void getSummary_validValue_shouldReturnLong() { 65 Settings.Secure.putInt(mContext.getContentResolver(), 66 Settings.Secure.LONG_PRESS_TIMEOUT, VALID_VALUE); 67 final String expected = "Long"; 68 69 assertThat(mController.getSummary()).isEqualTo(expected); 70 } 71 72 @Test getSummary_invalidValue_shouldReturnNull()73 public void getSummary_invalidValue_shouldReturnNull() { 74 Settings.Secure.putInt(mContext.getContentResolver(), 75 Settings.Secure.LONG_PRESS_TIMEOUT, INVALID_VALUE); 76 77 assertThat(mController.getSummary()).isNull(); 78 } 79 } 80