| 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.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/system_monitor/system_monitor.h" | |
| 10 #include "base/test/thread_test_helper.h" | 9 #include "base/test/thread_test_helper.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 14 #include "chrome/test/base/testing_profile_manager.h" | 13 #include "chrome/test/base/testing_profile_manager.h" |
| 15 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 16 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 | 83 |
| 85 } // namespace | 84 } // namespace |
| 86 | 85 |
| 87 class EventRouterForwarderTest : public testing::Test { | 86 class EventRouterForwarderTest : public testing::Test { |
| 88 protected: | 87 protected: |
| 89 EventRouterForwarderTest() | 88 EventRouterForwarderTest() |
| 90 : ui_thread_(BrowserThread::UI, &message_loop_), | 89 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 91 io_thread_(BrowserThread::IO), | 90 io_thread_(BrowserThread::IO), |
| 92 profile_manager_( | 91 profile_manager_( |
| 93 static_cast<TestingBrowserProcess*>(g_browser_process)) { | 92 static_cast<TestingBrowserProcess*>(g_browser_process)) { |
| 94 #if defined(OS_MACOSX) | |
| 95 base::SystemMonitor::AllocateSystemIOPorts(); | |
| 96 #endif | |
| 97 dummy.reset(new base::SystemMonitor); | |
| 98 } | 93 } |
| 99 | 94 |
| 100 virtual void SetUp() { | 95 virtual void SetUp() { |
| 101 ASSERT_TRUE(profile_manager_.SetUp()); | 96 ASSERT_TRUE(profile_manager_.SetUp()); |
| 102 | 97 |
| 103 // Inject a BrowserProcess with a ProfileManager. | 98 // Inject a BrowserProcess with a ProfileManager. |
| 104 ASSERT_TRUE(io_thread_.Start()); | 99 ASSERT_TRUE(io_thread_.Start()); |
| 105 | 100 |
| 106 profile1_ = profile_manager_.CreateTestingProfile("one"); | 101 profile1_ = profile_manager_.CreateTestingProfile("one"); |
| 107 profile2_ = profile_manager_.CreateTestingProfile("two"); | 102 profile2_ = profile_manager_.CreateTestingProfile("two"); |
| 108 } | 103 } |
| 109 | 104 |
| 110 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { | 105 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { |
| 111 TestingProfile* incognito = new TestingProfile; // Owned by |base|. | 106 TestingProfile* incognito = new TestingProfile; // Owned by |base|. |
| 112 incognito->set_incognito(true); | 107 incognito->set_incognito(true); |
| 113 base->SetOffTheRecordProfile(incognito); | 108 base->SetOffTheRecordProfile(incognito); |
| 114 return incognito; | 109 return incognito; |
| 115 } | 110 } |
| 116 | 111 |
| 117 MessageLoopForUI message_loop_; | 112 MessageLoopForUI message_loop_; |
| 118 content::TestBrowserThread ui_thread_; | 113 content::TestBrowserThread ui_thread_; |
| 119 content::TestBrowserThread io_thread_; | 114 content::TestBrowserThread io_thread_; |
| 120 TestingProfileManager profile_manager_; | 115 TestingProfileManager profile_manager_; |
| 121 scoped_ptr<base::SystemMonitor> dummy; | |
| 122 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. | 116 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. |
| 123 TestingProfile* profile1_; | 117 TestingProfile* profile1_; |
| 124 TestingProfile* profile2_; | 118 TestingProfile* profile2_; |
| 125 }; | 119 }; |
| 126 | 120 |
| 127 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { | 121 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { |
| 128 scoped_refptr<MockEventRouterForwarder> event_router( | 122 scoped_refptr<MockEventRouterForwarder> event_router( |
| 129 new MockEventRouterForwarder); | 123 new MockEventRouterForwarder); |
| 130 GURL url; | 124 GURL url; |
| 131 EXPECT_CALL(*event_router, | 125 EXPECT_CALL(*event_router, |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 GURL url; | 274 GURL url; |
| 281 EXPECT_CALL(*event_router, | 275 EXPECT_CALL(*event_router, |
| 282 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); | 276 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); |
| 283 EXPECT_CALL(*event_router, | 277 EXPECT_CALL(*event_router, |
| 284 CallEventRouter(profile2_, _, _, _, _)).Times(0); | 278 CallEventRouter(profile2_, _, _, _, _)).Times(0); |
| 285 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, | 279 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, |
| 286 false, url); | 280 false, url); |
| 287 } | 281 } |
| 288 | 282 |
| 289 } // namespace extensions | 283 } // namespace extensions |
| OLD | NEW |