diff options
3 files changed, 29 insertions, 3 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index fce7d36..f322700 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -930,6 +930,7 @@ 'common/bzip2_unittest.cc', 'common/child_process_logging_mac_unittest.mm', 'common/common_param_traits_unittest.cc', + 'common/desktop_notifications/active_notification_tracker_unittest.cc', 'common/extensions/extension_action_unittest.cc', 'common/extensions/extension_file_util_unittest.cc', 'common/extensions/extension_l10n_util_unittest.cc', 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(); +} + |