Add items in Other Sound directly into Sound settings.
- In new IA, Other Sound no longer is a separate preference screen, but individual preferences are put directly under SoundSettings. - Add controllers for each other sounds preference. - Remove Cast settings from Soundsettings in new IA. Change-Id: I75d771674ffabfecbd66079bc86844b2ff098b71 Fix: 33944294 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
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 org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
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 BootSoundPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
private BootSoundPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
SettingsShadowSystemProperties.clear();
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_boot_sounds))
|
||||
.thenReturn(true);
|
||||
mController = new BootSoundPreferenceController(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasBootSounds_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(
|
||||
com.android.settings.R.bool.has_boot_sounds)).thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noBootSounds_shouldReturnFale() {
|
||||
when(mContext.getResources().getBoolean(
|
||||
com.android.settings.R.bool.has_boot_sounds)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_bootSoundEnabled_shouldCheckedPreference() {
|
||||
SettingsShadowSystemProperties.set(BootSoundPreferenceController.PROPERTY_BOOT_SOUNDS, "1");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void displayPreference_bootSoundDisabled_shouldUncheckedPreference() {
|
||||
SettingsShadowSystemProperties.set(BootSoundPreferenceController.PROPERTY_BOOT_SOUNDS, "0");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceChecked_shouldEnableBootSound() {
|
||||
when(mPreference.isChecked()).thenReturn(true);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(SystemProperties.getBoolean(
|
||||
BootSoundPreferenceController.PROPERTY_BOOT_SOUNDS, true)).isTrue();
|
||||
}
|
||||
|
||||
@Config(shadows = {SettingsShadowSystemProperties.class})
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_preferenceUnchecked_shouldDisableBootSound() {
|
||||
when(mPreference.isChecked()).thenReturn(false);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
assertThat(SystemProperties.getBoolean(
|
||||
BootSoundPreferenceController.PROPERTY_BOOT_SOUNDS, true)).isFalse();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ChargingSoundPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
private ChargingSoundPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new ChargingSoundPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isAlwaysTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() {
|
||||
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_chargingSoundDisabled_shouldUncheckedPreference() {
|
||||
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledChargingSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledChargingSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.System;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DialPadTonePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
private DialPadTonePreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new DialPadTonePreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_voiceCapable_shouldReturnTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notVoiceCapable_shouldReturnFalse() {
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dialToneEnabled_shouldCheckedPreference() {
|
||||
System.putInt(mContentResolver, System.DTMF_TONE_WHEN_DIALING, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dialToneDisabled_shouldUncheckedPreference() {
|
||||
System.putInt(mContentResolver, System.DTMF_TONE_WHEN_DIALING, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledDialTone() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.DTMF_TONE_WHEN_DIALING, 1)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledDialTone() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.DTMF_TONE_WHEN_DIALING, 1)).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.DropDownPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DockAudioMediaPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private DockAudioMediaPreferenceController mController;
|
||||
private DropDownPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Context appContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(mActivity.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
when(mActivity.getResources().getString(anyInt())).thenReturn("test string");
|
||||
mPreference = new DropDownPreference(appContext);
|
||||
mController = new DockAudioMediaPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasDockSettings_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noDockSettings_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dockAudioDisabled_shouldSelectFirstItem() {
|
||||
Global.putInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dockAudioEnabled_shouldSelectSecondItem() {
|
||||
Global.putInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_firstItemSelected_shouldDisableDockAudio() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, "0");
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 0))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_secondItemSelected_shouldEnableDockAudio() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, "1");
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.DOCK_AUDIO_MEDIA_ENABLED, 0))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Global;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class DockingSoundPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
|
||||
private DockingSoundPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
when(mActivity.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
mController = new DockingSoundPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasDockSettings_shouldReturnTrue() {
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noDockSettings_shouldReturnFalse() {
|
||||
when(mContext.getResources().getBoolean(com.android.settings.R.bool.has_dock_settings))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dockingSoundEnabled_shouldCheckedPreference() {
|
||||
Global.putInt(mContentResolver, Global.DOCK_SOUNDS_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_dockingSoundDisabled_shouldUncheckedPreference() {
|
||||
Global.putInt(mContentResolver, Global.DOCK_SOUNDS_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledDockingSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.DOCK_SOUNDS_ENABLED, 1)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledDockingSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.DOCK_SOUNDS_ENABLED, 1)).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.DropDownPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.Global;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class EmergencyTonePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
private EmergencyTonePreferenceController mController;
|
||||
private DropDownPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
final Context appContext = ShadowApplication.getInstance().getApplicationContext();
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(mActivity.getResources()).thenReturn(appContext.getResources());
|
||||
mPreference = new DropDownPreference(appContext);
|
||||
mController = new EmergencyTonePreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_cdma_shouldReturnTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notCdma_shouldReturnFalse() {
|
||||
when(mTelephonyManager.getCurrentPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_emergencyToneOff_shouldSelectFirstItem() {
|
||||
Global.putInt(mContentResolver, Global.EMERGENCY_TONE, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_emergencyToneAlert_shouldSelectSecondItem() {
|
||||
Global.putInt(mContentResolver, Global.EMERGENCY_TONE, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_emergencyToneVibrate_shouldSelectThirdItem() {
|
||||
Global.putInt(mContentResolver, Global.EMERGENCY_TONE, 2);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo("2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_firstItemSelected_shouldSetEmergencyToneToOff() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, "0");
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.EMERGENCY_TONE, 0)).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_secondItemSelected_shouldSetEmergencyToneToAlert() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, "1");
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.EMERGENCY_TONE, 0)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_thirdItemSelected_shouldSetEmergencyToneToVibrate() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, "2");
|
||||
|
||||
assertThat(Global.getInt(mContentResolver, Global.EMERGENCY_TONE, 0)).isEqualTo(2);
|
||||
}
|
||||
}
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.System;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ScreenLockSoundPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
private ScreenLockSoundPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new ScreenLockSoundPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isAlwaysTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_lockScreenSoundEnabled_shouldCheckedPreference() {
|
||||
System.putInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_lockScreenSoundDisabled_shouldUncheckedPreference() {
|
||||
System.putInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledLockScreenSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1))
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledLockScreenSound() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.LOCKSCREEN_SOUNDS_ENABLED, 1))
|
||||
.isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings.Global;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.android.settings.notification.SettingPref.TYPE_GLOBAL;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
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 SettingPrefControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private OtherSoundSettings mSetting;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceControllerTestable mController;
|
||||
private SettingPref mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ShadowApplication.getInstance().getApplicationContext());
|
||||
when(mContext.getContentResolver()).thenReturn(mContentResolver);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
mController = new PreferenceControllerTestable(mContext, mSetting, null);
|
||||
mPreference = mController.getPref();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldInitPreference() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).init(mSetting);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_shouldCallisApplicable() {
|
||||
mController.isAvailable();
|
||||
|
||||
verify(mPreference).isApplicable(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceKey_shouldReturnPrefKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo(mController.KEY_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_shouldUpdatePreference() {
|
||||
mController.updateState(null);
|
||||
|
||||
verify(mPreference).update(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onResume_shouldRegisterContentObserver() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onResume();
|
||||
|
||||
verify(mContentResolver).registerContentObserver(
|
||||
Global.getUriFor("Setting1"), false, mController.getObserver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPause_shouldUnregisterContentObserver() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPause();
|
||||
|
||||
verify(mContentResolver).unregisterContentObserver(mController.getObserver());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onContentChange_shouldUpdatePreference() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onResume();
|
||||
mController.getObserver().onChange(false, Global.getUriFor("Setting1"));
|
||||
|
||||
verify(mPreference).update(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonIndexableKeys_applicable_shouldNotUpdate() {
|
||||
final List<String> keys = new ArrayList<>();
|
||||
|
||||
mController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNonIndexableKeys_notApplicable_shouldUpdate() {
|
||||
mController.setApplicable(false);
|
||||
final List<String> keys = new ArrayList<>();
|
||||
|
||||
mController.updateNonIndexableKeys(keys);
|
||||
|
||||
assertThat(keys).isNotEmpty();
|
||||
}
|
||||
|
||||
private class PreferenceControllerTestable extends SettingPrefController {
|
||||
|
||||
private static final String KEY_TEST = "key1";
|
||||
private boolean mApplicable = true;
|
||||
|
||||
public PreferenceControllerTestable(Context context, SettingsPreferenceFragment parent,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, parent, lifecycle);
|
||||
mPreference = spy(new SettingPref(
|
||||
TYPE_GLOBAL, KEY_TEST, "Setting1", 1) {
|
||||
@Override
|
||||
public boolean isApplicable(Context context) {
|
||||
return mApplicable;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
SettingPref getPref() {
|
||||
return mPreference;
|
||||
}
|
||||
|
||||
PreferenceControllerTestable.SettingsObserver getObserver() {
|
||||
return mSettingsObserver;
|
||||
}
|
||||
|
||||
void setApplicable(boolean applicable) {
|
||||
mApplicable = applicable;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.System;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
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 TouchSoundPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private AudioManager mAudioManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
|
||||
private TouchSoundPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new TouchSoundPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_isAlwaysTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_soundEffectEnabled_shouldCheckedPreference() {
|
||||
System.putInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_soundEffectDisabled_shouldUncheckedPreference() {
|
||||
System.putInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledSoundEffect() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledSoundEffect() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.SOUND_EFFECTS_ENABLED, 1)).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.notification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Vibrator;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.provider.Settings.System;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Answers.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class VibrateOnTouchPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private ContentResolver mContentResolver;
|
||||
@Mock
|
||||
private SoundSettings mSetting;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private Vibrator mVibrator;
|
||||
|
||||
private VibrateOnTouchPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
when(mSetting.getActivity()).thenReturn(mActivity);
|
||||
when(mActivity.getContentResolver()).thenReturn(mContentResolver);
|
||||
mPreference = new SwitchPreference(ShadowApplication.getInstance().getApplicationContext());
|
||||
mController = new VibrateOnTouchPreferenceController(mContext, mSetting, null);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
doReturn(mScreen).when(mSetting).getPreferenceScreen();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasHaptic_shouldReturnTrue() {
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noHaptic_shouldReturnFalse() {
|
||||
when(mVibrator.hasVibrator()).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hapticEnabled_shouldCheckedPreference() {
|
||||
System.putInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hapticDisabled_shouldUncheckedPreference() {
|
||||
System.putInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 0);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceChecked_shouldEnabledHaptic() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_preferenceUnchecked_shouldDisabledHaptic() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false);
|
||||
|
||||
assertThat(System.getInt(mContentResolver, System.HAPTIC_FEEDBACK_ENABLED, 1)).isEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.testutils.shadow;
|
||||
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowSystemProperties;
|
||||
|
||||
/**
|
||||
* This class provides write capability to ShadowSystemProperties.
|
||||
*/
|
||||
@Implements(SystemProperties.class)
|
||||
public class SettingsShadowSystemProperties extends ShadowSystemProperties {
|
||||
|
||||
private static final Map<String, String> sValues = new HashMap<>();
|
||||
|
||||
@Implementation
|
||||
public static synchronized boolean getBoolean(String key, boolean def) {
|
||||
if (sValues.containsKey(key)) {
|
||||
String val = sValues.get(key);
|
||||
return "y".equals(val) || "yes".equals(val) || "1".equals(val) || "true".equals(val)
|
||||
|| "on".equals(val);
|
||||
}
|
||||
return ShadowSystemProperties.getBoolean(key, def);
|
||||
}
|
||||
|
||||
public static synchronized void set(String key, String val) {
|
||||
sValues.put(key, val);
|
||||
}
|
||||
|
||||
public static synchronized void clear() {
|
||||
sValues.clear();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user