[Wi-Fi] Fix Wi-Fi broken tests
Bug: 150910070 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.wifi Change-Id: Ie9b9384610857e2999fe4642a93c2d31ce3315f3 Merged-In: Ie9b9384610857e2999fe4642a93c2d31ce3315f3
This commit is contained in:
@@ -1049,7 +1049,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
public void onFailure(int reason) {
|
public void onFailure(int reason) {
|
||||||
Activity activity = mFragment.getActivity();
|
Activity activity = mFragment.getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_failed_save_message,
|
R.string.wifi_failed_save_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
@@ -1090,7 +1090,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
final Activity activity = mFragment.getActivity();
|
final Activity activity = mFragment.getActivity();
|
||||||
// error handling, connected/saved network should have mWifiConfig.
|
// error handling, connected/saved network should have mWifiConfig.
|
||||||
if (mWifiConfig == null) {
|
if (mWifiConfig == null) {
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_failed_connect_message,
|
R.string.wifi_failed_connect_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
@@ -1116,7 +1116,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
if (state == STATE_ENABLE_WIFI) {
|
if (state == STATE_ENABLE_WIFI) {
|
||||||
Log.d(TAG, "Turn on Wi-Fi automatically!");
|
Log.d(TAG, "Turn on Wi-Fi automatically!");
|
||||||
updateConnectedButton(STATE_ENABLE_WIFI);
|
updateConnectedButton(STATE_ENABLE_WIFI);
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_turned_on_message,
|
R.string.wifi_turned_on_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
mWifiManager.setWifiEnabled(true);
|
mWifiManager.setWifiEnabled(true);
|
||||||
@@ -1137,7 +1137,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
stopTimer();
|
stopTimer();
|
||||||
// reset state
|
// reset state
|
||||||
state = STATE_NONE;
|
state = STATE_NONE;
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_failed_connect_message,
|
R.string.wifi_failed_connect_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
updateConnectedButton(STATE_ENABLE_WIFI_FAILED);
|
updateConnectedButton(STATE_ENABLE_WIFI_FAILED);
|
||||||
@@ -1159,7 +1159,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
Log.d(TAG, "connected");
|
Log.d(TAG, "connected");
|
||||||
stopTimer();
|
stopTimer();
|
||||||
updateConnectedButton(STATE_CONNECTED);
|
updateConnectedButton(STATE_CONNECTED);
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
mContext.getString(R.string.wifi_connected_to_message,
|
mContext.getString(R.string.wifi_connected_to_message,
|
||||||
mAccessPoint.getTitle()),
|
mAccessPoint.getTitle()),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
@@ -1170,7 +1170,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
stopTimer();
|
stopTimer();
|
||||||
// reset state
|
// reset state
|
||||||
state = STATE_NONE;
|
state = STATE_NONE;
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_not_in_range_message,
|
R.string.wifi_not_in_range_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
updateConnectedButton(STATE_NOT_IN_RANGE);
|
updateConnectedButton(STATE_NOT_IN_RANGE);
|
||||||
@@ -1179,7 +1179,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
|
|||||||
stopTimer();
|
stopTimer();
|
||||||
// reset state
|
// reset state
|
||||||
state = STATE_NONE;
|
state = STATE_NONE;
|
||||||
Toast.makeText(activity,
|
Toast.makeText(mContext,
|
||||||
R.string.wifi_failed_connect_message,
|
R.string.wifi_failed_connect_message,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
updateConnectedButton(STATE_FAILED);
|
updateConnectedButton(STATE_FAILED);
|
||||||
|
@@ -94,7 +94,7 @@ public class WifiTetherSwitchBarController implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (mSwitch.isChecked()) {
|
if (((Switch) v).isChecked()) {
|
||||||
startTether();
|
startTether();
|
||||||
} else {
|
} else {
|
||||||
stopTether();
|
stopTether();
|
||||||
|
@@ -49,6 +49,7 @@ import android.os.Bundle;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.util.FeatureFlagUtils;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -296,6 +297,10 @@ public class WifiSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
||||||
public void checkDataUsagePreference_perferenceInvisibleIfWifiNotSupported() {
|
public void checkDataUsagePreference_perferenceInvisibleIfWifiNotSupported() {
|
||||||
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setUpForOnCreate();
|
setUpForOnCreate();
|
||||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;
|
||||||
|
|
||||||
@@ -307,6 +312,10 @@ public class WifiSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
||||||
public void checkDataUsagePreference_perferenceVisibleIfWifiSupported() {
|
public void checkDataUsagePreference_perferenceVisibleIfWifiSupported() {
|
||||||
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setUpForOnCreate();
|
setUpForOnCreate();
|
||||||
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;
|
||||||
|
|
||||||
@@ -351,6 +360,10 @@ public class WifiSettingsTest {
|
|||||||
@Test
|
@Test
|
||||||
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
@Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
|
||||||
public void clickOnWifiNetworkWith_shouldStartCaptivePortalApp() {
|
public void clickOnWifiNetworkWith_shouldStartCaptivePortalApp() {
|
||||||
|
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
when(mWifiManager.getConfiguredNetworks()).thenReturn(createMockWifiConfigurations(
|
when(mWifiManager.getConfiguredNetworks()).thenReturn(createMockWifiConfigurations(
|
||||||
NUM_NETWORKS));
|
NUM_NETWORKS));
|
||||||
when(mWifiTracker.isConnected()).thenReturn(true);
|
when(mWifiTracker.isConnected()).thenReturn(true);
|
||||||
|
@@ -21,7 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@@ -32,6 +32,7 @@ import android.content.Context;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkPolicyManager;
|
import android.net.NetworkPolicyManager;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.widget.Switch;
|
||||||
|
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
|
|
||||||
@@ -98,14 +99,21 @@ public class WifiTetherSwitchBarControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSwitchToggled_onlyStartsTetherWhenNeeded() {
|
public void onSwitchToggled_switchOff_noStartTethering() {
|
||||||
when(mWifiManager.isWifiApEnabled()).thenReturn(true);
|
final Switch mockSwitch = mock(Switch.class);
|
||||||
mController.onClick(mSwitchBar.getSwitch());
|
when(mockSwitch.isChecked()).thenReturn(false);
|
||||||
|
|
||||||
|
mController.onClick(mockSwitch);
|
||||||
|
|
||||||
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
|
||||||
|
}
|
||||||
|
|
||||||
doReturn(false).when(mWifiManager).isWifiApEnabled();
|
@Test
|
||||||
mController.onClick(mSwitchBar.getSwitch());
|
public void onSwitchToggled_switchOn_startTethering() {
|
||||||
|
final Switch mockSwitch = mock(Switch.class);
|
||||||
|
when(mockSwitch.isChecked()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.onClick(mockSwitch);
|
||||||
|
|
||||||
verify(mConnectivityManager, times(1))
|
verify(mConnectivityManager, times(1))
|
||||||
.startTethering(anyInt(), anyBoolean(), any(), any());
|
.startTethering(anyInt(), anyBoolean(), any(), any());
|
||||||
|
Reference in New Issue
Block a user