1 /* 2 * Copyright (C) 2023 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.inputmethod; 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 26 import com.android.settings.R; 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 import org.robolectric.RobolectricTestRunner; 33 34 /** Tests for {@link TrackpadGoBackPreferenceController} */ 35 @RunWith(RobolectricTestRunner.class) 36 public class TrackpadGoBackPreferenceControllerTest { 37 38 private static final String PREFERENCE_KEY = "gesture_go_back"; 39 private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_BACK_ENABLED; 40 41 private Context mContext; 42 private TrackpadGoBackPreferenceController mController; 43 44 @Before setUp()45 public void setUp() { 46 mContext = ApplicationProvider.getApplicationContext(); 47 mController = new TrackpadGoBackPreferenceController(mContext, PREFERENCE_KEY); 48 } 49 50 @Test getAvailabilityStatus_expected()51 public void getAvailabilityStatus_expected() { 52 assertThat(mController.getAvailabilityStatus()) 53 .isEqualTo(BasePreferenceController.AVAILABLE); 54 } 55 56 @Test getSliceHighlightMenuRes_expected()57 public void getSliceHighlightMenuRes_expected() { 58 assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system); 59 } 60 61 @Test setChecked_true_shouldReturn1()62 public void setChecked_true_shouldReturn1() { 63 mController.setChecked(true); 64 65 int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1); 66 67 assertThat(result).isEqualTo(1); 68 } 69 70 @Test setChecked_false_shouldReturn0()71 public void setChecked_false_shouldReturn0() { 72 mController.setChecked(false); 73 74 int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1); 75 76 assertThat(result).isEqualTo(0); 77 } 78 79 @Test isChecked_providerPutInt1_returnTrue()80 public void isChecked_providerPutInt1_returnTrue() { 81 Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1); 82 83 boolean result = mController.isChecked(); 84 85 assertThat(result).isTrue(); 86 } 87 88 @Test isChecked_providerPutInt0_returnFalse()89 public void isChecked_providerPutInt0_returnFalse() { 90 Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0); 91 92 boolean result = mController.isChecked(); 93 94 assertThat(result).isFalse(); 95 } 96 } 97