summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 17:42:36 +0000
committerjohnnyg@chromium.org <johnnyg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-08 17:42:36 +0000
commitfe13603a0c02d46b06c9ca7477131133455f688c (patch)
treef06ebf2a9323884d395875bad0a388237d6c861a /chrome/common
parente72302b0bad3354d391aa664c24ba51c7918efa0 (diff)
downloadchromium_src-fe13603a0c02d46b06c9ca7477131133455f688c.zip
chromium_src-fe13603a0c02d46b06c9ca7477131133455f688c.tar.gz
chromium_src-fe13603a0c02d46b06c9ca7477131133455f688c.tar.bz2
Fix a crash on Mac because the STL iterator behavior on delete is not consistent between platforms. Add a trivial test to make sure this works on all platforms.
BUG=40170 TEST=on Mac, create a notification (e.g. go/notify_demo.html), refresh the page while the toast is open. Review URL: http://codereview.chromium.org/1562016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43965 0039d316-1c4b-4281-b951-d872f2087c98
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();
+}
+