1 /* 2 * Copyright (C) 2018 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.location; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import android.content.Context; 22 import android.provider.Settings; 23 24 import com.android.settings.R; 25 26 import org.junit.Before; 27 import org.junit.Test; 28 import org.junit.runner.RunWith; 29 import org.robolectric.RobolectricTestRunner; 30 import org.robolectric.RuntimeEnvironment; 31 import org.robolectric.annotation.Config; 32 33 @RunWith(RobolectricTestRunner.class) 34 public class LocationScanningPreferenceControllerTest { 35 private Context mContext; 36 private LocationScanningPreferenceController mController; 37 38 @Before setUp()39 public void setUp() { 40 mContext = RuntimeEnvironment.application; 41 mController = new LocationScanningPreferenceController(mContext); 42 } 43 44 @Test testLocationScanning_byDefault_shouldBeShown()45 public void testLocationScanning_byDefault_shouldBeShown() { 46 assertThat(mController.isAvailable()).isTrue(); 47 } 48 49 @Test testLocationScanning_WifiOnBleOn()50 public void testLocationScanning_WifiOnBleOn() { 51 Settings.Global.putInt(mContext.getContentResolver(), 52 Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1); 53 Settings.Global.putInt(mContext.getContentResolver(), 54 Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1); 55 assertThat(mController.getSummary()).isEqualTo( 56 mContext.getString(R.string.scanning_status_text_wifi_on_ble_on)); 57 } 58 59 @Test testLocationScanning_WifiOnBleOff()60 public void testLocationScanning_WifiOnBleOff() { 61 Settings.Global.putInt(mContext.getContentResolver(), 62 Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1); 63 Settings.Global.putInt(mContext.getContentResolver(), 64 Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0); 65 assertThat(mController.getSummary()).isEqualTo( 66 mContext.getString(R.string.scanning_status_text_wifi_on_ble_off)); 67 } 68 69 @Test testLocationScanning_WifiOffBleOn()70 public void testLocationScanning_WifiOffBleOn() { 71 Settings.Global.putInt(mContext.getContentResolver(), 72 Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0); 73 Settings.Global.putInt(mContext.getContentResolver(), 74 Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1); 75 assertThat(mController.getSummary()).isEqualTo( 76 mContext.getString(R.string.scanning_status_text_wifi_off_ble_on)); 77 } 78 79 @Test testLocationScanning_WifiOffBleOff()80 public void testLocationScanning_WifiOffBleOff() { 81 Settings.Global.putInt(mContext.getContentResolver(), 82 Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0); 83 Settings.Global.putInt(mContext.getContentResolver(), 84 Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0); 85 assertThat(mController.getSummary()).isEqualTo( 86 mContext.getString(R.string.scanning_status_text_wifi_off_ble_off)); 87 } 88 89 @Test 90 @Config(qualifiers = "mcc999") testLocationScanning_ifDisabled_shouldNotBeShown()91 public void testLocationScanning_ifDisabled_shouldNotBeShown() { 92 assertThat(mController.isAvailable()).isFalse(); 93 } 94 }