Merge "Refactor hotspot into a full page"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f357f78eef
@@ -16,10 +16,10 @@
|
||||
|
||||
package com.android.settings.core.codeinspection;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.core.instrumentation.InstrumentableFragmentCodeInspector;
|
||||
import com.android.settings.search.SearchIndexProviderCodeInspector;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.widget;
|
||||
|
||||
|
||||
import android.text.InputType;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ValidatedEditTextPreferenceTest {
|
||||
|
||||
@Mock
|
||||
private View mView;
|
||||
@Mock
|
||||
private ValidatedEditTextPreference.Validator mValidator;
|
||||
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindDialogView_noTextWatcher_shouldDoNothing() {
|
||||
mPreference.onBindDialogView(mView);
|
||||
|
||||
verifyZeroInteractions(mView);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindDialogView_hasValidator_shouldBindToEditText() {
|
||||
final EditText editText = spy(new EditText(RuntimeEnvironment.application));
|
||||
when(mView.findViewById(android.R.id.edit)).thenReturn(editText);
|
||||
|
||||
mPreference.setValidator(mValidator);
|
||||
mPreference.onBindDialogView(mView);
|
||||
|
||||
verify(editText).addTextChangedListener(any(TextWatcher.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindDialogView_isPassword_shouldSetInputType() {
|
||||
final EditText editText = spy(new EditText(RuntimeEnvironment.application));
|
||||
when(mView.findViewById(android.R.id.edit)).thenReturn(editText);
|
||||
|
||||
mPreference.setValidator(mValidator);
|
||||
mPreference.setIsPassword(true);
|
||||
mPreference.onBindDialogView(mView);
|
||||
|
||||
assertThat(editText.getInputType()
|
||||
& (InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_CLASS_TEXT))
|
||||
.isNotEqualTo(0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.wifi;
|
||||
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WifiUtilsTest {
|
||||
|
||||
@Test
|
||||
public void testSSID() {
|
||||
assertThat(WifiUtils.isSSIDTooLong("123")).isFalse();
|
||||
assertThat(WifiUtils.isSSIDTooLong("☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎☎")).isTrue();
|
||||
|
||||
assertThat(WifiUtils.isSSIDTooShort("123")).isFalse();
|
||||
assertThat(WifiUtils.isSSIDTooShort("")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPassword() {
|
||||
final String longPassword = "123456789012345678901234567890"
|
||||
+ "1234567890123456789012345678901234567890";
|
||||
assertThat(WifiUtils.isPasswordValid("123")).isFalse();
|
||||
assertThat(WifiUtils.isPasswordValid("12345678")).isTrue();
|
||||
assertThat(WifiUtils.isPasswordValid("1234567890")).isTrue();
|
||||
assertThat(WifiUtils.isPasswordValid(longPassword)).isFalse();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
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.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
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 WifiTetherApBandPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherApBandPreferenceController mController;
|
||||
private ListPreference mListPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mListPreference = new ListPreference(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mListPreference);
|
||||
|
||||
mController = new WifiTetherApBandPreferenceController(mContext, mListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_5GhzSupported_shouldDisplayFullList() {
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mListPreference.getEntries().length).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_5GhzNotSupported_shouldDisable() {
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(false);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mListPreference.getEntries()).isNull();
|
||||
assertThat(mListPreference.isEnabled()).isFalse();
|
||||
assertThat(mListPreference.getSummary())
|
||||
.isEqualTo(RuntimeEnvironment.application.getString(R.string.wifi_ap_choose_2G));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_shouldUpdateValue() {
|
||||
when(mWifiManager.is5GHzBandSupported()).thenReturn(true);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mListPreference, "1");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(1);
|
||||
|
||||
mController.onPreferenceChange(mListPreference, "0");
|
||||
assertThat(mController.getBandIndex()).isEqualTo(0);
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
}
|
||||
}
|
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
|
||||
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.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
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 WifiTetherPasswordPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherPasswordPreferenceController mController;
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
private WifiConfiguration mConfig;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
|
||||
mConfig = new WifiConfiguration();
|
||||
mConfig.SSID = "test_1234";
|
||||
mConfig.preSharedKey = "test_password";
|
||||
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
|
||||
mController = new WifiTetherPasswordPreferenceController(mContext, mListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldStylePreference() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(mPreference.getText()).isEqualTo(mConfig.preSharedKey);
|
||||
assertThat(mPreference.isPassword()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_shouldUpdateValue() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getPassword()).isEqualTo("1");
|
||||
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getPassword()).isEqualTo("0");
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
}
|
||||
}
|
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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.wifi.tether;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowSettings;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
WifiTetherPreferenceControllerTest.ShadowWifiTetherSettings.class
|
||||
})
|
||||
public class WifiTetherPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherPreferenceController mController;
|
||||
private Lifecycle mLifecycle;
|
||||
private Preference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mLifecycle = new Lifecycle();
|
||||
mPreference = new Preference(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_noTetherRegex_shouldReturnFalse() {
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{});
|
||||
mController = new WifiTetherPreferenceController(mContext, mLifecycle);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_hasTetherRegex_shouldReturnTrue() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resumeAndPause_shouldRegisterUnregisterReceiver() {
|
||||
final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
mLifecycle.onResume();
|
||||
mLifecycle.onPause();
|
||||
|
||||
verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
|
||||
verify(mContext).unregisterReceiver(receiver);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiver_apStateChangedToDisabled_shouldUpdatePreferenceSummary() {
|
||||
mController.displayPreference(mScreen);
|
||||
final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
|
||||
final Intent broadcast = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
broadcast.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_DISABLED);
|
||||
|
||||
receiver.onReceive(RuntimeEnvironment.application, broadcast);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
RuntimeEnvironment.application.getString(R.string.wifi_hotspot_off_subtext));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiver_apStateChangedToDisabling_shouldUpdatePreferenceSummary() {
|
||||
mController.displayPreference(mScreen);
|
||||
final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
|
||||
final Intent broadcast = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
broadcast.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_DISABLING);
|
||||
|
||||
receiver.onReceive(RuntimeEnvironment.application, broadcast);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
RuntimeEnvironment.application.getString(R.string.wifi_tether_stopping));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiver_goingToAirplaneMode_shouldClearPreferenceSummary() {
|
||||
final ContentResolver cr = mock(ContentResolver.class);
|
||||
when(mContext.getContentResolver()).thenReturn(cr);
|
||||
ShadowSettings.ShadowGlobal.putInt(cr, Settings.Global.AIRPLANE_MODE_ON, 1);
|
||||
mController.displayPreference(mScreen);
|
||||
final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
|
||||
final Intent broadcast = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
|
||||
receiver.onReceive(RuntimeEnvironment.application, broadcast);
|
||||
|
||||
assertThat(mPreference.getSummary().toString()).isEqualTo(
|
||||
RuntimeEnvironment.application.getString(R.string.summary_placeholder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiver_tetherEnabled_shouldUpdatePreferenceSummary() {
|
||||
mController.displayPreference(mScreen);
|
||||
final BroadcastReceiver receiver = ReflectionHelpers.getField(mController, "mReceiver");
|
||||
final Intent broadcast = new Intent(ConnectivityManager.ACTION_TETHER_STATE_CHANGED);
|
||||
final ArrayList<String> activeTethers = new ArrayList<>();
|
||||
activeTethers.add("1");
|
||||
broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER, activeTethers);
|
||||
broadcast.putStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER,
|
||||
new ArrayList<>());
|
||||
final WifiConfiguration configuration = new WifiConfiguration();
|
||||
configuration.SSID = "test-ap";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(configuration);
|
||||
|
||||
receiver.onReceive(RuntimeEnvironment.application, broadcast);
|
||||
|
||||
verify(mContext).getString(eq(R.string.wifi_tether_enabled_subtext), any());
|
||||
}
|
||||
|
||||
@Implements(WifiTetherSettings.class)
|
||||
public static final class ShadowWifiTetherSettings {
|
||||
|
||||
@Implementation
|
||||
public static boolean isTetherSettingPageEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.wifi.tether;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||
|
||||
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.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
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 WifiTetherSSIDPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private ConnectivityManager mConnectivityManager;
|
||||
@Mock
|
||||
private WifiManager mWifiManager;
|
||||
@Mock
|
||||
private WifiTetherBasePreferenceController.OnTetherConfigUpdateListener mListener;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private WifiTetherSSIDPreferenceController mController;
|
||||
private ValidatedEditTextPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mPreference = new ValidatedEditTextPreference(RuntimeEnvironment.application);
|
||||
|
||||
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifiManager);
|
||||
when(mContext.getSystemService(Context.CONNECTIVITY_SERVICE))
|
||||
.thenReturn(mConnectivityManager);
|
||||
when(mConnectivityManager.getTetherableWifiRegexs()).thenReturn(new String[]{"1", "2"});
|
||||
when(mContext.getResources()).thenReturn(RuntimeEnvironment.application.getResources());
|
||||
when(mScreen.findPreference(anyString())).thenReturn(mPreference);
|
||||
|
||||
mController = new WifiTetherSSIDPreferenceController(mContext, mListener);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_noWifiConfig_shouldDisplayDefaultSSID() {
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(null);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.getSSID())
|
||||
.isEqualTo(WifiTetherSSIDPreferenceController.DEFAULT_SSID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_hasCustomWifiConfig_shouldDisplayCustomSSID() {
|
||||
final WifiConfiguration config = new WifiConfiguration();
|
||||
config.SSID = "test_1234";
|
||||
when(mWifiManager.getWifiApConfiguration()).thenReturn(config);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
assertThat(mController.getSSID()).isEqualTo(config.SSID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changePreference_shouldUpdateValue() {
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPreferenceChange(mPreference, "1");
|
||||
assertThat(mController.getSSID()).isEqualTo("1");
|
||||
|
||||
mController.onPreferenceChange(mPreference, "0");
|
||||
assertThat(mController.getSSID()).isEqualTo("0");
|
||||
|
||||
verify(mListener, times(2)).onTetherConfigUpdated();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user