| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/notification_service.h" | 5 #include "chrome/common/notification_service.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 class NotificationServiceTest: public testing::Test { | 10 class NotificationServiceTest: public testing::Test { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 service->Notify(NotificationType::IDLE, | 134 service->Notify(NotificationType::IDLE, |
| 135 Source<TestSource>(&test_source), | 135 Source<TestSource>(&test_source), |
| 136 NotificationService::NoDetails()); | 136 NotificationService::NoDetails()); |
| 137 | 137 |
| 138 EXPECT_EQ(5, all_types_all_sources.notification_count()); | 138 EXPECT_EQ(5, all_types_all_sources.notification_count()); |
| 139 EXPECT_EQ(3, idle_all_sources.notification_count()); | 139 EXPECT_EQ(3, idle_all_sources.notification_count()); |
| 140 EXPECT_EQ(2, all_types_test_source.notification_count()); | 140 EXPECT_EQ(2, all_types_test_source.notification_count()); |
| 141 EXPECT_EQ(1, idle_test_source.notification_count()); | 141 EXPECT_EQ(1, idle_test_source.notification_count()); |
| 142 | 142 |
| 143 // Removing an observer that isn't there is a no-op, this should be fine. | 143 // Removing an observer that isn't there is a no-op, this should be fine. |
| 144 service->RemoveObserver( | 144 service->RemoveObserver(&all_types_all_sources, |
| 145 &all_types_all_sources, NotificationType::ALL, NotificationService::AllSourc
es()); | 145 NotificationType::ALL, |
| 146 NotificationService::AllSources()); |
| 146 } | 147 } |
| 147 | 148 |
| 148 TEST(NotificationServiceTest, MultipleRegistration) { | 149 TEST(NotificationServiceTest, MultipleRegistration) { |
| 149 TestSource test_source; | 150 TestSource test_source; |
| 150 | 151 |
| 151 TestObserver idle_test_source; | 152 TestObserver idle_test_source; |
| 152 | 153 |
| 153 NotificationService* service = NotificationService::current(); | 154 NotificationService* service = NotificationService::current(); |
| 154 | 155 |
| 155 service->AddObserver( | 156 service->AddObserver(&idle_test_source, |
| 156 &idle_test_source, NotificationType::IDLE, Source<TestSource>(&test_source))
; | 157 NotificationType::IDLE, |
| 157 service->AddObserver( | 158 Source<TestSource>(&test_source)); |
| 158 &idle_test_source, NotificationType::ALL, Source<TestSource>(&test_source)); | 159 service->AddObserver(&idle_test_source, |
| 160 NotificationType::ALL, |
| 161 Source<TestSource>(&test_source)); |
| 159 | 162 |
| 160 service->Notify(NotificationType::IDLE, | 163 service->Notify(NotificationType::IDLE, |
| 161 Source<TestSource>(&test_source), | 164 Source<TestSource>(&test_source), |
| 162 NotificationService::NoDetails()); | 165 NotificationService::NoDetails()); |
| 163 EXPECT_EQ(2, idle_test_source.notification_count()); | 166 EXPECT_EQ(2, idle_test_source.notification_count()); |
| 164 | 167 |
| 165 service->RemoveObserver( | 168 service->RemoveObserver(&idle_test_source, |
| 166 &idle_test_source, NotificationType::IDLE, Source<TestSource>(&test_source))
; | 169 NotificationType::IDLE, |
| 170 Source<TestSource>(&test_source)); |
| 167 | 171 |
| 168 service->Notify(NotificationType::IDLE, | 172 service->Notify(NotificationType::IDLE, |
| 169 Source<TestSource>(&test_source), | 173 Source<TestSource>(&test_source), |
| 170 NotificationService::NoDetails()); | 174 NotificationService::NoDetails()); |
| 171 EXPECT_EQ(3, idle_test_source.notification_count()); | 175 EXPECT_EQ(3, idle_test_source.notification_count()); |
| 172 | 176 |
| 173 service->RemoveObserver( | 177 service->RemoveObserver(&idle_test_source, |
| 174 &idle_test_source, NotificationType::ALL, Source<TestSource>(&test_source)); | 178 NotificationType::ALL, |
| 179 Source<TestSource>(&test_source)); |
| 175 | 180 |
| 176 service->Notify(NotificationType::IDLE, | 181 service->Notify(NotificationType::IDLE, |
| 177 Source<TestSource>(&test_source), | 182 Source<TestSource>(&test_source), |
| 178 NotificationService::NoDetails()); | 183 NotificationService::NoDetails()); |
| 179 EXPECT_EQ(3, idle_test_source.notification_count()); | 184 EXPECT_EQ(3, idle_test_source.notification_count()); |
| 180 } | 185 } |
| 181 | 186 |
| OLD | NEW |