Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(736)

Side by Side Diff: chrome/browser/extensions/event_router_forwarder_unittest.cc

Issue 179923006: Attempting to resolve a race condition with PowerMonitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored to a more explicitly singleton-like style. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 EventRouterForwarderTest() 90 EventRouterForwarderTest()
91 : ui_thread_(BrowserThread::UI, &message_loop_), 91 : ui_thread_(BrowserThread::UI, &message_loop_),
92 io_thread_(BrowserThread::IO), 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 base::PowerMonitor::Initialize(power_monitor_source.Pass());
101 } 101 }
102 102
103 virtual ~EventRouterForwarderTest() { base::PowerMonitor::Shutdown(); }
104
103 virtual void SetUp() { 105 virtual void SetUp() {
104 ASSERT_TRUE(profile_manager_.SetUp()); 106 ASSERT_TRUE(profile_manager_.SetUp());
105 107
106 // Inject a BrowserProcess with a ProfileManager. 108 // Inject a BrowserProcess with a ProfileManager.
107 ASSERT_TRUE(io_thread_.Start()); 109 ASSERT_TRUE(io_thread_.Start());
108 110
109 profile1_ = profile_manager_.CreateTestingProfile("one"); 111 profile1_ = profile_manager_.CreateTestingProfile("one");
110 profile2_ = profile_manager_.CreateTestingProfile("two"); 112 profile2_ = profile_manager_.CreateTestingProfile("two");
111 } 113 }
112 114
113 TestingProfile* CreateIncognitoProfile(TestingProfile* base) { 115 TestingProfile* CreateIncognitoProfile(TestingProfile* base) {
114 TestingProfile::Builder builder; 116 TestingProfile::Builder builder;
115 builder.SetIncognito(); 117 builder.SetIncognito();
116 scoped_ptr<TestingProfile> incognito = builder.Build(); 118 scoped_ptr<TestingProfile> incognito = builder.Build();
117 TestingProfile* incognito_ptr = incognito.get(); 119 TestingProfile* incognito_ptr = incognito.get();
118 // Incognito profile now owned by |base| 120 // Incognito profile now owned by |base|
119 base->SetOffTheRecordProfile(incognito.PassAs<Profile>()); 121 base->SetOffTheRecordProfile(incognito.PassAs<Profile>());
120 return incognito_ptr; 122 return incognito_ptr;
121 } 123 }
122 124
123 base::MessageLoopForUI message_loop_; 125 base::MessageLoopForUI message_loop_;
124 content::TestBrowserThread ui_thread_; 126 content::TestBrowserThread ui_thread_;
125 content::TestBrowserThread io_thread_; 127 content::TestBrowserThread io_thread_;
126 TestingProfileManager profile_manager_; 128 TestingProfileManager profile_manager_;
127 scoped_ptr<base::PowerMonitor> dummy;
128 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. 129 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|.
129 TestingProfile* profile1_; 130 TestingProfile* profile1_;
130 TestingProfile* profile2_; 131 TestingProfile* profile2_;
131 }; 132 };
132 133
133 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { 134 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) {
134 scoped_refptr<MockEventRouterForwarder> event_router( 135 scoped_refptr<MockEventRouterForwarder> event_router(
135 new MockEventRouterForwarder); 136 new MockEventRouterForwarder);
136 GURL url; 137 GURL url;
137 EXPECT_CALL(*event_router.get(), 138 EXPECT_CALL(*event_router.get(),
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 GURL url; 286 GURL url;
286 EXPECT_CALL(*event_router.get(), 287 EXPECT_CALL(*event_router.get(),
287 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); 288 CallEventRouter(profile1_, kExt, kEventName, NULL, url));
288 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _)) 289 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
289 .Times(0); 290 .Times(0);
290 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, 291 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_,
291 false, url); 292 false, url);
292 } 293 }
293 294
294 } // namespace extensions 295 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698