summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/desktop_notifications/active_notification_tracker.cc5
-rw-r--r--chrome/common/desktop_notifications/active_notification_tracker_unittest.cc26
2 files changed, 28 insertions, 3 deletions
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc
index bc25838..0bfff59 100644
--- a/chrome/common/desktop_notifications/active_notification_tracker.cc
+++ b/chrome/common/desktop_notifications/active_notification_tracker.cc
@@ -48,10 +48,9 @@ void ActiveNotificationTracker::UnregisterNotification(int id) {
}
void ActiveNotificationTracker::Clear() {
- ReverseTable::iterator iter = reverse_notification_table_.begin();
- while (iter != reverse_notification_table_.end()) {
+ while (!reverse_notification_table_.empty()) {
+ ReverseTable::iterator iter = reverse_notification_table_.begin();
UnregisterNotification((*iter).second);
- ++iter;
}
}
diff --git a/chrome/common/desktop_notifications/active_notification_tracker_unittest.cc b/chrome/common/desktop_notifications/active_notification_tracker_unittest.cc
new file mode 100644
index 0000000..9553a73
--- /dev/null
+++ b/chrome/common/desktop_notifications/active_notification_tracker_unittest.cc
@@ -0,0 +1,26 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/desktop_notifications/active_notification_tracker.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(ActiveNotificationTrackerTest, TestLookupAndClear) {
+ ActiveNotificationTracker tracker;
+
+ WebKit::WebNotification notification1;
+ int id1 = tracker.RegisterNotification(notification1);
+
+ WebKit::WebNotification notification2;
+ int id2 = tracker.RegisterNotification(notification2);
+
+ WebKit::WebNotification result;
+ tracker.GetNotification(id1, &result);
+ EXPECT_TRUE(result == notification1);
+
+ tracker.GetNotification(id2, &result);
+ EXPECT_TRUE(result == notification2);
+
+ tracker.Clear();
+}
+