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

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

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 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.h" 8 #include "base/message_loop.h"
9 #include "base/power_monitor/power_monitor.h" 9 #include "base/power_monitor/power_monitor.h"
10 #include "base/test/thread_test_helper.h" 10 #include "base/test/thread_test_helper.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 scoped_ptr<base::PowerMonitor> dummy; 121 scoped_ptr<base::PowerMonitor> dummy;
122 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|. 122 // Profiles are weak pointers, owned by ProfileManager in |browser_process_|.
123 TestingProfile* profile1_; 123 TestingProfile* profile1_;
124 TestingProfile* profile2_; 124 TestingProfile* profile2_;
125 }; 125 };
126 126
127 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) { 127 TEST_F(EventRouterForwarderTest, BroadcastRendererUI) {
128 scoped_refptr<MockEventRouterForwarder> event_router( 128 scoped_refptr<MockEventRouterForwarder> event_router(
129 new MockEventRouterForwarder); 129 new MockEventRouterForwarder);
130 GURL url; 130 GURL url;
131 EXPECT_CALL(*event_router, 131 EXPECT_CALL(*event_router.get(),
132 CallEventRouter(profile1_, "", kEventName, profile1_, url)); 132 CallEventRouter(profile1_, "", kEventName, profile1_, url));
133 EXPECT_CALL(*event_router, 133 EXPECT_CALL(*event_router.get(),
134 CallEventRouter(profile2_, "", kEventName, profile2_, url)); 134 CallEventRouter(profile2_, "", kEventName, profile2_, url));
135 BroadcastEventToRenderers(event_router.get(), kEventName, url); 135 BroadcastEventToRenderers(event_router.get(), kEventName, url);
136 } 136 }
137 137
138 TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) { 138 TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) {
139 scoped_refptr<MockEventRouterForwarder> event_router( 139 scoped_refptr<MockEventRouterForwarder> event_router(
140 new MockEventRouterForwarder); 140 new MockEventRouterForwarder);
141 using ::testing::_; 141 using ::testing::_;
142 GURL url; 142 GURL url;
143 Profile* incognito = CreateIncognitoProfile(profile1_); 143 Profile* incognito = CreateIncognitoProfile(profile1_);
144 EXPECT_CALL(*event_router, 144 EXPECT_CALL(*event_router.get(),
145 CallEventRouter(profile1_, "", kEventName, profile1_, url)); 145 CallEventRouter(profile1_, "", kEventName, profile1_, url));
146 EXPECT_CALL(*event_router, 146 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _))
147 CallEventRouter(incognito, _, _, _, _)).Times(0); 147 .Times(0);
148 EXPECT_CALL(*event_router, 148 EXPECT_CALL(*event_router.get(),
149 CallEventRouter(profile2_, "", kEventName, profile2_, url)); 149 CallEventRouter(profile2_, "", kEventName, profile2_, url));
150 BroadcastEventToRenderers(event_router.get(), kEventName, url); 150 BroadcastEventToRenderers(event_router.get(), kEventName, url);
151 } 151 }
152 152
153 // This is the canonical test for passing control flow from the IO thread 153 // This is the canonical test for passing control flow from the IO thread
154 // to the UI thread. Repeating this for all public functions of 154 // to the UI thread. Repeating this for all public functions of
155 // EventRouterForwarder would not increase coverage. 155 // EventRouterForwarder would not increase coverage.
156 TEST_F(EventRouterForwarderTest, BroadcastRendererIO) { 156 TEST_F(EventRouterForwarderTest, BroadcastRendererIO) {
157 scoped_refptr<MockEventRouterForwarder> event_router( 157 scoped_refptr<MockEventRouterForwarder> event_router(
158 new MockEventRouterForwarder); 158 new MockEventRouterForwarder);
159 GURL url; 159 GURL url;
160 EXPECT_CALL(*event_router, 160 EXPECT_CALL(*event_router.get(),
161 CallEventRouter(profile1_, "", kEventName, profile1_, url)); 161 CallEventRouter(profile1_, "", kEventName, profile1_, url));
162 EXPECT_CALL(*event_router, 162 EXPECT_CALL(*event_router.get(),
163 CallEventRouter(profile2_, "", kEventName, profile2_, url)); 163 CallEventRouter(profile2_, "", kEventName, profile2_, url));
164 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 164 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
165 base::Bind( 165 base::Bind(
166 &BroadcastEventToRenderers, base::Unretained(event_router.get()), 166 &BroadcastEventToRenderers, base::Unretained(event_router.get()),
167 kEventName, url)); 167 kEventName, url));
168 168
169 // Wait for IO thread's message loop to be processed 169 // Wait for IO thread's message loop to be processed
170 scoped_refptr<base::ThreadTestHelper> helper( 170 scoped_refptr<base::ThreadTestHelper> helper(
171 new base::ThreadTestHelper( 171 new base::ThreadTestHelper(
172 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); 172 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
173 ASSERT_TRUE(helper->Run()); 173 ASSERT_TRUE(helper->Run());
174 174
175 base::MessageLoop::current()->RunUntilIdle(); 175 base::MessageLoop::current()->RunUntilIdle();
176 } 176 }
177 177
178 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestricted) { 178 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestricted) {
179 scoped_refptr<MockEventRouterForwarder> event_router( 179 scoped_refptr<MockEventRouterForwarder> event_router(
180 new MockEventRouterForwarder); 180 new MockEventRouterForwarder);
181 using ::testing::_; 181 using ::testing::_;
182 GURL url; 182 GURL url;
183 EXPECT_CALL(*event_router, 183 EXPECT_CALL(*event_router.get(),
184 CallEventRouter(profile1_, "", kEventName, profile1_, url)); 184 CallEventRouter(profile1_, "", kEventName, profile1_, url));
185 EXPECT_CALL(*event_router, 185 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
186 CallEventRouter(profile2_, _, _, _, _)).Times(0); 186 .Times(0);
187 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, 187 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true,
188 url); 188 url);
189 } 189 }
190 190
191 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) { 191 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) {
192 scoped_refptr<MockEventRouterForwarder> event_router( 192 scoped_refptr<MockEventRouterForwarder> event_router(
193 new MockEventRouterForwarder); 193 new MockEventRouterForwarder);
194 Profile* incognito = CreateIncognitoProfile(profile1_); 194 Profile* incognito = CreateIncognitoProfile(profile1_);
195 using ::testing::_; 195 using ::testing::_;
196 GURL url; 196 GURL url;
197 EXPECT_CALL(*event_router, 197 EXPECT_CALL(*event_router.get(),
198 CallEventRouter(profile1_, "", kEventName, profile1_, url)); 198 CallEventRouter(profile1_, "", kEventName, profile1_, url));
199 EXPECT_CALL(*event_router, 199 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _))
200 CallEventRouter(incognito, _, _, _, _)).Times(0); 200 .Times(0);
201 EXPECT_CALL(*event_router, 201 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
202 CallEventRouter(profile2_, _, _, _, _)).Times(0); 202 .Times(0);
203 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true, 203 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true,
204 url); 204 url);
205 } 205 }
206 206
207 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) { 207 TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) {
208 scoped_refptr<MockEventRouterForwarder> event_router( 208 scoped_refptr<MockEventRouterForwarder> event_router(
209 new MockEventRouterForwarder); 209 new MockEventRouterForwarder);
210 Profile* incognito = CreateIncognitoProfile(profile1_); 210 Profile* incognito = CreateIncognitoProfile(profile1_);
211 using ::testing::_; 211 using ::testing::_;
212 GURL url; 212 GURL url;
213 EXPECT_CALL(*event_router, 213 EXPECT_CALL(*event_router.get(), CallEventRouter(profile1_, _, _, _, _))
214 CallEventRouter(profile1_, _, _, _, _)).Times(0); 214 .Times(0);
215 EXPECT_CALL(*event_router, 215 EXPECT_CALL(*event_router.get(),
216 CallEventRouter(incognito, "", kEventName, incognito, url)); 216 CallEventRouter(incognito, "", kEventName, incognito, url));
217 EXPECT_CALL(*event_router, 217 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
218 CallEventRouter(profile2_, _, _, _, _)).Times(0); 218 .Times(0);
219 DispatchEventToRenderers(event_router.get(), kEventName, incognito, true, 219 DispatchEventToRenderers(event_router.get(), kEventName, incognito, true,
220 url); 220 url);
221 } 221 }
222 222
223 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) { 223 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) {
224 scoped_refptr<MockEventRouterForwarder> event_router( 224 scoped_refptr<MockEventRouterForwarder> event_router(
225 new MockEventRouterForwarder); 225 new MockEventRouterForwarder);
226 using ::testing::_; 226 using ::testing::_;
227 GURL url; 227 GURL url;
228 EXPECT_CALL(*event_router, 228 EXPECT_CALL(*event_router.get(),
229 CallEventRouter(profile1_, "", kEventName, NULL, url)); 229 CallEventRouter(profile1_, "", kEventName, NULL, url));
230 EXPECT_CALL(*event_router, 230 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
231 CallEventRouter(profile2_, _, _, _, _)).Times(0); 231 .Times(0);
232 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, 232 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false,
233 url); 233 url);
234 } 234 }
235 235
236 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) { 236 TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) {
237 scoped_refptr<MockEventRouterForwarder> event_router( 237 scoped_refptr<MockEventRouterForwarder> event_router(
238 new MockEventRouterForwarder); 238 new MockEventRouterForwarder);
239 Profile* incognito = CreateIncognitoProfile(profile1_); 239 Profile* incognito = CreateIncognitoProfile(profile1_);
240 using ::testing::_; 240 using ::testing::_;
241 GURL url; 241 GURL url;
242 EXPECT_CALL(*event_router, 242 EXPECT_CALL(*event_router.get(),
243 CallEventRouter(profile1_, "", kEventName, NULL, url)); 243 CallEventRouter(profile1_, "", kEventName, NULL, url));
244 EXPECT_CALL(*event_router, 244 EXPECT_CALL(*event_router.get(), CallEventRouter(incognito, _, _, _, _))
245 CallEventRouter(incognito, _, _, _, _)).Times(0); 245 .Times(0);
246 EXPECT_CALL(*event_router, 246 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
247 CallEventRouter(profile2_, _, _, _, _)).Times(0); 247 .Times(0);
248 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false, 248 DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false,
249 url); 249 url);
250 } 250 }
251 251
252 TEST_F(EventRouterForwarderTest, BroadcastExtensionUI) { 252 TEST_F(EventRouterForwarderTest, BroadcastExtensionUI) {
253 scoped_refptr<MockEventRouterForwarder> event_router( 253 scoped_refptr<MockEventRouterForwarder> event_router(
254 new MockEventRouterForwarder); 254 new MockEventRouterForwarder);
255 GURL url; 255 GURL url;
256 EXPECT_CALL(*event_router, 256 EXPECT_CALL(*event_router.get(),
257 CallEventRouter(profile1_, kExt, kEventName, profile1_, url)); 257 CallEventRouter(profile1_, kExt, kEventName, profile1_, url));
258 EXPECT_CALL(*event_router, 258 EXPECT_CALL(*event_router.get(),
259 CallEventRouter(profile2_, kExt, kEventName, profile2_, url)); 259 CallEventRouter(profile2_, kExt, kEventName, profile2_, url));
260 BroadcastEventToExtension(event_router.get(), kExt, kEventName, url); 260 BroadcastEventToExtension(event_router.get(), kExt, kEventName, url);
261 } 261 }
262 262
263 TEST_F(EventRouterForwarderTest, UnicastExtensionUIRestricted) { 263 TEST_F(EventRouterForwarderTest, UnicastExtensionUIRestricted) {
264 scoped_refptr<MockEventRouterForwarder> event_router( 264 scoped_refptr<MockEventRouterForwarder> event_router(
265 new MockEventRouterForwarder); 265 new MockEventRouterForwarder);
266 using ::testing::_; 266 using ::testing::_;
267 GURL url; 267 GURL url;
268 EXPECT_CALL(*event_router, 268 EXPECT_CALL(*event_router.get(),
269 CallEventRouter(profile1_, kExt, kEventName, profile1_, url)); 269 CallEventRouter(profile1_, kExt, kEventName, profile1_, url));
270 EXPECT_CALL(*event_router, 270 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
271 CallEventRouter(profile2_, _, _, _, _)).Times(0); 271 .Times(0);
272 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, 272 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_,
273 true, url); 273 true, url);
274 } 274 }
275 275
276 TEST_F(EventRouterForwarderTest, UnicastExtensionUIUnrestricted) { 276 TEST_F(EventRouterForwarderTest, UnicastExtensionUIUnrestricted) {
277 scoped_refptr<MockEventRouterForwarder> event_router( 277 scoped_refptr<MockEventRouterForwarder> event_router(
278 new MockEventRouterForwarder); 278 new MockEventRouterForwarder);
279 using ::testing::_; 279 using ::testing::_;
280 GURL url; 280 GURL url;
281 EXPECT_CALL(*event_router, 281 EXPECT_CALL(*event_router.get(),
282 CallEventRouter(profile1_, kExt, kEventName, NULL, url)); 282 CallEventRouter(profile1_, kExt, kEventName, NULL, url));
283 EXPECT_CALL(*event_router, 283 EXPECT_CALL(*event_router.get(), CallEventRouter(profile2_, _, _, _, _))
284 CallEventRouter(profile2_, _, _, _, _)).Times(0); 284 .Times(0);
285 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_, 285 DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_,
286 false, url); 286 false, url);
287 } 287 }
288 288
289 } // namespace extensions 289 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/extension_action_icon_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698