1 /* 2 * Copyright (C) 2022 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.android.settings.accessibility.ToggleAutoclickPreferenceFragment.KEY_AUTOCLICK_SHORTCUT_PREFERENCE; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import android.app.settings.SettingsEnums; 24 import android.content.Context; 25 import android.platform.test.annotations.DisableFlags; 26 import android.platform.test.annotations.EnableFlags; 27 import android.platform.test.flag.junit.SetFlagsRule; 28 29 import androidx.test.core.app.ApplicationProvider; 30 31 import com.android.settings.R; 32 import com.android.settings.testutils.XmlTestUtils; 33 34 import org.junit.Before; 35 import org.junit.Rule; 36 import org.junit.Test; 37 import org.junit.runner.RunWith; 38 import org.robolectric.RobolectricTestRunner; 39 40 import java.util.List; 41 42 /** Tests for {@link ToggleAutoclickPreferenceFragment}. */ 43 @RunWith(RobolectricTestRunner.class) 44 public class ToggleAutoclickPreferenceFragmentTest { 45 46 @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); 47 48 private final Context mContext = ApplicationProvider.getApplicationContext(); 49 private ToggleAutoclickPreferenceFragment mFragment; 50 51 @Before setUp()52 public void setUp() { 53 mFragment = new ToggleAutoclickPreferenceFragment(); 54 } 55 56 @Test getMetricsCategory_returnsCorrectCategory()57 public void getMetricsCategory_returnsCorrectCategory() { 58 assertThat(mFragment.getMetricsCategory()).isEqualTo( 59 SettingsEnums.ACCESSIBILITY_TOGGLE_AUTOCLICK); 60 } 61 62 @Test getPreferenceScreenResId_returnsCorrectXml()63 public void getPreferenceScreenResId_returnsCorrectXml() { 64 assertThat(mFragment.getPreferenceScreenResId()).isEqualTo( 65 R.xml.accessibility_autoclick_settings); 66 } 67 68 @Test getHelpResource_returnsCorrectHelpResource()69 public void getHelpResource_returnsCorrectHelpResource() { 70 assertThat(mFragment.getHelpResource()).isEqualTo(R.string.help_url_autoclick); 71 } 72 73 @Test getLogTag_returnsCorrectTag()74 public void getLogTag_returnsCorrectTag() { 75 assertThat(mFragment.getLogTag()).isEqualTo("AutoclickPrefFragment"); 76 } 77 78 @Test getNonIndexableKeys_existInXmlLayout()79 public void getNonIndexableKeys_existInXmlLayout() { 80 final List<String> niks = ToggleAutoclickPreferenceFragment.SEARCH_INDEX_DATA_PROVIDER 81 .getNonIndexableKeys(mContext); 82 final List<String> keys = 83 XmlTestUtils.getKeysFromPreferenceXml(mContext, 84 R.xml.accessibility_autoclick_settings); 85 86 assertThat(keys).containsAtLeastElementsIn(niks); 87 } 88 89 @Test 90 @DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) getNonIndexableKeys_flagDisabled_doesNotContainShortcut()91 public void getNonIndexableKeys_flagDisabled_doesNotContainShortcut() { 92 final List<String> niks = ToggleAutoclickPreferenceFragment.SEARCH_INDEX_DATA_PROVIDER 93 .getNonIndexableKeys(mContext); 94 95 assertThat(niks).contains(KEY_AUTOCLICK_SHORTCUT_PREFERENCE); 96 } 97 98 @Test 99 @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) getNonIndexableKeys_returnsOnlyShortcutKey()100 public void getNonIndexableKeys_returnsOnlyShortcutKey() { 101 final List<String> niks = ToggleAutoclickPreferenceFragment.SEARCH_INDEX_DATA_PROVIDER 102 .getNonIndexableKeys(mContext); 103 104 assertThat(niks).doesNotContain(KEY_AUTOCLICK_SHORTCUT_PREFERENCE); 105 } 106 } 107