diff options
author | Peter Qiu <zqiu@google.com> | 2017-07-07 10:25:31 -0700 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2017-07-14 11:04:11 -0700 |
commit | e81e74137b3da0254cc7d77a5773ea9bff67d5f8 (patch) | |
tree | 2d0c5ecdcd8b3f17ba8b1bbcc302030cb2e5e203 /tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java | |
parent | ec0922425c007ba22527e0cacad1445d5f0d0ad8 (diff) | |
download | android_frameworks_opt_net_wifi-e81e74137b3da0254cc7d77a5773ea9bff67d5f8.tar.gz android_frameworks_opt_net_wifi-e81e74137b3da0254cc7d77a5773ea9bff67d5f8.tar.bz2 android_frameworks_opt_net_wifi-e81e74137b3da0254cc7d77a5773ea9bff67d5f8.zip |
Display notification when wrong password error is detected
A new notification will be generated and displayed when the wrong
password error is detected for the current connection.
It will be dismissed when:
- the user manually dismiss it or tap on it
- attempting a new Wi-Fi network connection
- timeout, currently set to 5 minutes
The current landing page for the notification is the network list page,
it will be updated when the new landing page is ready (dialog prompting
for the new password).
Bug: 33245941
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manual testing
Change-Id: Iaa75bff6d96ed8c9e9d8472a840d03c54f9f2c52
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WrongPasswordNotifierTest.java | 101 |
1 files changed, 101 insertions, 0 deletions
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()); + } +} |