summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRebecca Silberstein <silberst@google.com>2017-05-11 11:34:07 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-05-11 11:34:07 +0000
commit7e39ddac8d7451985b6a6a753c9e7f6336f2b15e (patch)
tree2a20fc1b128074c7546005812e34f6b6bb876976 /tests
parentab68b41871ffaa9ac24042536c6f74c1bd306f1c (diff)
parent31b90afebaa66d7b5570aff5cfd8a51a0f5529f7 (diff)
Merge "WifiStateMachine: properly update wifi enabling" into oc-dev am: 4d31977e4f
am: 31b90afeba Change-Id: Ic94b3f7fdb341710b3b417964c20009f07c564ec
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java48
1 files changed, 42 insertions, 6 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 20dd11757..2e365a048 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -26,6 +26,7 @@ import android.app.ActivityManager;
import android.app.test.MockAnswerUtil.AnswerWithArguments;
import android.app.test.TestAlarmManager;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.Resources;
@@ -86,6 +87,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.ArgumentMatcher;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@@ -309,6 +311,7 @@ public class WifiStateMachineTest {
MockWifiMonitor mWifiMonitor;
TestIpManager mTestIpManager;
TestLooper mLooper;
+ Context mContext;
@Mock WifiScanner mWifiScanner;
@Mock SupplicantStateTracker mSupplicantStateTracker;
@@ -381,17 +384,17 @@ public class WifiStateMachineTest {
FrameworkFacade factory = getFrameworkFacade();
- Context context = getContext();
+ mContext = getContext();
Resources resources = getMockResources();
- when(context.getResources()).thenReturn(resources);
+ when(mContext.getResources()).thenReturn(resources);
- when(factory.getIntegerSetting(context,
+ when(factory.getIntegerSetting(mContext,
Settings.Global.WIFI_FREQUENCY_BAND,
WifiManager.WIFI_FREQUENCY_BAND_AUTO)).thenReturn(
WifiManager.WIFI_FREQUENCY_BAND_AUTO);
- when(factory.makeApConfigStore(eq(context), eq(mBackupManagerProxy)))
+ when(factory.makeApConfigStore(eq(mContext), eq(mBackupManagerProxy)))
.thenReturn(mApConfigStore);
when(factory.makeSupplicantStateTracker(
@@ -407,7 +410,7 @@ public class WifiStateMachineTest {
when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder);
when(mClientInterface.asBinder()).thenReturn(mClientInterfaceBinder);
- mWsm = new WifiStateMachine(context, factory, mLooper.getLooper(),
+ mWsm = new WifiStateMachine(mContext, factory, mLooper.getLooper(),
mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative);
mWsmThread = getWsmHandlerThread(mWsm);
@@ -430,7 +433,7 @@ public class WifiStateMachineTest {
}
};
- channel.connect(context, handler, mWsm.getMessenger());
+ channel.connect(mContext, handler, mWsm.getMessenger());
mLooper.dispatchAll();
/* Now channel is supposed to be connected */
@@ -465,6 +468,9 @@ public class WifiStateMachineTest {
public void loadComponentsInStaMode() throws Exception {
startSupplicantAndDispatchMessages();
+ verify(mContext).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), eq(UserHandle.ALL));
+
assertEquals("DisconnectedState", getCurrentState().getName());
}
@@ -484,6 +490,9 @@ public class WifiStateMachineTest {
mWsm.setSupplicantRunning(true);
mLooper.dispatchAll();
assertEquals("InitialState", getCurrentState().getName());
+ // we should not be sending a wifi enabling update
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
@Test
@@ -571,6 +580,9 @@ public class WifiStateMachineTest {
assertEquals(WifiStateMachine.SCAN_ONLY_MODE, mWsm.getOperationalModeForTest());
assertEquals("ScanModeState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
+
// switch to connect mode and verify wifi is reported as enabled
mWsm.setOperationalMode(WifiStateMachine.CONNECT_MODE);
@@ -578,6 +590,12 @@ public class WifiStateMachineTest {
assertEquals("DisconnectedState", getCurrentState().getName());
assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest());
assertEquals(WifiManager.WIFI_STATE_ENABLED, mWsm.syncGetWifiState());
+ verify(mContext).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), eq(UserHandle.ALL));
+
+ // reset the expectations on mContext since we did get an expected broadcast, but we should
+ // not on the next transition
+ reset(mContext);
// now go back to scan mode with "wifi disabled" to verify the reported wifi state.
mWsm.setOperationalMode(WifiStateMachine.SCAN_ONLY_WITH_WIFI_OFF_MODE);
@@ -586,6 +604,8 @@ public class WifiStateMachineTest {
mWsm.getOperationalModeForTest());
assertEquals("ScanModeState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
// now go to AP mode
mWsm.setSupplicantRunning(false);
@@ -595,8 +615,22 @@ public class WifiStateMachineTest {
mLooper.dispatchAll();
assertEquals("SoftApState", getCurrentState().getName());
assertEquals(WifiManager.WIFI_STATE_DISABLED, mWsm.syncGetWifiState());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
+ private class WifiEnablingStateIntentMatcher implements ArgumentMatcher<Intent> {
+ @Override
+ public boolean matches(Intent intent) {
+ if (WifiManager.WIFI_STATE_CHANGED_ACTION != intent.getAction()) {
+ // not the correct type
+ return false;
+ }
+ return WifiManager.WIFI_STATE_ENABLING
+ == intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+ WifiManager.WIFI_STATE_DISABLED);
+ }
+ }
/**
* Test that mode changes for WifiStateMachine in the InitialState are realized when supplicant
@@ -620,6 +654,8 @@ public class WifiStateMachineTest {
startSupplicantAndDispatchMessages();
assertEquals("ScanModeState", getCurrentState().getName());
+ verify(mContext, never()).sendStickyBroadcastAsUser(
+ (Intent) argThat(new WifiEnablingStateIntentMatcher()), any());
}
/**