Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e0807a0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "[Wi-Fi] Fix Wi-Fi broken tests" into rvc-dev am: 534bb50e

Change-Id: I808a81e954fab8d93583300fedd006d3cb8bebe3
parents 4758893d 534bb50e
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -1049,7 +1049,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                public void onFailure(int reason) {
                    Activity activity = mFragment.getActivity();
                    if (activity != null) {
                        Toast.makeText(activity,
                        Toast.makeText(mContext,
                                R.string.wifi_failed_save_message,
                                Toast.LENGTH_SHORT).show();
                    }
@@ -1090,7 +1090,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
        final Activity activity = mFragment.getActivity();
        // error handling, connected/saved network should have mWifiConfig.
        if (mWifiConfig == null) {
            Toast.makeText(activity,
            Toast.makeText(mContext,
                    R.string.wifi_failed_connect_message,
                    Toast.LENGTH_SHORT).show();
            return;
@@ -1116,7 +1116,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                if (state == STATE_ENABLE_WIFI) {
                    Log.d(TAG, "Turn on Wi-Fi automatically!");
                    updateConnectedButton(STATE_ENABLE_WIFI);
                    Toast.makeText(activity,
                    Toast.makeText(mContext,
                            R.string.wifi_turned_on_message,
                            Toast.LENGTH_SHORT).show();
                    mWifiManager.setWifiEnabled(true);
@@ -1137,7 +1137,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                    stopTimer();
                    // reset state
                    state = STATE_NONE;
                    Toast.makeText(activity,
                    Toast.makeText(mContext,
                            R.string.wifi_failed_connect_message,
                            Toast.LENGTH_SHORT).show();
                    updateConnectedButton(STATE_ENABLE_WIFI_FAILED);
@@ -1159,7 +1159,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                    Log.d(TAG, "connected");
                    stopTimer();
                    updateConnectedButton(STATE_CONNECTED);
                    Toast.makeText(activity,
                    Toast.makeText(mContext,
                            mContext.getString(R.string.wifi_connected_to_message,
                                    mAccessPoint.getTitle()),
                            Toast.LENGTH_SHORT).show();
@@ -1170,7 +1170,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                    stopTimer();
                    // reset state
                    state = STATE_NONE;
                    Toast.makeText(activity,
                    Toast.makeText(mContext,
                            R.string.wifi_not_in_range_message,
                            Toast.LENGTH_SHORT).show();
                    updateConnectedButton(STATE_NOT_IN_RANGE);
@@ -1179,7 +1179,7 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController
                    stopTimer();
                    // reset state
                    state = STATE_NONE;
                    Toast.makeText(activity,
                    Toast.makeText(mContext,
                            R.string.wifi_failed_connect_message,
                            Toast.LENGTH_SHORT).show();
                    updateConnectedButton(STATE_FAILED);
+1 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class WifiTetherSwitchBarController implements

    @Override
    public void onClick(View v) {
        if (mSwitch.isChecked()) {
        if (((Switch) v).isChecked()) {
            startTether();
        } else {
            stopTether();
+13 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.Bundle;
import android.os.PowerManager;
import android.os.UserManager;
import android.provider.Settings;
import android.util.FeatureFlagUtils;
import android.view.ContextMenu;
import android.view.View;

@@ -296,6 +297,10 @@ public class WifiSettingsTest {
    @Test
    @Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
    public void checkDataUsagePreference_perferenceInvisibleIfWifiNotSupported() {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
            return;
        }

        setUpForOnCreate();
        ShadowDataUsageUtils.IS_WIFI_SUPPORTED = false;

@@ -307,6 +312,10 @@ public class WifiSettingsTest {
    @Test
    @Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
    public void checkDataUsagePreference_perferenceVisibleIfWifiSupported() {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
            return;
        }

        setUpForOnCreate();
        ShadowDataUsageUtils.IS_WIFI_SUPPORTED = true;

@@ -351,6 +360,10 @@ public class WifiSettingsTest {
    @Test
    @Config(shadows = {ShadowDataUsageUtils.class, ShadowFragment.class})
    public void clickOnWifiNetworkWith_shouldStartCaptivePortalApp() {
        if (FeatureFlagUtils.isEnabled(mContext, FeatureFlagUtils.SETTINGS_WIFITRACKER2)) {
            return;
        }

        when(mWifiManager.getConfiguredNetworks()).thenReturn(createMockWifiConfigurations(
                NUM_NETWORKS));
        when(mWifiTracker.isConnected()).thenReturn(true);
+14 −6
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
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.spy;
import static org.mockito.Mockito.times;
@@ -32,6 +32,7 @@ import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkPolicyManager;
import android.net.wifi.WifiManager;
import android.widget.Switch;

import com.android.settings.widget.SwitchBar;

@@ -98,14 +99,21 @@ public class WifiTetherSwitchBarControllerTest {
    }

    @Test
    public void onSwitchToggled_onlyStartsTetherWhenNeeded() {
        when(mWifiManager.isWifiApEnabled()).thenReturn(true);
        mController.onClick(mSwitchBar.getSwitch());
    public void onSwitchToggled_switchOff_noStartTethering() {
        final Switch mockSwitch = mock(Switch.class);
        when(mockSwitch.isChecked()).thenReturn(false);

        mController.onClick(mockSwitch);

        verify(mConnectivityManager, never()).startTethering(anyInt(), anyBoolean(), any(), any());
    }

    @Test
    public void onSwitchToggled_switchOn_startTethering() {
        final Switch mockSwitch = mock(Switch.class);
        when(mockSwitch.isChecked()).thenReturn(true);

        doReturn(false).when(mWifiManager).isWifiApEnabled();
        mController.onClick(mSwitchBar.getSwitch());
        mController.onClick(mockSwitch);

        verify(mConnectivityManager, times(1))
                .startTethering(anyInt(), anyBoolean(), any(), any());