Merge "Remove Language and Input duplicates"

This commit is contained in:
TreeHugger Robot
2017-05-18 22:37:24 +00:00
committed by Android (Google) Code Review
32 changed files with 259 additions and 90 deletions

View File

@@ -0,0 +1,44 @@
package com.android.settings;
import android.content.Context;
import android.os.PowerManager;
import com.android.settings.core.PreferenceController;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowPowerManagerWrapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DisplaySettingsTest {
@Test
@Config(shadows = ShadowPowerManagerWrapper.class)
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
final Context context = RuntimeEnvironment.application;
// PowerManager wrapper = mock(PowerManager.class);
// doReturn(wrapper).when(context).getSystemService(Context.POWER_SERVICE);
final DisplaySettings fragment = new DisplaySettings();
final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context,
fragment.getPreferenceScreenResId());
final List<String> preferenceKeys = new ArrayList<>();
for (PreferenceController controller : fragment.getPreferenceControllers(context)) {
preferenceKeys.add(controller.getPreferenceKey());
}
// Nightmode is currently hidden
preferenceKeys.remove("night_mode");
assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys);
}
}

View File

@@ -52,12 +52,14 @@ public class AssistGesturePreferenceControllerTest {
private FakeFeatureFactory mFactory;
private AssistGesturePreferenceController mController;
private static final String KEY_ASSIST = "gesture_assist";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
mFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mController = new AssistGesturePreferenceController(mContext, null);
mController = new AssistGesturePreferenceController(mContext, null, KEY_ASSIST);
}
@Test
@@ -77,7 +79,7 @@ public class AssistGesturePreferenceControllerTest {
// Set the setting to be enabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 1);
mController = new AssistGesturePreferenceController(context, null);
mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@@ -87,7 +89,7 @@ public class AssistGesturePreferenceControllerTest {
// Set the setting to be disabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), ASSIST_GESTURE_ENABLED, 0);
mController = new AssistGesturePreferenceController(context, null);
mController = new AssistGesturePreferenceController(context, null, KEY_ASSIST);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}

View File

@@ -47,11 +47,12 @@ public class DoubleTapPowerPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
private DoubleTapPowerPreferenceController mController;
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new DoubleTapPowerPreferenceController(mContext, null);
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
}
@Test
@@ -78,7 +79,7 @@ public class DoubleTapPowerPreferenceControllerTest {
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
mController = new DoubleTapPowerPreferenceController(context, null);
mController = new DoubleTapPowerPreferenceController(context, null, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@@ -89,7 +90,7 @@ public class DoubleTapPowerPreferenceControllerTest {
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1);
mController = new DoubleTapPowerPreferenceController(context, null);
mController = new DoubleTapPowerPreferenceController(context, null, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}

View File

@@ -46,11 +46,13 @@ public class DoubleTapScreenPreferenceControllerTest {
private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
private DoubleTapScreenPreferenceController mController;
private static final String KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new DoubleTapScreenPreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0);
mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
}
@Test

View File

@@ -53,11 +53,12 @@ public class DoubleTwistPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SensorManager mSensorManager;
private DoubleTwistPreferenceController mController;
private static final String KEY_DOUBLE_TWIST = "gesture_double_twist";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new DoubleTwistPreferenceController(mContext, null);
mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
}
@Test
@@ -98,7 +99,7 @@ public class DoubleTwistPreferenceControllerTest {
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
mController = new DoubleTwistPreferenceController(context, null);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@@ -109,7 +110,7 @@ public class DoubleTwistPreferenceControllerTest {
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(),
CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
mController = new DoubleTwistPreferenceController(context, null);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}

View File

@@ -47,11 +47,13 @@ public class PIckupGesturePreferenceControllerTest {
private PickupGesturePreferenceController mController;
private static final String KEY_PICK_UP = "gesture_pick_up";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new PickupGesturePreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0);
mContext, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
}
@Test

View File

@@ -45,11 +45,12 @@ public class SwipeToNotificationPreferenceControllerTest {
private Context mContext;
private SwipeToNotificationPreferenceController mController;
private static final String KEY_SWIPE_DOWN = "gesture_swipe_down_fingerprint";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new SwipeToNotificationPreferenceController(mContext, null);
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
}
@Test
@@ -75,7 +76,7 @@ public class SwipeToNotificationPreferenceControllerTest {
// Set the setting to be enabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
mController = new SwipeToNotificationPreferenceController(context, null);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
}
@@ -85,7 +86,7 @@ public class SwipeToNotificationPreferenceControllerTest {
// Set the setting to be disabled.
final Context context = ShadowApplication.getInstance().getApplicationContext();
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
mController = new SwipeToNotificationPreferenceController(context, null);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
}

View File

@@ -18,7 +18,9 @@ package com.android.settings.language;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -42,6 +44,9 @@ import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.PreferenceController;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -52,6 +57,7 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
@@ -80,6 +86,7 @@ public class LanguageAndInputSettingsTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
FakeFeatureFactory.setupForTest(mContext);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mock(InputManager.class));
when(mContext.getSystemService(Context.INPUT_SERVICE)).thenReturn(mIm);
@@ -145,6 +152,37 @@ public class LanguageAndInputSettingsTest {
verify(loader).setSummary(provider, null);
}
@Test
public void testNonIndexableKeys_existInXmlLayout() {
final Context context = spy(RuntimeEnvironment.application);
//(InputManager) context.getSystemService(Context.INPUT_SERVICE);
InputManager manager = mock(InputManager.class);
when(manager.getInputDeviceIds()).thenReturn(new int[]{});
doReturn(manager).when(context).getSystemService(Context.INPUT_SERVICE);
final List<String> niks = LanguageAndInputSettings.SEARCH_INDEX_DATA_PROVIDER
.getNonIndexableKeys(context);
final int xmlId = (new LanguageAndInputSettings()).getPreferenceScreenResId();
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
assertThat(keys).containsAllIn(niks);
}
@Test
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
final Context context = RuntimeEnvironment.application;
final LanguageAndInputSettings fragment = new LanguageAndInputSettings();
final List<String> preferenceScreenKeys = XmlTestUtils.getKeysFromPreferenceXml(context,
fragment.getPreferenceScreenResId());
final List<String> preferenceKeys = new ArrayList<>();
for (PreferenceController controller : fragment.getPreferenceControllers(context)) {
preferenceKeys.add(controller.getPreferenceKey());
}
assertThat(preferenceScreenKeys).containsAllIn(preferenceKeys);
}
/**
* Test fragment to expose lifecycle and context so we can verify behavior for observables.
*/

View File

@@ -108,7 +108,7 @@ public class BaseSearchIndexProviderTest {
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.language_and_input;
sir.xmlResId = R.xml.data_usage;
return Arrays.asList(sir);
}
@@ -121,13 +121,7 @@ public class BaseSearchIndexProviderTest {
final List<String> nonIndexableKeys = provider
.getNonIndexableKeys(RuntimeEnvironment.application);
assertThat(nonIndexableKeys).containsAllOf("phone_language", "spellcheckers_settings",
"key_user_dictionary_settings", "gesture_settings_category", "gesture_assist",
"gesture_swipe_down_fingerprint", "gesture_double_tap_power",
"gesture_double_twist", "gesture_double_tap_screen", "gesture_pick_up",
"pointer_speed", "tts_settings",
"game_controller_settings_category", "vibrate_input_devices");
assertThat(nonIndexableKeys).containsAllOf("status_header", "limit_summary",
"restrict_background");
}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.android.settings.testutils.shadow;
import com.android.settings.display.PowerManagerWrapper;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
@Implements(PowerManagerWrapper.class)
public class ShadowPowerManagerWrapper {
@Implementation
public int getMinimumScreenBrightnessSetting() {
return 0;
}
@Implementation
public int getMaximumScreenBrightnessSetting() {
return 0;
}
@Implementation
public int getMinimumScreenBrightnessForVrSetting() {
return 0;
}
@Implementation
public int getMaximumScreenBrightnessForVrSetting() {
return 0;
}
}