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

Side by Side Diff: chrome/browser/prerender/prerender_tracker_unittest.cc

Issue 407093011: Allow URLRequests from one context to have different NetworkDelegates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mojo Created 6 years, 4 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 <set> 5 #include <set>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectResume) { 216 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectResume) {
217 const base::FilePath::CharType kRedirectPath[] = 217 const base::FilePath::CharType kRedirectPath[] =
218 FILE_PATH_LITERAL("prerender/image-deferred.png"); 218 FILE_PATH_LITERAL("prerender/image-deferred.png");
219 219
220 test_contents()->Start(); 220 test_contents()->Start();
221 RunEvents(); 221 RunEvents();
222 222
223 // Fake a request. 223 // Fake a request.
224 net::TestURLRequestContext url_request_context; 224 net::TestURLRequestContext url_request_context;
225 DeferredRedirectDelegate delegate; 225 DeferredRedirectDelegate delegate;
226 net::URLRequest request( 226 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
227 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), 227 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
228 net::DEFAULT_PRIORITY, 228 net::DEFAULT_PRIORITY,
229 &delegate, 229 &delegate,
230 &url_request_context); 230 NULL));
231 content::ResourceRequestInfo::AllocateForTesting(&request, 231 content::ResourceRequestInfo::AllocateForTesting(request.get(),
232 content::RESOURCE_TYPE_IMAGE, 232 content::RESOURCE_TYPE_IMAGE,
233 NULL, 233 NULL,
234 kDefaultChildId, 234 kDefaultChildId,
235 kDefaultRouteId, 235 kDefaultRouteId,
236 MSG_ROUTING_NONE, 236 MSG_ROUTING_NONE,
237 true); 237 true);
238 238
239 // Install a prerender throttle. 239 // Install a prerender throttle.
240 PrerenderResourceThrottle throttle(&request); 240 PrerenderResourceThrottle throttle(request.get());
241 delegate.SetThrottle(&throttle); 241 delegate.SetThrottle(&throttle);
242 242
243 // Start the request and wait for a redirect. 243 // Start the request and wait for a redirect.
244 request.Start(); 244 request->Start();
245 delegate.Run(); 245 delegate.Run();
246 EXPECT_TRUE(delegate.was_deferred()); 246 EXPECT_TRUE(delegate.was_deferred());
247 // This calls WillRedirectRequestOnUI(). 247 // This calls WillRedirectRequestOnUI().
248 RunEvents(); 248 RunEvents();
249 249
250 // Display the prerendered RenderView and wait for the throttle to 250 // Display the prerendered RenderView and wait for the throttle to
251 // notice. 251 // notice.
252 test_contents()->Use(); 252 test_contents()->Use();
253 delegate.Run(); 253 delegate.Run();
254 EXPECT_TRUE(delegate.resume_called()); 254 EXPECT_TRUE(delegate.resume_called());
255 EXPECT_FALSE(delegate.cancel_called()); 255 EXPECT_FALSE(delegate.cancel_called());
256 } 256 }
257 257
258 // Checks that redirects in main frame loads are not deferred. 258 // Checks that redirects in main frame loads are not deferred.
259 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectMainFrame) { 259 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectMainFrame) {
260 const base::FilePath::CharType kRedirectPath[] = 260 const base::FilePath::CharType kRedirectPath[] =
261 FILE_PATH_LITERAL("prerender/image-deferred.png"); 261 FILE_PATH_LITERAL("prerender/image-deferred.png");
262 262
263 test_contents()->Start(); 263 test_contents()->Start();
264 RunEvents(); 264 RunEvents();
265 265
266 // Fake a request. 266 // Fake a request.
267 net::TestURLRequestContext url_request_context; 267 net::TestURLRequestContext url_request_context;
268 DeferredRedirectDelegate delegate; 268 DeferredRedirectDelegate delegate;
269 net::URLRequest request( 269 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
270 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), 270 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
271 net::DEFAULT_PRIORITY, 271 net::DEFAULT_PRIORITY,
272 &delegate, 272 &delegate,
273 &url_request_context); 273 NULL));
274 content::ResourceRequestInfo::AllocateForTesting( 274 content::ResourceRequestInfo::AllocateForTesting(
275 &request, 275 request.get(),
276 content::RESOURCE_TYPE_MAIN_FRAME, 276 content::RESOURCE_TYPE_MAIN_FRAME,
277 NULL, 277 NULL,
278 kDefaultChildId, 278 kDefaultChildId,
279 kDefaultRouteId, 279 kDefaultRouteId,
280 MSG_ROUTING_NONE, 280 MSG_ROUTING_NONE,
281 true); 281 true);
282 282
283 // Install a prerender throttle. 283 // Install a prerender throttle.
284 PrerenderResourceThrottle throttle(&request); 284 PrerenderResourceThrottle throttle(request.get());
285 delegate.SetThrottle(&throttle); 285 delegate.SetThrottle(&throttle);
286 286
287 // Start the request and wait for a redirect. This time, it should 287 // Start the request and wait for a redirect. This time, it should
288 // not be deferred. 288 // not be deferred.
289 request.Start(); 289 request->Start();
290 delegate.Run(); 290 delegate.Run();
291 // This calls WillRedirectRequestOnUI(). 291 // This calls WillRedirectRequestOnUI().
292 RunEvents(); 292 RunEvents();
293 293
294 // Cleanup work so the prerender is gone. 294 // Cleanup work so the prerender is gone.
295 test_contents()->Cancel(); 295 test_contents()->Cancel();
296 RunEvents(); 296 RunEvents();
297 } 297 }
298 298
299 // Checks that attempting to defer a synchronous request aborts the 299 // Checks that attempting to defer a synchronous request aborts the
300 // prerender. 300 // prerender.
301 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectSyncXHR) { 301 TEST_F(PrerenderTrackerTest, PrerenderThrottledRedirectSyncXHR) {
302 const base::FilePath::CharType kRedirectPath[] = 302 const base::FilePath::CharType kRedirectPath[] =
303 FILE_PATH_LITERAL("prerender/image-deferred.png"); 303 FILE_PATH_LITERAL("prerender/image-deferred.png");
304 304
305 test_contents()->Start(); 305 test_contents()->Start();
306 RunEvents(); 306 RunEvents();
307 307
308 // Fake a request. 308 // Fake a request.
309 net::TestURLRequestContext url_request_context; 309 net::TestURLRequestContext url_request_context;
310 DeferredRedirectDelegate delegate; 310 DeferredRedirectDelegate delegate;
311 net::URLRequest request( 311 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest(
312 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), 312 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)),
313 net::DEFAULT_PRIORITY, 313 net::DEFAULT_PRIORITY,
314 &delegate, 314 &delegate,
315 &url_request_context); 315 NULL));
316 content::ResourceRequestInfo::AllocateForTesting(&request, 316 content::ResourceRequestInfo::AllocateForTesting(request.get(),
317 content::RESOURCE_TYPE_XHR, 317 content::RESOURCE_TYPE_XHR,
318 NULL, 318 NULL,
319 kDefaultChildId, 319 kDefaultChildId,
320 kDefaultRouteId, 320 kDefaultRouteId,
321 MSG_ROUTING_NONE, 321 MSG_ROUTING_NONE,
322 false); 322 false);
323 323
324 // Install a prerender throttle. 324 // Install a prerender throttle.
325 PrerenderResourceThrottle throttle(&request); 325 PrerenderResourceThrottle throttle(request.get());
326 delegate.SetThrottle(&throttle); 326 delegate.SetThrottle(&throttle);
327 327
328 // Start the request and wait for a redirect. 328 // Start the request and wait for a redirect.
329 request.Start(); 329 request->Start();
330 delegate.Run(); 330 delegate.Run();
331 // This calls WillRedirectRequestOnUI(). 331 // This calls WillRedirectRequestOnUI().
332 RunEvents(); 332 RunEvents();
333 333
334 // We should have cancelled the prerender. 334 // We should have cancelled the prerender.
335 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, 335 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT,
336 test_contents()->final_status()); 336 test_contents()->final_status());
337 337
338 // Cleanup work so the prerender is gone. 338 // Cleanup work so the prerender is gone.
339 test_contents()->Cancel(); 339 test_contents()->Cancel();
340 RunEvents(); 340 RunEvents();
341 } 341 }
342 342
343 } // namespace prerender 343 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698