OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/extensions/event_router_forwarder.h" | 5 #include "chrome/browser/extensions/event_router_forwarder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/power_monitor/power_monitor.h" | 9 #include "base/power_monitor/power_monitor.h" |
10 #include "base/power_monitor/power_monitor_device_source.h" | 10 #include "base/power_monitor/power_monitor_device_source.h" |
11 #include "base/test/thread_test_helper.h" | 11 #include "base/test/thread_test_helper.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 15 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 event_router->DispatchEventToExtension( | 82 event_router->DispatchEventToExtension( |
82 extension, event_name, args.Pass(), profile, | 83 extension, event_name, args.Pass(), profile, |
83 use_profile_to_restrict_events, url); | 84 use_profile_to_restrict_events, url); |
84 } | 85 } |
85 | 86 |
86 } // namespace | 87 } // namespace |
87 | 88 |
88 class EventRouterForwarderTest : public testing::Test { | 89 class EventRouterForwarderTest : public testing::Test { |
89 protected: | 90 protected: |
90 EventRouterForwarderTest() | 91 EventRouterForwarderTest() |
91 : ui_thread_(BrowserThread::UI, &message_loop_), | 92 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), |
92 io_thread_(BrowserThread::IO), | |
93 profile_manager_( | 93 profile_manager_( |
94 TestingBrowserProcess::GetGlobal()) { | 94 TestingBrowserProcess::GetGlobal()) { |
95 #if defined(OS_MACOSX) | 95 #if defined(OS_MACOSX) |
96 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 96 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
97 #endif | 97 #endif |
98 scoped_ptr<base::PowerMonitorSource> power_monitor_source( | 98 scoped_ptr<base::PowerMonitorSource> power_monitor_source( |
99 new base::PowerMonitorDeviceSource()); | 99 new base::PowerMonitorDeviceSource()); |
100 dummy.reset(new base::PowerMonitor(power_monitor_source.Pass())); | 100 dummy.reset(new base::PowerMonitor(power_monitor_source.Pass())); |
101 } | 101 } |
102 | 102 |
103 virtual void SetUp() { | 103 virtual void SetUp() { |
104 ASSERT_TRUE(profile_manager_.SetUp()); | 104 ASSERT_TRUE(profile_manager_.SetUp()); |
105 | 105 |
106 // Inject a BrowserProcess with a ProfileManager. | 106 // Inject a BrowserProcess with a ProfileManager. |
107 ASSERT_TRUE(io_thread_.Start()); | |
108 | |
109 profile1_ = profile_manager_.CreateTestingProfile("one"); | 107 profile1_ = profile_manager_.CreateTestingProfile("one"); |
110 profile2_ = profile_manager_.CreateTestingProfile("two"); | 108 profile2_ = profile_manager_.CreateTestingProfile("two"); |
111 } | 109 } |
112 | 110 |
113 base::MessageLoopForUI message_loop_; | 111 content::TestBrowserThreadBundle thread_bundle_; |
114 content::TestBrowserThread ui_thread_; | |
115 content::TestBrowserThread io_thread_; | |
116 TestingProfileManager profile_manager_; | 112 TestingProfileManager profile_manager_; |
117 scoped_ptr<base::PowerMonitor> dummy; | 113 scoped_ptr<base::PowerMonitor> dummy; |
118 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. | 114 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. |
119 TestingProfile* profile1_; | 115 TestingProfile* profile1_; |
120 TestingProfile* profile2_; | 116 TestingProfile* profile2_; |
121 }; | 117 }; |
122 | 118 |
123 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { | 119 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { |
124 scoped_refptr<MockEventRouterForwarder> event_router( | 120 scoped_refptr<MockEventRouterForwarder> event_router( |
125 new MockEventRouterForwarder); | 121 new MockEventRouterForwarder); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 GURL url; | 271 GURL url; |
276 EXPECT_CALL(*event_router.get(), | 272 EXPECT_CALL(*event_router.get(), |
277 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); | 273 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); |
278 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) | 274 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) |
279 .Times(0); | 275 .Times(0); |
280 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, | 276 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, |
281 false, url); | 277 false, url); |
282 } | 278 } |
283 | 279 |
284 } // namespace extensions | 280 } // namespace extensions |
OLD | NEW |