Prevent ringing gesture uses master switch

Test: make ROBOTEST_FILTER=PreventRingingGesturePreferenceControllerTest RunSettingsRoboTests
Test: make ROBOTEST_FILTER=PreventRingingSwitchPreferenceControllerTest RunSettingsRoboTests
Change-Id: Iaf356ccd3623e67c39810955093fc353ae0d10a0
Fixes: 119787033
This commit is contained in:
Beverly
2019-01-02 18:25:00 -05:00
parent ce380bdeef
commit 8b4d3c3f0c
6 changed files with 267 additions and 42 deletions

View File

@@ -18,44 +18,47 @@ package com.android.settings.gestures;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import android.content.Context;
import android.content.res.Resources;
import android.preference.PreferenceCategory;
import android.provider.Settings;
import androidx.preference.PreferenceScreen;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import com.android.settings.widget.RadioButtonPreference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class PreventRingingGesturePreferenceControllerTest {
private Context mContext;
private Resources mResources;
private PreventRingingGesturePreferenceController mController;
@Mock
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
.thenReturn(true);
mController = new PreventRingingGesturePreferenceController(mContext, null);
mController.mPreferenceCategory = new PreferenceCategory(mContext);
mController.mVibratePref = new RadioButtonPreference(mContext);
mController.mNonePref = new RadioButtonPreference(mContext);
mController.mMutePref = new RadioButtonPreference(mContext);
}
@@ -79,9 +82,10 @@ public class PreventRingingGesturePreferenceControllerTest {
public void testUpdateState_mute() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_MUTE);
mController.updateState(null);
mController.updateState(mPreference);
assertThat(mController.mVibratePref.isEnabled()).isTrue();
assertThat(mController.mMutePref.isEnabled()).isTrue();
assertThat(mController.mVibratePref.isChecked()).isFalse();
assertThat(mController.mNonePref.isChecked()).isFalse();
assertThat(mController.mMutePref.isChecked()).isTrue();
}
@@ -89,9 +93,21 @@ public class PreventRingingGesturePreferenceControllerTest {
public void testUpdateState_vibrate() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_VIBRATE);
mController.updateState(null);
mController.updateState(mPreference);
assertThat(mController.mVibratePref.isEnabled()).isTrue();
assertThat(mController.mMutePref.isEnabled()).isTrue();
assertThat(mController.mVibratePref.isChecked()).isTrue();
assertThat(mController.mNonePref.isChecked()).isFalse();
assertThat(mController.mMutePref.isChecked()).isFalse();
}
@Test
public void testUpdateState_off() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_OFF);
mController.updateState(mPreference);
assertThat(mController.mVibratePref.isEnabled()).isFalse();
assertThat(mController.mMutePref.isEnabled()).isFalse();
assertThat(mController.mVibratePref.isChecked()).isFalse();
assertThat(mController.mMutePref.isChecked()).isFalse();
}
@@ -99,9 +115,8 @@ public class PreventRingingGesturePreferenceControllerTest {
public void testUpdateState_other() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
7);
mController.updateState(null);
mController.updateState(mPreference);
assertThat(mController.mVibratePref.isChecked()).isFalse();
assertThat(mController.mNonePref.isChecked()).isTrue();
assertThat(mController.mMutePref.isChecked()).isFalse();
}
@@ -132,19 +147,4 @@ public class PreventRingingGesturePreferenceControllerTest {
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_OFF));
}
@Test
public void testRadioButtonClicked_off() {
RadioButtonPreference rbPref = new RadioButtonPreference(mContext);
rbPref.setKey(PreventRingingGesturePreferenceController.KEY_NONE);
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_MUTE);
mController.onRadioButtonClicked(rbPref);
assertThat(Settings.Secure.VOLUME_HUSH_OFF).isEqualTo(
Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_VIBRATE));
}
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (C) 2019 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 static com.google.common.truth.Truth.assertThat;
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;
import android.content.Context;
import android.content.res.Resources;
import android.provider.Settings;
import androidx.preference.Preference;
import com.android.settings.widget.SwitchBar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class PreventRingingSwitchPreferenceControllerTest {
private Context mContext;
private Resources mResources;
private PreventRingingSwitchPreferenceController mController;
private Preference mPreference = mock(Preference.class);
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mResources = mock(Resources.class);
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(com.android.internal.R.bool.config_volumeHushGestureEnabled))
.thenReturn(true);
mController = new PreventRingingSwitchPreferenceController(mContext);
mController.mSwitch = mock(SwitchBar.class);
}
@Test
public void testIsAvailable_configIsTrue_shouldReturnTrue() {
when(mResources.getBoolean(
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void testIsAvailable_configIsFalse_shouldReturnFalse() {
when(mResources.getBoolean(
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testOn_updateState_hushOff() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_OFF);
mController.updateState(mPreference);
verify(mController.mSwitch, times(1)).setChecked(false);
}
@Test
public void testOn_updateState_hushVibrate() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_VIBRATE);
mController.updateState(mPreference);
verify(mController.mSwitch, times(1)).setChecked(true);
}
@Test
public void testOn_updateState_hushMute() {
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
Settings.Secure.VOLUME_HUSH_MUTE);
mController.updateState(mPreference);
verify(mController.mSwitch, times(1)).setChecked(true);
}
}