1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accessibility; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.doReturn; 22 import static org.mockito.Mockito.spy; 23 24 import android.content.Context; 25 import android.provider.Settings; 26 27 import com.android.settings.testutils.shadow.ShadowDeviceConfig; 28 29 import org.junit.Before; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 import org.robolectric.RobolectricTestRunner; 33 import org.robolectric.RuntimeEnvironment; 34 import org.robolectric.annotation.Config; 35 36 @RunWith(RobolectricTestRunner.class) 37 public class RingVibrationPreferenceFragmentTest { 38 39 private Context mContext; 40 private RingVibrationPreferenceFragment mFragment; 41 42 @Before setUp()43 public void setUp() { 44 mContext = RuntimeEnvironment.application; 45 mFragment = spy(new RingVibrationPreferenceFragment()); 46 doReturn(mContext).when(mFragment).getContext(); 47 } 48 49 @Test 50 @Config(shadows = {ShadowDeviceConfig.class}) getVibrationEnabledSetting_rampingRingerEnabled_returnApplyRampingRinger()51 public void getVibrationEnabledSetting_rampingRingerEnabled_returnApplyRampingRinger() { 52 // Turn on both flags to enable ramping ringer. 53 Settings.Global.putInt( 54 mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 1 /* ON */); 55 assertThat(mFragment.getVibrationEnabledSetting()).isEqualTo( 56 Settings.Global.APPLY_RAMPING_RINGER); 57 } 58 59 @Test getVibrationEnabledSetting_rampingRingerDisabled_returnVibrationWhenRinging()60 public void getVibrationEnabledSetting_rampingRingerDisabled_returnVibrationWhenRinging() { 61 // Turn off Settings.Global.APPLY_RAMPING_RINGER to disable ramping ringer. 62 Settings.Global.putInt( 63 mContext.getContentResolver(), Settings.Global.APPLY_RAMPING_RINGER, 0 /* OFF */); 64 assertThat(mFragment.getVibrationEnabledSetting()).isEqualTo( 65 Settings.System.VIBRATE_WHEN_RINGING); 66 } 67 } 68