| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 const std::string&, | 39 const std::string&, |
| 40 events::HistogramValue, | 40 events::HistogramValue, |
| 41 const std::string&, | 41 const std::string&, |
| 42 Profile*, | 42 Profile*, |
| 43 const GURL&)); | 43 const GURL&)); |
| 44 | 44 |
| 45 virtual void CallEventRouter(Profile* profile, | 45 virtual void CallEventRouter(Profile* profile, |
| 46 const std::string& extension_id, | 46 const std::string& extension_id, |
| 47 events::HistogramValue histogram_value, | 47 events::HistogramValue histogram_value, |
| 48 const std::string& event_name, | 48 const std::string& event_name, |
| 49 scoped_ptr<base::ListValue> event_args, | 49 std::unique_ptr<base::ListValue> event_args, |
| 50 Profile* restrict_to_profile, | 50 Profile* restrict_to_profile, |
| 51 const GURL& event_url) { | 51 const GURL& event_url) { |
| 52 CallEventRouter(profile, extension_id, histogram_value, event_name, | 52 CallEventRouter(profile, extension_id, histogram_value, event_name, |
| 53 restrict_to_profile, event_url); | 53 restrict_to_profile, event_url); |
| 54 } | 54 } |
| 55 | 55 |
| 56 protected: | 56 protected: |
| 57 virtual ~MockEventRouterForwarder() {} | 57 virtual ~MockEventRouterForwarder() {} |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 static void BroadcastEventToRenderers(EventRouterForwarder* event_router, | 60 static void BroadcastEventToRenderers(EventRouterForwarder* event_router, |
| 61 events::HistogramValue histogram_value, | 61 events::HistogramValue histogram_value, |
| 62 const std::string& event_name, | 62 const std::string& event_name, |
| 63 const GURL& url) { | 63 const GURL& url) { |
| 64 scoped_ptr<base::ListValue> args(new base::ListValue()); | 64 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 65 event_router->BroadcastEventToRenderers(histogram_value, event_name, | 65 event_router->BroadcastEventToRenderers(histogram_value, event_name, |
| 66 std::move(args), url); | 66 std::move(args), url); |
| 67 } | 67 } |
| 68 | 68 |
| 69 static void DispatchEventToRenderers(EventRouterForwarder* event_router, | 69 static void DispatchEventToRenderers(EventRouterForwarder* event_router, |
| 70 events::HistogramValue histogram_value, | 70 events::HistogramValue histogram_value, |
| 71 const std::string& event_name, | 71 const std::string& event_name, |
| 72 void* profile, | 72 void* profile, |
| 73 bool use_profile_to_restrict_events, | 73 bool use_profile_to_restrict_events, |
| 74 const GURL& url) { | 74 const GURL& url) { |
| 75 scoped_ptr<base::ListValue> args(new base::ListValue()); | 75 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 76 event_router->DispatchEventToRenderers(histogram_value, event_name, | 76 event_router->DispatchEventToRenderers(histogram_value, event_name, |
| 77 std::move(args), profile, | 77 std::move(args), profile, |
| 78 use_profile_to_restrict_events, url); | 78 use_profile_to_restrict_events, url); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static void BroadcastEventToExtension(EventRouterForwarder* event_router, | 81 static void BroadcastEventToExtension(EventRouterForwarder* event_router, |
| 82 const std::string& extension, | 82 const std::string& extension, |
| 83 events::HistogramValue histogram_value, | 83 events::HistogramValue histogram_value, |
| 84 const std::string& event_name, | 84 const std::string& event_name, |
| 85 const GURL& url) { | 85 const GURL& url) { |
| 86 scoped_ptr<base::ListValue> args(new base::ListValue()); | 86 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 87 event_router->BroadcastEventToExtension(extension, histogram_value, | 87 event_router->BroadcastEventToExtension(extension, histogram_value, |
| 88 event_name, std::move(args), url); | 88 event_name, std::move(args), url); |
| 89 } | 89 } |
| 90 | 90 |
| 91 static void DispatchEventToExtension(EventRouterForwarder* event_router, | 91 static void DispatchEventToExtension(EventRouterForwarder* event_router, |
| 92 const std::string& extension, | 92 const std::string& extension, |
| 93 events::HistogramValue histogram_value, | 93 events::HistogramValue histogram_value, |
| 94 const std::string& event_name, | 94 const std::string& event_name, |
| 95 void* profile, | 95 void* profile, |
| 96 bool use_profile_to_restrict_events, | 96 bool use_profile_to_restrict_events, |
| 97 const GURL& url) { | 97 const GURL& url) { |
| 98 scoped_ptr<base::ListValue> args(new base::ListValue()); | 98 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 99 event_router->DispatchEventToExtension(extension, histogram_value, event_name, | 99 event_router->DispatchEventToExtension(extension, histogram_value, event_name, |
| 100 std::move(args), profile, | 100 std::move(args), profile, |
| 101 use_profile_to_restrict_events, url); | 101 use_profile_to_restrict_events, url); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 class EventRouterForwarderTest : public testing::Test { | 106 class EventRouterForwarderTest : public testing::Test { |
| 107 protected: | 107 protected: |
| 108 EventRouterForwarderTest() | 108 EventRouterForwarderTest() |
| 109 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), | 109 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD), |
| 110 profile_manager_( | 110 profile_manager_( |
| 111 TestingBrowserProcess::GetGlobal()) { | 111 TestingBrowserProcess::GetGlobal()) { |
| 112 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
| 113 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); | 113 base::PowerMonitorDeviceSource::AllocateSystemIOPorts(); |
| 114 #endif | 114 #endif |
| 115 scoped_ptr<base::PowerMonitorSource> power_monitor_source( | 115 std::unique_ptr<base::PowerMonitorSource> power_monitor_source( |
| 116 new base::PowerMonitorDeviceSource()); | 116 new base::PowerMonitorDeviceSource()); |
| 117 dummy.reset(new base::PowerMonitor(std::move(power_monitor_source))); | 117 dummy.reset(new base::PowerMonitor(std::move(power_monitor_source))); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void SetUp() override { | 120 void SetUp() override { |
| 121 ASSERT_TRUE(profile_manager_.SetUp()); | 121 ASSERT_TRUE(profile_manager_.SetUp()); |
| 122 | 122 |
| 123 // Inject a BrowserProcess with a ProfileManager. | 123 // Inject a BrowserProcess with a ProfileManager. |
| 124 profile1_ = profile_manager_.CreateTestingProfile("one"); | 124 profile1_ = profile_manager_.CreateTestingProfile("one"); |
| 125 profile2_ = profile_manager_.CreateTestingProfile("two"); | 125 profile2_ = profile_manager_.CreateTestingProfile("two"); |
| 126 } | 126 } |
| 127 | 127 |
| 128 content::TestBrowserThreadBundle thread_bundle_; | 128 content::TestBrowserThreadBundle thread_bundle_; |
| 129 TestingProfileManager profile_manager_; | 129 TestingProfileManager profile_manager_; |
| 130 scoped_ptr<base::PowerMonitor> dummy; | 130 std::unique_ptr<base::PowerMonitor> dummy; |
| 131 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. | 131 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. |
| 132 TestingProfile* profile1_; | 132 TestingProfile* profile1_; |
| 133 TestingProfile* profile2_; | 133 TestingProfile* profile2_; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { | 136 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { |
| 137 scoped_refptr<MockEventRouterForwarder> event_router( | 137 scoped_refptr<MockEventRouterForwarder> event_router( |
| 138 new MockEventRouterForwarder); | 138 new MockEventRouterForwarder); |
| 139 GURL url; | 139 GURL url; |
| 140 EXPECT_CALL(*event_router.get(), | 140 EXPECT_CALL(*event_router.get(), |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 EXPECT_CALL( | 306 EXPECT_CALL( |
| 307 *event_router.get(), | 307 *event_router.get(), |
| 308 CallEventRouter(profile1_, kExt, kHistogramValue, kEventName, NULL, url)); | 308 CallEventRouter(profile1_, kExt, kHistogramValue, kEventName, NULL, url)); |
| 309 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _, _)) | 309 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _, _)) |
| 310 .Times(0); | 310 .Times(0); |
| 311 DispatchEventToExtension(event_router.get(), kExt, kHistogramValue, | 311 DispatchEventToExtension(event_router.get(), kExt, kHistogramValue, |
| 312 kEventName, profile1_, false, url); | 312 kEventName, profile1_, false, url); |
| 313 } | 313 } |
| 314 | 314 |
| 315 } // namespace extensions | 315 } // namespace extensions |
| OLD | NEW |