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