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 static org.mockito.ArgumentMatchers.any; 22 import static org.mockito.ArgumentMatchers.eq; 23 import static org.mockito.Mockito.verify; 24 25 import android.app.settings.SettingsEnums; 26 import android.content.Context; 27 import android.provider.Settings; 28 29 import androidx.test.core.app.ApplicationProvider; 30 31 import com.android.settings.R; 32 import com.android.settings.core.BasePreferenceController; 33 import com.android.settings.testutils.FakeFeatureFactory; 34 35 import org.junit.Before; 36 import org.junit.Rule; 37 import org.junit.Test; 38 import org.junit.runner.RunWith; 39 import org.mockito.junit.MockitoJUnit; 40 import org.mockito.junit.MockitoRule; 41 import org.robolectric.RobolectricTestRunner; 42 43 /** Tests for {@link TrackpadRecentAppsPreferenceController} */ 44 @RunWith(RobolectricTestRunner.class) 45 public class TrackpadRecentAppsPreferenceControllerTest { 46 @Rule 47 public MockitoRule rule = MockitoJUnit.rule(); 48 49 private static final String PREFERENCE_KEY = "gesture_recent_apps"; 50 private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_OVERVIEW_ENABLED; 51 52 private Context mContext; 53 private TrackpadRecentAppsPreferenceController mController; 54 private FakeFeatureFactory mFeatureFactory; 55 56 @Before setUp()57 public void setUp() { 58 mContext = ApplicationProvider.getApplicationContext(); 59 mFeatureFactory = FakeFeatureFactory.setupForTest(); 60 mController = new TrackpadRecentAppsPreferenceController(mContext, PREFERENCE_KEY); 61 } 62 63 @Test getAvailabilityStatus_expected()64 public void getAvailabilityStatus_expected() { 65 assertThat(mController.getAvailabilityStatus()) 66 .isEqualTo(BasePreferenceController.AVAILABLE); 67 } 68 69 @Test getSliceHighlightMenuRes_expected()70 public void getSliceHighlightMenuRes_expected() { 71 assertThat(mController.getSliceHighlightMenuRes()).isEqualTo(R.string.menu_key_system); 72 } 73 74 @Test setChecked_true_shouldReturn1()75 public void setChecked_true_shouldReturn1() { 76 mController.setChecked(true); 77 78 int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1); 79 80 assertThat(result).isEqualTo(1); 81 verify(mFeatureFactory.metricsFeatureProvider).action( 82 any(), 83 eq(SettingsEnums.ACTION_GESTURE_RECENT_APPS_CHANGED), 84 eq(true)); 85 } 86 87 @Test setChecked_false_shouldReturn0()88 public void setChecked_false_shouldReturn0() { 89 mController.setChecked(false); 90 91 int result = Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1); 92 93 assertThat(result).isEqualTo(0); 94 verify(mFeatureFactory.metricsFeatureProvider).action( 95 any(), 96 eq(SettingsEnums.ACTION_GESTURE_RECENT_APPS_CHANGED), 97 eq(false)); 98 } 99 100 @Test isChecked_providerPutInt1_returnTrue()101 public void isChecked_providerPutInt1_returnTrue() { 102 Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 1); 103 104 boolean result = mController.isChecked(); 105 106 assertThat(result).isTrue(); 107 } 108 109 @Test isChecked_providerPutInt0_returnFalse()110 public void isChecked_providerPutInt0_returnFalse() { 111 Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, 0); 112 113 boolean result = mController.isChecked(); 114 115 assertThat(result).isFalse(); 116 } 117 } 118