Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/notification_observer.h" | 5 #include "content/common/notification_observer.h" |
| 6 #include "content/common/notification_registrar.h" | 6 #include "content/common/notification_registrar.h" |
| 7 #include "content/common/notification_service.h" | 7 #include "content/common/notification_service.h" |
| 8 #include "chrome/test/testing_browser_process_test.h" | |
|
sky
2011/07/28 00:28:03
nit: before content
| |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 // Bogus class to act as a NotificationSource for the messages. | 13 // Bogus class to act as a NotificationSource for the messages. |
| 13 class TestSource {}; | 14 class TestSource {}; |
| 14 | 15 |
| 15 class TestObserver : public NotificationObserver { | 16 class TestObserver : public NotificationObserver { |
| 16 public: | 17 public: |
| 17 TestObserver() : notification_count_(0) {} | 18 TestObserver() : notification_count_(0) {} |
| 18 | 19 |
| 19 int notification_count() { return notification_count_; } | 20 int notification_count() { return notification_count_; } |
| 20 | 21 |
| 21 void Observe(int type, | 22 void Observe(int type, |
| 22 const NotificationSource& source, | 23 const NotificationSource& source, |
| 23 const NotificationDetails& details) { | 24 const NotificationDetails& details) { |
| 24 ++notification_count_; | 25 ++notification_count_; |
| 25 } | 26 } |
| 26 | 27 |
| 27 private: | 28 private: |
| 28 int notification_count_; | 29 int notification_count_; |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 | 34 |
| 34 class NotificationServiceTest : public testing::Test { | 35 class NotificationServiceTest : public TestingBrowserProcessTest { |
|
jam
2011/07/28 01:41:21
why should a unit test derive from BrowserProcessT
Paweł Hajdan Jr.
2011/07/28 03:49:18
TestingBrowserProcess has nothing to do with brows
jam
2011/07/28 16:48:54
I see, although I'm not sure I understand why unit
| |
| 35 protected: | 36 protected: |
| 36 NotificationRegistrar registrar_; | 37 NotificationRegistrar registrar_; |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 TEST_F(NotificationServiceTest, Basic) { | 40 TEST_F(NotificationServiceTest, Basic) { |
| 40 TestSource test_source; | 41 TestSource test_source; |
| 41 TestSource other_source; | 42 TestSource other_source; |
| 42 | 43 |
| 43 // Check the equality operators defined for NotificationSource | 44 // Check the equality operators defined for NotificationSource |
| 44 EXPECT_TRUE( | 45 EXPECT_TRUE( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 EXPECT_EQ(3, idle_test_source.notification_count()); | 156 EXPECT_EQ(3, idle_test_source.notification_count()); |
| 156 | 157 |
| 157 registrar_.Remove(&idle_test_source, content::NOTIFICATION_ALL, | 158 registrar_.Remove(&idle_test_source, content::NOTIFICATION_ALL, |
| 158 Source<TestSource>(&test_source)); | 159 Source<TestSource>(&test_source)); |
| 159 | 160 |
| 160 service->Notify(content::NOTIFICATION_IDLE, | 161 service->Notify(content::NOTIFICATION_IDLE, |
| 161 Source<TestSource>(&test_source), | 162 Source<TestSource>(&test_source), |
| 162 NotificationService::NoDetails()); | 163 NotificationService::NoDetails()); |
| 163 EXPECT_EQ(3, idle_test_source.notification_count()); | 164 EXPECT_EQ(3, idle_test_source.notification_count()); |
| 164 } | 165 } |
| OLD | NEW |