GesturesSettingPreferenceController to Toggle

Convert GesturesSettingPreferenceController to
TogglePreferenceController,
All of its children need follow the change,
add setter and robotest for them:
AssistGestureSettingsPreferenceController
DoubleTapPowerPreferenceController
DoubleTapScreenPreferenceController
DoubleTwistPreferenceController
PickupGesturePreferenceController
SwipeToNotificationPreferenceController

Change-Id: I792b2d370eea828bf345fb2b1cc3eac260eb66f4
Merged-In: I792b2d370eea828bf345fb2b1cc3eac260eb66f4
Fixes: 74913806
Fixes: 67998110
Fixes: 67998098
Fixes: 67998048
Fixes: 67998069
Fixes: 67997452
Test: make RunSettingsRoboTests
This commit is contained in:
HJ ChangLiao
2018-04-02 17:06:55 +08:00
parent 85c34077d3
commit 3c4c3fc5c7
40 changed files with 320 additions and 429 deletions

View File

@@ -55,8 +55,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
mController =
new AssistGestureSettingsPreferenceController(mContext, null, KEY_ASSIST, false);
mController = new AssistGestureSettingsPreferenceController(mContext, KEY_ASSIST);
mController.setAssistOnly(false);
}
@Test
@@ -76,8 +76,8 @@ public class AssistGestureSettingsPreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
AssistGestureSettingsPreferenceController controller =
new AssistGestureSettingsPreferenceController(context, null /* lifecycle */,
KEY_ASSIST, false /* assistOnly */);
new AssistGestureSettingsPreferenceController(context, KEY_ASSIST);
controller.setAssistOnly(false);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -56,7 +56,7 @@ public class DoubleTapPowerPreferenceControllerTest {
public void setUp() {
mContext = RuntimeEnvironment.application;
mContentResolver = mContext.getContentResolver();
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
}
@After
@@ -81,28 +81,27 @@ public class DoubleTapPowerPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() {
public void testIsChecked_configIsNotSet_shouldReturnTrue() {
// Set the setting to be enabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnFalse() {
public void testIsChecked_configIsSet_shouldReturnFalse() {
// Set the setting to be disabled.
Settings.System.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
mController = new DoubleTapPowerPreferenceController(mContext, null, KEY_DOUBLE_TAP_POWER);
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
DoubleTapPowerPreferenceController controller =
new DoubleTapPowerPreferenceController(mContext, null /* lifecycle */,
KEY_DOUBLE_TAP_POWER);
new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -56,8 +56,8 @@ public class DoubleTapScreenPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new DoubleTapScreenPreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
mController = new DoubleTapScreenPreferenceController(mContext, KEY_DOUBLE_TAP_SCREEN);
mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -75,26 +75,26 @@ public class DoubleTapScreenPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
DoubleTapScreenPreferenceController controller =
new DoubleTapScreenPreferenceController(context, null /* lifecycle */,
mAmbientDisplayConfiguration, 0 /* userid */, KEY_DOUBLE_TAP_SCREEN);
new DoubleTapScreenPreferenceController(context, KEY_DOUBLE_TAP_SCREEN);
controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -61,7 +61,7 @@ public class DoubleTwistPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mock(UserManager.class));
mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST);
}
@After
@@ -120,7 +120,7 @@ public class DoubleTwistPreferenceControllerTest {
Settings.Secure.putIntForUser(
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
DoubleTwistPreferenceController controller =
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
spy(new DoubleTwistPreferenceController(mContext, KEY_DOUBLE_TWIST));
ShadowDoubleTwistPreferenceController.setManagedProfileId(managedId);
// enable the gesture
@@ -135,24 +135,24 @@ public class DoubleTwistPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(),
Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
mController = new DoubleTwistPreferenceController(context, null, KEY_DOUBLE_TWIST);
mController = new DoubleTwistPreferenceController(context, KEY_DOUBLE_TWIST);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
}

View File

@@ -17,6 +17,9 @@
package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@@ -31,7 +34,6 @@ import android.support.v7.preference.TwoStatePreference;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.widget.VideoPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
@@ -49,7 +51,6 @@ public class GesturePreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Lifecycle mLifecycle;
private TestPrefController mController;
private Preference mPreference;
@@ -57,7 +58,7 @@ public class GesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new TestPrefController(mContext, mLifecycle);
mController = new TestPrefController(mContext, "testKey");
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
@@ -187,7 +188,8 @@ public class GesturePreferenceControllerTest {
mController.updateState(preference);
// Verify summary is set to off (as setting is disabled).
verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
assertThat(preference.getSummary()).isEqualTo(
mContext.getString(com.android.settings.R.string.gesture_setting_off));
}
private class TestPrefController extends GesturePreferenceController {
@@ -196,18 +198,13 @@ public class GesturePreferenceControllerTest {
boolean mIsPrefEnabled;
private TestPrefController(Context context,
Lifecycle lifecycle) {
super(context, lifecycle);
String key) {
super(context, key);
}
@Override
public boolean isAvailable() {
return mIsPrefAvailable;
}
@Override
public String getPreferenceKey() {
return "testKey";
public int getAvailabilityStatus() {
return mIsPrefAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
}
@Override
@@ -216,12 +213,12 @@ public class GesturePreferenceControllerTest {
}
@Override
protected boolean isSwitchPrefEnabled() {
public boolean isChecked() {
return mIsPrefEnabled;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean setChecked(boolean isChecked) {
return false;
}
}

View File

@@ -57,8 +57,8 @@ public class PickupGesturePreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new PickupGesturePreferenceController(
mContext, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
mController = new PickupGesturePreferenceController(mContext, KEY_PICK_UP);
mController.setConfig(mAmbientDisplayConfiguration);
}
@Test
@@ -76,19 +76,19 @@ public class PickupGesturePreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
// Set the setting to be enabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
// Set the setting to be disabled.
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test
@@ -111,8 +111,8 @@ public class PickupGesturePreferenceControllerTest {
public void testPreferenceController_ProperResultPayloadType() {
final Context context = RuntimeEnvironment.application;
PickupGesturePreferenceController controller =
new PickupGesturePreferenceController(
context, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
new PickupGesturePreferenceController(context, KEY_PICK_UP);
controller.setConfig(mAmbientDisplayConfiguration);
ResultPayload payload = controller.getResultPayload();
assertThat(payload).isInstanceOf(InlineSwitchPayload.class);
}

View File

@@ -53,7 +53,7 @@ public class SwipeToNotificationPreferenceControllerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(mContext, KEY_SWIPE_DOWN);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
@@ -93,27 +93,27 @@ public class SwipeToNotificationPreferenceControllerTest {
}
@Test
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
public void testIsChecked_configIsSet_shouldReturnTrue() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be enabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 1);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isTrue();
assertThat(mController.isChecked()).isTrue();
}
@Test
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
public void testIsChecked_configIsNotSet_shouldReturnFalse() {
stubFingerprintSupported(true);
when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
// Set the setting to be disabled.
final Context context = RuntimeEnvironment.application;
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
mController = new SwipeToNotificationPreferenceController(context, null, KEY_SWIPE_DOWN);
mController = new SwipeToNotificationPreferenceController(context, KEY_SWIPE_DOWN);
assertThat(mController.isSwitchPrefEnabled()).isFalse();
assertThat(mController.isChecked()).isFalse();
}
@Test

View File

@@ -53,14 +53,6 @@ public class SwipeToNotificationSettingsTest {
.isEqualTo(R.xml.swipe_to_notification_settings);
}
@Test
public void testGetPreferenceControllers_shouldAllBeCreated() {
final List<AbstractPreferenceController> controllers =
mFragment.createPreferenceControllers(mContext);
assertThat(controllers.isEmpty()).isFalse();
}
@Test
public void testSearchIndexProvider_shouldIndexResource() {
final List<SearchIndexableResource> indexRes =