diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2017-09-07 23:17:07 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-09-07 23:17:07 +0000 |
commit | 7fc4bd4bdbe70f4d1e7c471ba008c7c4f9f287e8 (patch) | |
tree | a3c29e0aac7569b18879230a5080c39576520cec /tests | |
parent | d0cafb20481fc76e546deb9d71626e79e320d440 (diff) | |
parent | 08ffa580f6756129929667785408da377b363787 (diff) |
Merge "ONA: Implement connection attempt and failure callback." into oc-mr1-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java | 32 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 44 |
2 files changed, 68 insertions, 8 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java index 957fc2294..7c1223a79 100644 --- a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java +++ b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java @@ -33,6 +33,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.net.wifi.ScanResult; +import android.os.Message; import android.os.UserHandle; import android.os.UserManager; import android.os.test.TestLooper; @@ -66,6 +67,7 @@ public class OpenNetworkNotifierTest { @Mock private WifiConfigManager mWifiConfigManager; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Notification.Builder mNotificationBuilder; @Mock private NotificationManager mNotificationManager; + @Mock private WifiStateMachine mWifiStateMachine; @Mock private OpenNetworkRecommender mOpenNetworkRecommender; @Mock private UserManager mUserManager; private OpenNetworkNotifier mNotificationController; @@ -103,7 +105,7 @@ public class OpenNetworkNotifierTest { TestLooper mock_looper = new TestLooper(); mNotificationController = new OpenNetworkNotifier( mContext, mock_looper.getLooper(), mFrameworkFacade, mClock, mWifiConfigManager, - mWifiConfigStore, mOpenNetworkRecommender); + mWifiConfigStore, mWifiStateMachine, mOpenNetworkRecommender); ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor = ArgumentCaptor.forClass(BroadcastReceiver.class); verify(mContext).registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any()); @@ -348,4 +350,32 @@ public class OpenNetworkNotifierTest { verify(mNotificationManager).cancel(anyInt()); } + + /** + * {@link OpenNetworkNotifier#ACTION_CONNECT_TO_NETWORK} does not connect to any network if + * there is no current recommendation. + */ + @Test + public void actionConnectToNetwork_currentRecommendationIsNull_doesNothing() { + mBroadcastReceiver.onReceive(mContext, + new Intent(OpenNetworkNotifier.ACTION_CONNECT_TO_NETWORK)); + + verify(mWifiStateMachine, never()).sendMessage(any(Message.class)); + } + + /** + * {@link OpenNetworkNotifier#ACTION_CONNECT_TO_NETWORK} connects to the currently recommended + * network if it exists. + */ + @Test + public void actionConnectToNetwork_currentRecommendationExists_connectsToNetwork() { + mNotificationController.handleScanResults(mOpenNetworks); + + verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); + + mBroadcastReceiver.onReceive(mContext, + new Intent(OpenNetworkNotifier.ACTION_CONNECT_TO_NETWORK)); + + verify(mWifiStateMachine).sendMessage(any(Message.class)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index a8278d365..cb1160cc1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -614,7 +614,7 @@ public class WifiConnectivityManagerTest { * Expected behavior: ONA handles scan results */ @Test - public void wifiDisconnected_noConnectionCandidate_openNetworkNotificationScanResultsHandled() { + public void wifiDisconnected_noConnectionCandidate_openNetworkNotifierScanResultsHandled() { // no connection candidate selected when(mWifiNS.selectNetwork(anyObject(), anyObject(), anyObject(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(null); @@ -643,12 +643,12 @@ public class WifiConnectivityManagerTest { * Expected behavior: ONA clears pending notification and does not reset repeat delay. */ @Test - public void wifiConnected_openNetworkNotificationClearsPendingNotification() { + public void wifiConnected_openNetworkNotifierClearsPendingNotification() { // Set WiFi to connected state mWifiConnectivityManager.handleConnectionStateChanged( WifiConnectivityManager.WIFI_STATE_CONNECTED); - verify(mOpenNetworkNotifier).clearPendingNotification(false /* isRepeatDelayReset*/); + verify(mOpenNetworkNotifier).clearPendingNotification(false /* resetRepeatDelay*/); } /** @@ -658,7 +658,7 @@ public class WifiConnectivityManagerTest { * Expected behavior: ONA does not clear pending notification. */ @Test - public void wifiDisconnected_openNetworkNotificationDoesNotClearPendingNotification() { + public void wifiDisconnected_openNetworkNotifierDoesNotClearPendingNotification() { // Set WiFi to disconnected state mWifiConnectivityManager.handleConnectionStateChanged( WifiConnectivityManager.WIFI_STATE_DISCONNECTED); @@ -667,22 +667,52 @@ public class WifiConnectivityManagerTest { } /** + * When a Wi-Fi connection attempt ends, {@link OpenNetworkNotifier} handles the connection + * failure. A failure code that is not {@link WifiMetrics.ConnectionEvent#FAILURE_NONE} + * represents a connection failure. + * + * Expected behavior: ONA handles connection failure. + */ + @Test + public void wifiConnectionEndsWithFailure_openNetworkNotifierHandlesConnectionFailure() { + mWifiConnectivityManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_CONNECT_NETWORK_FAILED); + + verify(mOpenNetworkNotifier).handleConnectionFailure(); + } + + /** + * When a Wi-Fi connection attempt ends, {@link OpenNetworkNotifier} does not handle connection + * failure after a successful connection. {@link WifiMetrics.ConnectionEvent#FAILURE_NONE} + * represents a successful connection. + * + * Expected behavior: ONA does nothing. + */ + @Test + public void wifiConnectionEndsWithSuccess_openNetworkNotifierDoesNotHandleConnectionFailure() { + mWifiConnectivityManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_NONE); + + verify(mOpenNetworkNotifier, never()).handleConnectionFailure(); + } + + /** * When Wi-Fi is disabled, clear the pending notification and reset notification repeat delay. * * Expected behavior: clear pending notification and reset notification repeat delay * */ @Test - public void openNetworkNotificationControllerToggledOnWifiStateChanges() { + public void openNetworkNotifierClearsPendingNotificationOnWifiDisabled() { mWifiConnectivityManager.setWifiEnabled(false); - verify(mOpenNetworkNotifier).clearPendingNotification(true /* isRepeatDelayReset */); + verify(mOpenNetworkNotifier).clearPendingNotification(true /* resetRepeatDelay */); } /** * Verify that the ONA controller tracks screen state changes. */ @Test - public void openNetworkNotificationControllerTracksScreenStateChanges() { + public void openNetworkNotifierTracksScreenStateChanges() { mWifiConnectivityManager.handleScreenStateChanged(false); verify(mOpenNetworkNotifier).handleScreenStateChanged(false); |