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.gestures; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.os.SystemProperties; 23 import android.provider.SearchIndexableResource; 24 25 import org.junit.Before; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 import org.robolectric.RobolectricTestRunner; 29 import org.robolectric.RuntimeEnvironment; 30 import org.robolectric.util.ReflectionHelpers; 31 32 import java.util.List; 33 34 @RunWith(RobolectricTestRunner.class) 35 public class OneHandedSettingsTest { 36 37 private OneHandedSettings mSettings; 38 private Context mContext; 39 40 @Before setUp()41 public void setUp() { 42 mSettings = new OneHandedSettings(); 43 mContext = RuntimeEnvironment.application; 44 } 45 46 @Test testSearchIndexProvider_shouldIndexResource()47 public void testSearchIndexProvider_shouldIndexResource() { 48 final List<SearchIndexableResource> indexRes = 49 OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex( 50 RuntimeEnvironment.application, true /* enabled */); 51 52 assertThat(indexRes).isNotNull(); 53 assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId()); 54 } 55 56 @Test isPageSearchEnabled_setSupportOneHandedModeProperty_shouldReturnTrue()57 public void isPageSearchEnabled_setSupportOneHandedModeProperty_shouldReturnTrue() { 58 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "true"); 59 60 final Object obj = ReflectionHelpers.callInstanceMethod( 61 OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled", 62 ReflectionHelpers.ClassParameter.from(Context.class, mContext)); 63 final boolean isEnabled = (Boolean) obj; 64 assertThat(isEnabled).isTrue(); 65 } 66 67 @Test isPageSearchEnabled_unsetSupportOneHandedModeProperty_shouldReturnFalse()68 public void isPageSearchEnabled_unsetSupportOneHandedModeProperty_shouldReturnFalse() { 69 SystemProperties.set(OneHandedSettingsUtils.SUPPORT_ONE_HANDED_MODE, "false"); 70 71 final Object obj = ReflectionHelpers.callInstanceMethod( 72 OneHandedSettings.SEARCH_INDEX_DATA_PROVIDER, "isPageSearchEnabled", 73 ReflectionHelpers.ClassParameter.from(Context.class, mContext)); 74 final boolean isEnabled = (Boolean) obj; 75 assertThat(isEnabled).isFalse(); 76 } 77 } 78