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