diff options
author | Peter Qiu <zqiu@google.com> | 2017-07-20 00:56:21 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-07-20 00:56:21 +0000 |
commit | 7b038e3159fe4469d4d4f3fd85bb5de53fb309f2 (patch) | |
tree | 330ccb18727cc5d5604f7895616d3466a18efa1a /tests | |
parent | 47c0707ab23c1b39b205f6ce7e3046f93dafcc9f (diff) | |
parent | 5adcd54d9534c1530a67ee14dc76737646ce5182 (diff) |
Merge "Display notification when wrong password error is detected" into oc-dr1-dev am: 96e29a8bc2
am: 5adcd54d95
Change-Id: I9afa128d0113ccb30f28200c7a0ca0dc1e6d4769
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 7 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java | 101 |
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 52622ef1b..eb1bae018 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -345,6 +345,7 @@ public class WifiStateMachineTest { @Mock SelfRecovery mSelfRecovery; @Mock IpManager mIpManager; @Mock TelephonyManager mTelephonyManager; + @Mock WrongPasswordNotifier mWrongPasswordNotifier; public WifiStateMachineTest() throws Exception { } @@ -437,7 +438,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(); @@ -1115,6 +1117,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)); @@ -1140,6 +1143,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); @@ -1147,6 +1151,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()); + } +} |