Add video to each gesture preference screen.
- Refactor GesturePreference to a generic VideoPreference. - The old video_preference.xml is only for magnification video, so renamed. - And use VideoPreference in gesture setting pages. - Refactor common logic into GesturePreferenceController. Bug: 32637613 Test: RunSettingsRoboTests Change-Id: I58580b01a32873cb32c5dc5bf2ec021d5b1400cc
This commit is contained in:
@@ -18,11 +18,8 @@ package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -36,10 +33,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -55,81 +49,46 @@ public class DoubleTapPowerPreferenceControllerTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DoubleTapPowerPreferenceController(mContext);
|
||||
mController = new DoubleTapPowerPreferenceController(mContext, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsTrue_shouldDisplay() {
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mContext.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled))
|
||||
.thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsFalse_shouldNotDisplay() {
|
||||
public void isAvailable_configIsTrue_shouldReturnFalse() {
|
||||
when(mContext.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled))
|
||||
.thenReturn(false);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
|
||||
mController = new DoubleTapPowerPreferenceController(context, null);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTapPowerPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnFalse() {
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1);
|
||||
mController = new DoubleTapPowerPreferenceController(context, null);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTapPowerPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTapPowerPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(R.string.gesture_setting_off);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,12 +17,8 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -34,11 +30,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -47,8 +40,6 @@ public class DoubleTapScreenPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
|
||||
private DoubleTapScreenPreferenceController mController;
|
||||
@@ -57,68 +48,35 @@ public class DoubleTapScreenPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DoubleTapScreenPreferenceController(
|
||||
mContext, mAmbientDisplayConfiguration, 0);
|
||||
mContext, null, mAmbientDisplayConfiguration, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsTrue_shouldDisplay() {
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsFalse_shouldNotDisplay() {
|
||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
// Set the setting to be disabled.
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(R.string.gesture_setting_off);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
}
|
||||
|
@@ -20,9 +20,6 @@ import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
@@ -40,11 +37,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -54,19 +49,17 @@ public class DoubleTwistPreferenceControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private SensorManager mSensorManager;
|
||||
private DoubleTwistPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new DoubleTwistPreferenceController(mContext);
|
||||
mController = new DoubleTwistPreferenceController(mContext, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_hasSensor_shouldDisplay() {
|
||||
public void isAvailable_hasSensor_shouldReturnTrue() {
|
||||
// Mock sensors
|
||||
final List<Sensor> sensorList = new ArrayList<>();
|
||||
sensorList.add(mock(Sensor.class));
|
||||
@@ -75,28 +68,17 @@ public class DoubleTwistPreferenceControllerTest {
|
||||
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
||||
when(sensorList.get(0).getName()).thenReturn("test");
|
||||
when(sensorList.get(0).getVendor()).thenReturn("test");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
// Run through display
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// Verify preference is not removed
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_noSensor_shouldNotDisplay() {
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
public void isAvailable_noSensor_shouldReturnFalse() {
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_differentSensor_shouldNotDisplay() {
|
||||
public void isAvailable_differentSensor_shouldReturnFalse() {
|
||||
// Mock sensors
|
||||
final List<Sensor> sensorList = new ArrayList<>();
|
||||
sensorList.add(mock(Sensor.class));
|
||||
@@ -104,68 +86,29 @@ public class DoubleTwistPreferenceControllerTest {
|
||||
when(mContext.getSystemService(Context.SENSOR_SERVICE)).thenReturn(mSensorManager);
|
||||
when(mSensorManager.getSensorList(anyInt())).thenReturn(sensorList);
|
||||
when(sensorList.get(0).getName()).thenReturn("not_test");
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
// Run through display
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// Verify preference is not removed
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 1);
|
||||
mController = new DoubleTwistPreferenceController(context, null);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTwistPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
|
||||
mController = new DoubleTwistPreferenceController(context, null);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTwistPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(),
|
||||
CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0);
|
||||
|
||||
// Run through updateState
|
||||
mController = new DoubleTwistPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
import com.android.settings.widget.VideoPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class GesturePreferenceControllerTest {
|
||||
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Lifecycle mLifecycle;
|
||||
private TestPrefController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new TestPrefController(mContext, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsTrue_shouldDisplay() {
|
||||
mController.mIsPrefAvailable = true;
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mock(VideoPreference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsFalse_shouldNotDisplay() {
|
||||
mController.mIsPrefAvailable = false;
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldStartVideoPreference() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart();
|
||||
|
||||
verify(videoPreference).onViewVisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldStopVideoPreference() {
|
||||
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(videoPreference);
|
||||
mController.mIsPrefAvailable = true;
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStop();
|
||||
|
||||
verify(videoPreference).onViewInvisible();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
// Set the setting to be enabled.
|
||||
mController.mIsPrefEnabled = true;
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
// Set the setting to be disabled.
|
||||
mController.mIsPrefEnabled = false;
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
mController.mIsPrefEnabled = false;
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(com.android.settings.R.string.gesture_setting_off);
|
||||
}
|
||||
|
||||
private class TestPrefController extends GesturePreferenceController {
|
||||
|
||||
boolean mIsPrefAvailable;
|
||||
boolean mIsPrefEnabled;
|
||||
|
||||
public TestPrefController(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, lifecycle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mIsPrefAvailable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getVideoPrefKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isSwitchPrefEnabled() {
|
||||
return mIsPrefEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,12 +17,8 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -34,11 +30,8 @@ import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -47,8 +40,6 @@ public class PIckupGesturePreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
|
||||
|
||||
@@ -58,69 +49,37 @@ public class PIckupGesturePreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new PickupGesturePreferenceController(
|
||||
mContext, mAmbientDisplayConfiguration, 0);
|
||||
mContext, null, mAmbientDisplayConfiguration, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsTrue_shouldDisplay() {
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsFalse_shouldNotDisplay() {
|
||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(false);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
|
||||
// Set the setting to be disabled.
|
||||
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
|
||||
|
||||
// Run through updateState
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(R.string.gesture_setting_off);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,11 +18,7 @@ package com.android.settings.gestures;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -36,10 +32,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static android.provider.Settings.Secure.SYSTEM_NAVIGATION_KEYS_ENABLED;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@@ -48,85 +41,50 @@ public class SwipeToNotificationPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private SwipeToNotificationPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mController = new SwipeToNotificationPreferenceController(mContext);
|
||||
mController = new SwipeToNotificationPreferenceController(mContext, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsTrue_shouldDisplay() {
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mContext.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
|
||||
.thenReturn(true);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen, never()).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_configIsFalse_shouldNotDisplay() {
|
||||
public void isAvailable_configIsFalse_shouldReturnFalse() {
|
||||
when(mContext.getResources().
|
||||
getBoolean(com.android.internal.R.bool.config_supportSystemNavigationKeys))
|
||||
.thenReturn(false);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mock(Preference.class));
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mScreen).removePreference(any(Preference.class));
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetCheckedWhenSettingIsOn() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
|
||||
// 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);
|
||||
|
||||
// Run through updateState
|
||||
mController = new SwipeToNotificationPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is checked (as setting is enabled).
|
||||
verify(preference).setChecked(true);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_preferenceSetUncheckedWhenSettingIsOff() {
|
||||
// Mock a TwoStatePreference
|
||||
final TwoStatePreference preference = mock(TwoStatePreference.class);
|
||||
public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
|
||||
// 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);
|
||||
|
||||
// Run through updateState
|
||||
mController = new SwipeToNotificationPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify pref is unchecked (as setting is disabled).
|
||||
verify(preference).setChecked(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_notTwoStatePreference_setSummary() {
|
||||
// Mock a regular preference
|
||||
final Preference preference = mock(Preference.class);
|
||||
// Set the setting to be disabled.
|
||||
final Context context = ShadowApplication.getInstance().getApplicationContext();
|
||||
Settings.System.putInt(context.getContentResolver(), SYSTEM_NAVIGATION_KEYS_ENABLED, 0);
|
||||
|
||||
// Run through updateState
|
||||
mController = new SwipeToNotificationPreferenceController(context);
|
||||
mController.updateState(preference);
|
||||
|
||||
// Verify summary is set to off (as setting is disabled).
|
||||
verify(preference).setSummary(R.string.gesture_setting_off);
|
||||
assertThat(mController.isSwitchPrefEnabled()).isFalse();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user