summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-07-20 00:46:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-07-20 00:46:00 +0000
commit96e29a8bc2b03c301658ce3831e64113b060c427 (patch)
tree439744b1fee6785545b9fc1713ab224a08a2cde1 /tests
parent9cffbf45e26339f87536fbc07f750b8fdbd5b9cf (diff)
parente81e74137b3da0254cc7d77a5773ea9bff67d5f8 (diff)
Merge "Display notification when wrong password error is detected" into oc-dr1-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java7
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java101
2 files changed, 107 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index c91f937fe..fc2cda443 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -344,6 +344,7 @@ public class WifiStateMachineTest {
@Mock SelfRecovery mSelfRecovery;
@Mock IpManager mIpManager;
@Mock TelephonyManager mTelephonyManager;
+ @Mock WrongPasswordNotifier mWrongPasswordNotifier;
public WifiStateMachineTest() throws Exception {
}
@@ -436,7 +437,8 @@ public class WifiStateMachineTest {
private void initializeWsm() throws Exception {
mWsm = new WifiStateMachine(mContext, mFrameworkFacade, mLooper.getLooper(),
- mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative);
+ mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative,
+ mWrongPasswordNotifier);
mWsmThread = getWsmHandlerThread(mWsm);
final AsyncChannel channel = new AsyncChannel();
@@ -1113,6 +1115,7 @@ public class WifiStateMachineTest {
WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD);
mLooper.dispatchAll();
+ verify(mWrongPasswordNotifier, never()).onWrongPasswordError(anyString());
verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(),
eq(WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE));
@@ -1138,6 +1141,7 @@ public class WifiStateMachineTest {
verify(mWifiConfigManager).enableNetwork(eq(0), eq(true), anyInt());
WifiConfiguration config = new WifiConfiguration();
+ config.SSID = sSSID;
config.getNetworkSelectionStatus().setHasEverConnected(false);
when(mWifiConfigManager.getConfiguredNetwork(anyInt())).thenReturn(config);
@@ -1145,6 +1149,7 @@ public class WifiStateMachineTest {
WifiManager.ERROR_AUTH_FAILURE_WRONG_PSWD);
mLooper.dispatchAll();
+ verify(mWrongPasswordNotifier).onWrongPasswordError(eq(sSSID));
verify(mWifiConfigManager).updateNetworkSelectionStatus(anyInt(),
eq(WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD));
diff --git a/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java b/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java
new file mode 100644
index 000000000..405ab65c2
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.res.Resources;
+
+import com.android.internal.notification.SystemNotificationChannels;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.WrongPasswordNotifier}.
+ */
+public class WrongPasswordNotifierTest {
+ private static final String TEST_SSID = "Test SSID";
+
+ @Mock Context mContext;
+ @Mock Resources mResources;
+ @Mock NotificationManager mNotificationManager;
+ @Mock FrameworkFacade mFrameworkFacade;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Notification.Builder mNotificationBuilder;
+ WrongPasswordNotifier mWrongPassNotifier;
+
+ /**
+ * Sets up for unit test
+ */
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
+ .thenReturn(mNotificationManager);
+ when(mContext.getResources()).thenReturn(mResources);
+ mWrongPassNotifier =
+ new WrongPasswordNotifier(mContext, mFrameworkFacade);
+ }
+
+ /**
+ * Verify that a wrong password notification will be generated/pushed when a wrong password
+ * error is detected for the current connection.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void onWrongPasswordError() throws Exception {
+ when(mFrameworkFacade.makeNotificationBuilder(any(),
+ eq(SystemNotificationChannels.NETWORK_ALERTS))).thenReturn(mNotificationBuilder);
+ mWrongPassNotifier.onWrongPasswordError(TEST_SSID);
+ verify(mNotificationManager).notify(eq(WrongPasswordNotifier.NOTIFICATION_ID), any());
+ }
+
+ /**
+ * Verify that we will attempt to dismiss the wrong password notification when starting a new
+ * connection attempt with the previous connection resulting in a wrong password error.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void onNewConnectionAttemptWithPreviousWrongPasswordError() throws Exception {
+ onWrongPasswordError();
+ reset(mNotificationManager);
+
+ mWrongPassNotifier.onNewConnectionAttempt();
+ verify(mNotificationManager).cancel(any(), eq(WrongPasswordNotifier.NOTIFICATION_ID));
+ }
+
+ /**
+ * Verify that we don't attempt to dismiss the wrong password notification when starting a new
+ * connection attempt with the previous connection not resulting in a wrong password error.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void onNewConnectionAttemptWithoutPreviousWrongPasswordError() throws Exception {
+ mWrongPassNotifier.onNewConnectionAttempt();
+ verify(mNotificationManager, never()).cancel(any(), anyInt());
+ }
+}