diff options
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java | 109 |
1 files changed, 59 insertions, 50 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java index 3af19e163..46ec1597e 100644 --- a/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java +++ b/tests/wifitests/src/com/android/server/wifi/OpenNetworkNotifierTest.java @@ -120,7 +120,7 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); } @@ -144,42 +144,48 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mNotificationController.handleScanResults(new ArrayList<>()); verify(mNotificationManager).cancel(anyInt()); } + /** - * When a notification is showing, screen is off, and scan results with no open networks are - * handled, the notification is cleared. + * When a notification is showing and no recommendation is made for the new scan results, the + * notification is cleared. */ @Test - public void handleScanResults_notificationShown_screenOff_emptyList_notificationCleared() { + public void handleScanResults_notificationShown_noRecommendation_notificationCleared() { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); - mNotificationController.handleScreenStateChanged(false); - mNotificationController.handleScanResults(new ArrayList<>()); + when(mOpenNetworkRecommender.recommendNetwork(any(), any())).thenReturn(null); + mNotificationController.handleScanResults(mOpenNetworks); verify(mNotificationManager).cancel(anyInt()); } /** - * If notification is showing, do not post another notification. + * When a notification is showing, screen is off, and scan results with no open networks are + * handled, the notification is cleared. */ @Test - public void handleScanResults_notificationShowing_doesNotRepostNotification() { - mNotificationController.handleScanResults(mOpenNetworks); + public void handleScanResults_notificationShown_screenOff_emptyList_notificationCleared() { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); + + mNotificationController.handleScreenStateChanged(false); + mNotificationController.handleScanResults(new ArrayList<>()); + + verify(mNotificationManager).cancel(anyInt()); } /** @@ -191,7 +197,7 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mNotificationController.clearPendingNotification(true); @@ -215,7 +221,7 @@ public class OpenNetworkNotifierTest { * new scan results with open networks. */ @Test - public void screenOff_handleScanResults_notificationNotDisplayed() { + public void screenOff_notificationNotShowing_handleScanResults_notificationNotDisplayed() { mNotificationController.handleScreenStateChanged(false); mNotificationController.handleScanResults(mOpenNetworks); @@ -224,69 +230,69 @@ public class OpenNetworkNotifierTest { } /** - * When a notification is posted and cleared without resetting delay, the next scan with open - * networks should not post another notification. + * When screen is off and notification is displayed, the notification can be updated with a new + * recommendation. */ @Test - public void postNotification_clearNotificationWithoutDelayReset_shouldNotPostNotification() { + public void screenOff_notificationShowing_handleScanResults_recommendationCanBeUpdated() { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); - mNotificationController.clearPendingNotification(false); - + mNotificationController.handleScreenStateChanged(false); mNotificationController.handleScanResults(mOpenNetworks); - // Recommendation made twice but no new notification posted. + // Recommendation made twice verify(mOpenNetworkRecommender, times(2)).recommendNetwork( mOpenNetworks, mBlacklistedSsids); - verify(mNotificationManager).notify(anyInt(), any()); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); - verify(mNotificationManager).cancel(anyInt()); + verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork); + verify(mNotificationManager, times(2)).notify(anyInt(), any()); } /** * When a notification is posted and cleared without resetting delay, the next scan with open - * networks should post a notification. + * networks should not post another notification. */ @Test - public void postNotification_clearNotificationWithDelayReset_shouldPostNotification() { + public void postNotification_clearNotificationWithoutDelayReset_shouldNotPostNotification() { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); - mNotificationController.clearPendingNotification(true); + mNotificationController.clearPendingNotification(false); + + verify(mNotificationManager).cancel(anyInt()); mNotificationController.handleScanResults(mOpenNetworks); - verify(mOpenNetworkRecommender, times(2)).recommendNetwork( - mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(1); - verify(mNotificationManager, times(2)).notify(anyInt(), any()); + // no new notification posted + verify(mNotificationManager).notify(anyInt(), any()); } /** - * When a notification is tapped, open Wi-Fi settings. + * When a notification is posted and cleared without resetting delay, the next scan with open + * networks should post a notification. */ @Test - public void notificationTap_opensWifiSettings() { + public void postNotification_clearNotificationWithDelayReset_shouldPostNotification() { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); - mBroadcastReceiver.onReceive( - mContext, - new Intent(ConnectToNetworkNotificationBuilder.ACTION_USER_TAPPED_CONTENT)); + mNotificationController.clearPendingNotification(true); - ArgumentCaptor<Intent> pickerIntentCaptor = ArgumentCaptor.forClass(Intent.class); - verify(mContext).startActivity(pickerIntentCaptor.capture()); - assertEquals(pickerIntentCaptor.getValue().getAction(), Settings.ACTION_WIFI_SETTINGS); + mNotificationController.handleScanResults(mOpenNetworks); + + verify(mOpenNetworkRecommender, times(2)).recommendNetwork( + mOpenNetworks, mBlacklistedSsids); + verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork); + verify(mNotificationManager, times(2)).notify(anyInt(), any()); } /** @@ -298,7 +304,7 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mBroadcastReceiver.onReceive( @@ -307,7 +313,9 @@ public class OpenNetworkNotifierTest { verify(mWifiConfigManager).saveToStore(false /* forceWrite */); - mNotificationController.handleScanResults(mOpenNetworks); + mNotificationController.clearPendingNotification(true); + List<ScanDetail> scanResults = mOpenNetworks; + mNotificationController.handleScanResults(scanResults); Set<String> expectedBlacklist = new ArraySet<>(); expectedBlacklist.add(mDummyNetwork.SSID); @@ -323,7 +331,7 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mNotificationController.clearPendingNotification(false); @@ -335,6 +343,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender, times(2)).recommendNetwork( mOpenNetworks, mBlacklistedSsids); + verify(mNotificationBuilder, times(2)).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager, times(2)).notify(anyInt(), any()); } @@ -356,7 +365,7 @@ public class OpenNetworkNotifierTest { mNotificationController.handleScanResults(mOpenNetworks); verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); when(mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_WIFI, UserHandle.CURRENT)) @@ -389,7 +398,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); // Initial Notification - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mBroadcastReceiver.onReceive(mContext, @@ -421,7 +430,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); // Initial Notification - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mNotificationController.handleWifiConnected(); @@ -439,7 +448,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); // Initial Notification - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mBroadcastReceiver.onReceive(mContext, @@ -477,7 +486,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); // Initial Notification - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mBroadcastReceiver.onReceive(mContext, @@ -505,7 +514,7 @@ public class OpenNetworkNotifierTest { verify(mOpenNetworkRecommender).recommendNetwork(mOpenNetworks, mBlacklistedSsids); // Initial Notification - verify(mNotificationBuilder).createConnectToNetworkNotification(1); + verify(mNotificationBuilder).createConnectToNetworkNotification(mDummyNetwork); verify(mNotificationManager).notify(anyInt(), any()); mBroadcastReceiver.onReceive(mContext, |