Merge "Remove Language and Input duplicates" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-19 00:41:02 +00:00
committed by Android (Google) Code Review
31 changed files with 204 additions and 92 deletions

View File

@@ -0,0 +1,36 @@
package com.android.settings;
import android.content.Context;
import com.android.settings.core.PreferenceController;
import com.android.settings.testutils.XmlTestUtils;
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;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DisplaySettingsTest {
@Test
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
final Context context = RuntimeEnvironment.application;
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;
@@ -44,6 +46,8 @@ import com.android.settings.core.PreferenceController;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.core.lifecycle.LifecycleObserver;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
@@ -52,6 +56,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;
@@ -144,6 +149,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");
}
}