| 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" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
| 14 #include "chrome/browser/prerender/prerender_contents.h" | 14 #include "chrome/browser/prerender/prerender_contents.h" |
| 15 #include "chrome/browser/prerender/prerender_manager.h" | 15 #include "chrome/browser/prerender/prerender_manager.h" |
| 16 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 16 #include "chrome/browser/prerender/prerender_resource_throttle.h" |
| 17 #include "chrome/browser/prerender/prerender_tracker.h" | 17 #include "chrome/browser/prerender/prerender_tracker.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "content/public/browser/resource_controller.h" | 19 #include "content/public/browser/resource_controller.h" |
| 20 #include "content/public/browser/resource_request_info.h" | 20 #include "content/public/browser/resource_request_info.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "content/test/net/url_request_mock_http_job.h" | |
| 23 #include "ipc/ipc_message.h" | 22 #include "ipc/ipc_message.h" |
| 24 #include "net/base/request_priority.h" | 23 #include "net/base/request_priority.h" |
| 24 #include "net/test/url_request/url_request_mock_http_job.h" |
| 25 #include "net/url_request/redirect_info.h" | 25 #include "net/url_request/redirect_info.h" |
| 26 #include "net/url_request/url_request.h" | 26 #include "net/url_request/url_request.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 27 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 using content::ResourceType; | 31 using content::ResourceType; |
| 32 | 32 |
| 33 namespace prerender { | 33 namespace prerender { |
| 34 | 34 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 227 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 228 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), | 228 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 229 net::DEFAULT_PRIORITY, | 229 net::DEFAULT_PRIORITY, |
| 230 &delegate, | 230 &delegate, |
| 231 NULL)); | 231 NULL)); |
| 232 content::ResourceRequestInfo::AllocateForTesting(request.get(), | 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); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 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 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 270 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 271 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), | 271 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 272 net::DEFAULT_PRIORITY, | 272 net::DEFAULT_PRIORITY, |
| 273 &delegate, | 273 &delegate, |
| 274 NULL)); | 274 NULL)); |
| 275 content::ResourceRequestInfo::AllocateForTesting( | 275 content::ResourceRequestInfo::AllocateForTesting( |
| 276 request.get(), | 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, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 312 scoped_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 313 content::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), | 313 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kRedirectPath)), |
| 314 net::DEFAULT_PRIORITY, | 314 net::DEFAULT_PRIORITY, |
| 315 &delegate, | 315 &delegate, |
| 316 NULL)); | 316 NULL)); |
| 317 content::ResourceRequestInfo::AllocateForTesting(request.get(), | 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); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 |