Add getActiveNotifications to existing NoMan tests.

This has the dual benefit of testing the new API (requires
change I8cd61095 in frameworks/base) as well as providing
programmatic test of the old API rather than relying on
human verification (or just hoping everything worked).

Change-Id: Ieb6b2c50cf022f789edf65038156aad6d4f52133
diff --git a/tests/tests/app/src/android/app/cts/NotificationManagerTest.java b/tests/tests/app/src/android/app/cts/NotificationManagerTest.java
index 9a895ea..23dac25 100644
--- a/tests/tests/app/src/android/app/cts/NotificationManagerTest.java
+++ b/tests/tests/app/src/android/app/cts/NotificationManagerTest.java
@@ -22,12 +22,16 @@
 import android.content.Context;
 import android.content.Intent;
 import android.provider.Telephony.Threads;
+import android.service.notification.StatusBarNotification;
 import android.test.AndroidTestCase;
+import android.util.Log;
 
 import com.android.cts.app.stub.R;
 
 
 public class NotificationManagerTest extends AndroidTestCase {
+    final String TAG = NotificationManagerTest.class.getSimpleName();
+    final boolean DEBUG = false;
 
     private NotificationManager mNotificationManager;
 
@@ -36,6 +40,8 @@
         super.setUp();
         mNotificationManager = (NotificationManager) mContext.getSystemService(
                 Context.NOTIFICATION_SERVICE);
+        // clear the deck so that our getActiveNotifications results are predictable
+        mNotificationManager.cancelAll();
     }
 
     @Override
@@ -45,21 +51,52 @@
     }
 
     public void testNotify() {
+        mNotificationManager.cancelAll();
+
         final int id = 1;
         sendNotification(id, R.drawable.black);
+        // test updating the same notification
+        sendNotification(id, R.drawable.blue);
+        sendNotification(id, R.drawable.yellow);
+
+        // assume that sendNotification tested to make sure individual notifications were present
+        StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
+        for (StatusBarNotification sbn : sbns) {
+            if (sbn.getId() != id) {
+                fail("we got back other notifications besides the one we posted: "
+                        + sbn.getKey());
+            }
+        }
     }
 
     public void testCancel() {
         final int id = 9;
         sendNotification(id, R.drawable.black);
         mNotificationManager.cancel(id);
+
+        StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
+        for (StatusBarNotification sbn : sbns) {
+            assertFalse("canceled notification was still alive, id=" + id, sbn.getId() == id);
+        }
     }
 
     public void testCancelAll() {
         sendNotification(1, R.drawable.black);
         sendNotification(2, R.drawable.blue);
         sendNotification(3, R.drawable.yellow);
+
+        if (DEBUG) {
+            Log.d(TAG, "posted 3 notifications, here they are: ");
+            StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
+            for (StatusBarNotification sbn : sbns) {
+                Log.d(TAG, "  " + sbn);
+            }
+            Log.d(TAG, "about to cancel...");
+        }
         mNotificationManager.cancelAll();
+
+        StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
+        assertTrue("notification list was not empty after cancelAll", sbns.length == 0);
     }
 
     private void sendNotification(final int id, final int icon) {
@@ -76,6 +113,11 @@
         notification.setLatestEventInfo(mContext, "notify#" + id, "This is #" + id
                 + "notification  ", pendingIntent);
         mNotificationManager.notify(id, notification);
-    }
 
+        StatusBarNotification[] sbns = mNotificationManager.getActiveNotifications();
+        for (StatusBarNotification sbn : sbns) {
+            if (sbn.getId() == id) return;
+        }
+        fail("couldn't find posted notification id=" + id);
+    }
 }