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 "chrome/browser/extensions/extension_event_router_forwarder.h" | 5 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/system_monitor/system_monitor.h" | 8 #include "base/system_monitor/system_monitor.h" |
9 #include "base/test/thread_test_helper.h" | 9 #include "base/test/thread_test_helper.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/test/base/testing_browser_process_test.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
13 #include "content/browser/browser_thread.h" | 13 #include "content/browser/browser_thread.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const char kEventName[] = "event_name"; | 20 const char kEventName[] = "event_name"; |
21 const char kEventArgs[] = "event_args"; | 21 const char kEventArgs[] = "event_args"; |
22 const char kExt[] = "extension"; | 22 const char kExt[] = "extension"; |
23 | 23 |
24 class MockExtensionEventRouterForwarder : public ExtensionEventRouterForwarder { | 24 class MockExtensionEventRouterForwarder : public ExtensionEventRouterForwarder { |
25 public: | 25 public: |
26 virtual ~MockExtensionEventRouterForwarder() {} | 26 virtual ~MockExtensionEventRouterForwarder() {} |
27 | 27 |
28 MOCK_METHOD6(CallExtensionEventRouter, | 28 MOCK_METHOD6(CallExtensionEventRouter, |
29 void(Profile*, const std::string&, const std::string&, const std::string&, | 29 void(Profile*, const std::string&, const std::string&, const std::string&, |
30 Profile*, const GURL&)); | 30 Profile*, const GURL&)); |
31 }; | 31 }; |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class ExtensionEventRouterForwarderTest : public TestingBrowserProcessTest { | 35 class ExtensionEventRouterForwarderTest : public testing::Test { |
36 protected: | 36 protected: |
37 ExtensionEventRouterForwarderTest() | 37 ExtensionEventRouterForwarderTest() |
38 : ui_thread_(BrowserThread::UI, &message_loop_), | 38 : ui_thread_(BrowserThread::UI, &message_loop_), |
39 io_thread_(BrowserThread::IO) { | 39 io_thread_(BrowserThread::IO) { |
40 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
41 base::SystemMonitor::AllocateSystemIOPorts(); | 41 base::SystemMonitor::AllocateSystemIOPorts(); |
42 #endif | 42 #endif |
43 dummy.reset(new base::SystemMonitor); | 43 dummy.reset(new base::SystemMonitor); |
44 } | 44 } |
45 | 45 |
46 ~ExtensionEventRouterForwarderTest() { | 46 ~ExtensionEventRouterForwarderTest() { |
47 } | 47 } |
48 | 48 |
49 virtual void SetUp() { | 49 virtual void SetUp() { |
50 // Inject a BrowserProcess with a ProfileManager. | 50 // Inject a BrowserProcess with a ProfileManager. |
51 ASSERT_TRUE(io_thread_.Start()); | 51 ASSERT_TRUE(io_thread_.Start()); |
52 | 52 |
53 TestingBrowserProcess* browser_process = testing_browser_process_.get(); | 53 TestingBrowserProcess* browser_process = |
| 54 static_cast<TestingBrowserProcess*>(g_browser_process); |
54 browser_process->SetProfileManager(new ProfileManager); | 55 browser_process->SetProfileManager(new ProfileManager); |
55 | 56 |
56 profile1_ = new TestingProfile(); | 57 profile1_ = new TestingProfile(); |
57 profile2_ = new TestingProfile(); | 58 profile2_ = new TestingProfile(); |
58 | 59 |
59 browser_process->profile_manager()->RegisterProfile(profile1_, true); | 60 browser_process->profile_manager()->RegisterProfile(profile1_, true); |
60 browser_process->profile_manager()->RegisterProfile(profile2_, true); | 61 browser_process->profile_manager()->RegisterProfile(profile2_, true); |
61 } | 62 } |
62 | 63 |
63 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { | 64 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 using ::testing::_; | 250 using ::testing::_; |
250 GURL url; | 251 GURL url; |
251 EXPECT_CALL(*event_router, | 252 EXPECT_CALL(*event_router, |
252 CallExtensionEventRouter( | 253 CallExtensionEventRouter( |
253 profile1_, kExt, kEventName, kEventArgs, NULL, url)); | 254 profile1_, kExt, kEventName, kEventArgs, NULL, url)); |
254 EXPECT_CALL(*event_router, | 255 EXPECT_CALL(*event_router, |
255 CallExtensionEventRouter(profile2_, _, _, _, _, _)).Times(0); | 256 CallExtensionEventRouter(profile2_, _, _, _, _, _)).Times(0); |
256 event_router->DispatchEventToExtension(kExt, kEventName, kEventArgs, | 257 event_router->DispatchEventToExtension(kExt, kEventName, kEventArgs, |
257 profile1_, false, url); | 258 profile1_, false, url); |
258 } | 259 } |
OLD | NEW |