Home | History | Annotate | Download | only in development
      1 /*
      2  * Copyright (C) 2017 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.development;
     18 
     19 import static com.android.settings.development.EnableGnssRawMeasFullTrackingPreferenceController.SETTING_VALUE_OFF;
     20 import static com.android.settings.development.EnableGnssRawMeasFullTrackingPreferenceController.SETTING_VALUE_ON;
     21 import static com.google.common.truth.Truth.assertThat;
     22 import static org.mockito.Mockito.verify;
     23 import static org.mockito.Mockito.when;
     24 
     25 import android.content.Context;
     26 import android.provider.Settings;
     27 import android.support.v14.preference.SwitchPreference;
     28 import android.support.v7.preference.PreferenceScreen;
     29 
     30 import com.android.settings.testutils.SettingsRobolectricTestRunner;
     31 
     32 import org.junit.Before;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 import org.mockito.Mock;
     36 import org.mockito.MockitoAnnotations;
     37 import org.robolectric.RuntimeEnvironment;
     38 
     39 @RunWith(SettingsRobolectricTestRunner.class)
     40 public class EnableGnssRawMeasFullTrackingPreferenceControllerTest {
     41 
     42     @Mock
     43     private SwitchPreference mPreference;
     44     @Mock
     45     private PreferenceScreen mPreferenceScreen;
     46 
     47     private Context mContext;
     48     private EnableGnssRawMeasFullTrackingPreferenceController mController;
     49 
     50     @Before
     51     public void setup() {
     52         MockitoAnnotations.initMocks(this);
     53         mContext = RuntimeEnvironment.application;
     54         mController = new EnableGnssRawMeasFullTrackingPreferenceController(mContext);
     55         when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
     56             .thenReturn(mPreference);
     57         mController.displayPreference(mPreferenceScreen);
     58     }
     59 
     60     @Test
     61     public void onPreferenceChange_settingEnabled_enableGnssRawMeasFullTrackingShouldBeOn() {
     62         mController.onPreferenceChange(mPreference, true /* new value */);
     63 
     64         final int mode = Settings.Global.getInt(mContext.getContentResolver(),
     65                 Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, -1 /* default */);
     66 
     67         assertThat(mode).isEqualTo(SETTING_VALUE_ON);
     68     }
     69 
     70     @Test
     71     public void onPreferenceChange_settingDisabled_enableGnssRawMeasFullTrackingShouldBeOff() {
     72         mController.onPreferenceChange(mPreference, false /* new value */);
     73 
     74         final int mode = Settings.Global.getInt(mContext.getContentResolver(),
     75                 Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, -1 /* default */);
     76 
     77         assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
     78     }
     79 
     80     @Test
     81     public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
     82         Settings.Global.putInt(mContext.getContentResolver(),
     83                 Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, SETTING_VALUE_OFF);
     84         mController.updateState(mPreference);
     85 
     86         verify(mPreference).setChecked(false);
     87     }
     88 
     89     @Test
     90     public void updateState_settingEnabled_preferenceShouldBeChecked() {
     91         Settings.Global.putInt(mContext.getContentResolver(),
     92                 Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, SETTING_VALUE_ON);
     93         mController.updateState(mPreference);
     94 
     95         verify(mPreference).setChecked(true);
     96     }
     97 
     98     @Test
     99     public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
    100         mController.onDeveloperOptionsSwitchDisabled();
    101 
    102         final int mode = Settings.Global.getInt(mContext.getContentResolver(),
    103                 Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING, -1 /* default */);
    104 
    105         assertThat(mode).isEqualTo(SETTING_VALUE_OFF);
    106         verify(mPreference).setChecked(false);
    107         verify(mPreference).setEnabled(false);
    108     }
    109 }
    110