| 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 <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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 RunEvents(); | 219 RunEvents(); |
| 220 | 220 |
| 221 // Fake a request. | 221 // Fake a request. |
| 222 net::TestURLRequestContext url_request_context; | 222 net::TestURLRequestContext url_request_context; |
| 223 DeferredRedirectDelegate delegate; | 223 DeferredRedirectDelegate delegate; |
| 224 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 224 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 225 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), | 225 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 226 net::DEFAULT_PRIORITY, | 226 net::DEFAULT_PRIORITY, |
| 227 &delegate, | 227 &delegate, |
| 228 NULL)); | 228 NULL)); |
| 229 content::ResourceRequestInfo::AllocateForTesting(request.get(), | 229 content::ResourceRequestInfo::AllocateForTesting( |
| 230 content::RESOURCE_TYPE_IMAGE, | 230 request.get(), |
| 231 NULL, | 231 content::RESOURCE_TYPE_IMAGE, |
| 232 kDefaultChildId, | 232 NULL, |
| 233 kDefaultRouteId, | 233 kDefaultChildId, |
| 234 MSG_ROUTING_NONE, | 234 kDefaultRouteId, |
| 235 true); | 235 MSG_ROUTING_NONE, |
| 236 false, // is_main_frame |
| 237 false, // parent_is_main_frame |
| 238 true); // is_async |
| 236 | 239 |
| 237 // Install a prerender throttle. | 240 // Install a prerender throttle. |
| 238 PrerenderResourceThrottle throttle(request.get()); | 241 PrerenderResourceThrottle throttle(request.get()); |
| 239 delegate.SetThrottle(&throttle); | 242 delegate.SetThrottle(&throttle); |
| 240 | 243 |
| 241 // Start the request and wait for a redirect. | 244 // Start the request and wait for a redirect. |
| 242 request->Start(); | 245 request->Start(); |
| 243 delegate.Run(); | 246 delegate.Run(); |
| 244 EXPECT_TRUE(delegate.was_deferred()); | 247 EXPECT_TRUE(delegate.was_deferred()); |
| 245 // This calls WillRedirectRequestOnUI(). | 248 // This calls WillRedirectRequestOnUI(). |
| (...skipping 23 matching lines...) Expand all Loading... |
| 269 net::DEFAULT_PRIORITY, | 272 net::DEFAULT_PRIORITY, |
| 270 &delegate, | 273 &delegate, |
| 271 NULL)); | 274 NULL)); |
| 272 content::ResourceRequestInfo::AllocateForTesting( | 275 content::ResourceRequestInfo::AllocateForTesting( |
| 273 request.get(), | 276 request.get(), |
| 274 content::RESOURCE_TYPE_MAIN_FRAME, | 277 content::RESOURCE_TYPE_MAIN_FRAME, |
| 275 NULL, | 278 NULL, |
| 276 kDefaultChildId, | 279 kDefaultChildId, |
| 277 kDefaultRouteId, | 280 kDefaultRouteId, |
| 278 MSG_ROUTING_NONE, | 281 MSG_ROUTING_NONE, |
| 279 true); | 282 true, // is_main_frame |
| 283 false, // parent_is_main_frame |
| 284 true); // is_async |
| 280 | 285 |
| 281 // Install a prerender throttle. | 286 // Install a prerender throttle. |
| 282 PrerenderResourceThrottle throttle(request.get()); | 287 PrerenderResourceThrottle throttle(request.get()); |
| 283 delegate.SetThrottle(&throttle); | 288 delegate.SetThrottle(&throttle); |
| 284 | 289 |
| 285 // Start the request and wait for a redirect. This time, it should | 290 // Start the request and wait for a redirect. This time, it should |
| 286 // not be deferred. | 291 // not be deferred. |
| 287 request->Start(); | 292 request->Start(); |
| 288 delegate.Run(); | 293 delegate.Run(); |
| 289 // This calls WillRedirectRequestOnUI(). | 294 // This calls WillRedirectRequestOnUI(). |
| (...skipping 14 matching lines...) Expand all Loading... |
| 304 RunEvents(); | 309 RunEvents(); |
| 305 | 310 |
| 306 // Fake a request. | 311 // Fake a request. |
| 307 net::TestURLRequestContext url_request_context; | 312 net::TestURLRequestContext url_request_context; |
| 308 DeferredRedirectDelegate delegate; | 313 DeferredRedirectDelegate delegate; |
| 309 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 314 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 310 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), | 315 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 311 net::DEFAULT_PRIORITY, | 316 net::DEFAULT_PRIORITY, |
| 312 &delegate, | 317 &delegate, |
| 313 NULL)); | 318 NULL)); |
| 314 content::ResourceRequestInfo::AllocateForTesting(request.get(), | 319 content::ResourceRequestInfo::AllocateForTesting( |
| 315 content::RESOURCE_TYPE_XHR, | 320 request.get(), |
| 316 NULL, | 321 content::RESOURCE_TYPE_XHR, |
| 317 kDefaultChildId, | 322 NULL, |
| 318 kDefaultRouteId, | 323 kDefaultChildId, |
| 319 MSG_ROUTING_NONE, | 324 kDefaultRouteId, |
| 320 false); | 325 MSG_ROUTING_NONE, |
| 326 false, // is_main_frame |
| 327 false, // parent_is_main_frame |
| 328 false); // is_async |
| 321 | 329 |
| 322 // Install a prerender throttle. | 330 // Install a prerender throttle. |
| 323 PrerenderResourceThrottle throttle(request.get()); | 331 PrerenderResourceThrottle throttle(request.get()); |
| 324 delegate.SetThrottle(&throttle); | 332 delegate.SetThrottle(&throttle); |
| 325 | 333 |
| 326 // Start the request and wait for a redirect. | 334 // Start the request and wait for a redirect. |
| 327 request->Start(); | 335 request->Start(); |
| 328 delegate.Run(); | 336 delegate.Run(); |
| 329 // This calls WillRedirectRequestOnUI(). | 337 // This calls WillRedirectRequestOnUI(). |
| 330 RunEvents(); | 338 RunEvents(); |
| 331 | 339 |
| 332 // We should have cancelled the prerender. | 340 // We should have cancelled the prerender. |
| 333 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, | 341 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, |
| 334 test_contents()->final_status()); | 342 test_contents()->final_status()); |
| 335 | 343 |
| 336 // Cleanup work so the prerender is gone. | 344 // Cleanup work so the prerender is gone. |
| 337 test_contents()->Cancel(); | 345 test_contents()->Cancel(); |
| 338 RunEvents(); | 346 RunEvents(); |
| 339 } | 347 } |
| 340 | 348 |
| 341 } // namespace prerender | 349 } // namespace prerender |
| OLD | NEW |