diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java b/tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java index 125fe7258e94..273b8fc3773b 100644 --- a/tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java +++ b/tests/net/java/com/android/server/connectivity/NetworkNotificationManagerTest.java @@ -17,6 +17,7 @@ package com.android.server.connectivity; import static com.android.server.connectivity.NetworkNotificationManager.NotificationType.*; + import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.eq; @@ -34,25 +35,23 @@ import android.content.pm.PackageManager; import android.content.res.Resources; import android.net.NetworkCapabilities; import android.net.NetworkInfo; -import android.support.test.runner.AndroidJUnit4; import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import android.telephony.TelephonyManager; import com.android.server.connectivity.NetworkNotificationManager.NotificationType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.junit.runner.RunWith; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; @RunWith(AndroidJUnit4.class) @SmallTest @@ -194,4 +193,54 @@ public class NetworkNotificationManagerTest { mManager.clearNotification(id); verify(mNotificationManager, times(1)).cancelAsUser(eq(tag), eq(SIGN_IN.eventId), any()); } + + @Test + public void testSameLevelNotifications() { + final int id = 101; + final String tag = NetworkNotificationManager.tagFor(id); + + mManager.showNotification(id, LOGGED_IN, mWifiNai, mCellNai, null, false); + verify(mNotificationManager, times(1)) + .notifyAsUser(eq(tag), eq(LOGGED_IN.eventId), any(), any()); + + mManager.showNotification(id, LOST_INTERNET, mWifiNai, mCellNai, null, false); + verify(mNotificationManager, times(1)) + .notifyAsUser(eq(tag), eq(LOST_INTERNET.eventId), any(), any()); + } + + @Test + public void testClearNotificationByType() { + final int id = 101; + final String tag = NetworkNotificationManager.tagFor(id); + + // clearNotification(int id, NotificationType notifyType) will check if given type is equal + // to previous type or not. If they are equal then clear the notification; if they are not + // equal then return. + + mManager.showNotification(id, LOGGED_IN, mWifiNai, mCellNai, null, false); + verify(mNotificationManager, times(1)) + .notifyAsUser(eq(tag), eq(LOGGED_IN.eventId), any(), any()); + + // Previous notification is LOGGED_IN and given type is LOGGED_IN too. The notification + // should be cleared. + mManager.clearNotification(id, LOGGED_IN); + verify(mNotificationManager, times(1)) + .cancelAsUser(eq(tag), eq(LOGGED_IN.eventId), any()); + + mManager.showNotification(id, LOGGED_IN, mWifiNai, mCellNai, null, false); + verify(mNotificationManager, times(2)) + .notifyAsUser(eq(tag), eq(LOGGED_IN.eventId), any(), any()); + + // LOST_INTERNET notification popup after LOGGED_IN notification. + mManager.showNotification(id, LOST_INTERNET, mWifiNai, mCellNai, null, false); + verify(mNotificationManager, times(1)) + .notifyAsUser(eq(tag), eq(LOST_INTERNET.eventId), any(), any()); + + // Previous notification is LOST_INTERNET and given type is LOGGED_IN. The notification + // shouldn't be cleared. + mManager.clearNotification(id, LOGGED_IN); + // LOST_INTERNET shouldn't be cleared. + verify(mNotificationManager, never()) + .cancelAsUser(eq(tag), eq(LOST_INTERNET.eventId), any()); + } } |