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,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