| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "chrome/browser/net/url_request_mock_util.h" | 14 #include "chrome/browser/net/url_request_mock_util.h" |
| 15 #include "chrome/browser/prerender/prerender_contents.h" | 15 #include "chrome/browser/prerender/prerender_contents.h" |
| 16 #include "chrome/browser/prerender/prerender_manager.h" | 16 #include "chrome/browser/prerender/prerender_manager.h" |
| 17 #include "chrome/browser/prerender/prerender_resource_throttle.h" | 17 #include "chrome/browser/prerender/prerender_resource_throttle.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_request_info.h" | 19 #include "content/public/browser/resource_request_info.h" |
| 20 #include "content/public/browser/resource_throttle.h" | 20 #include "content/public/browser/resource_throttle.h" |
| 21 #include "content/public/common/previews_state.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread.h" |
| 22 #include "ipc/ipc_message.h" | 23 #include "ipc/ipc_message.h" |
| 23 #include "net/base/request_priority.h" | 24 #include "net/base/request_priority.h" |
| 24 #include "net/test/url_request/url_request_mock_http_job.h" | 25 #include "net/test/url_request/url_request_mock_http_job.h" |
| 25 #include "net/url_request/redirect_info.h" | 26 #include "net/url_request/redirect_info.h" |
| 26 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 test_contents()->Start(); | 206 test_contents()->Start(); |
| 206 RunEvents(); | 207 RunEvents(); |
| 207 | 208 |
| 208 // Fake a request. | 209 // Fake a request. |
| 209 net::TestURLRequestContext url_request_context; | 210 net::TestURLRequestContext url_request_context; |
| 210 DeferredRedirectDelegate delegate; | 211 DeferredRedirectDelegate delegate; |
| 211 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 212 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 212 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), | 213 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), |
| 213 net::DEFAULT_PRIORITY, &delegate)); | 214 net::DEFAULT_PRIORITY, &delegate)); |
| 214 content::ResourceRequestInfo::AllocateForTesting( | 215 content::ResourceRequestInfo::AllocateForTesting( |
| 215 request.get(), | 216 request.get(), content::RESOURCE_TYPE_IMAGE, NULL, kDefaultChildId, |
| 216 content::RESOURCE_TYPE_IMAGE, | 217 kDefaultRouteId, MSG_ROUTING_NONE, |
| 217 NULL, | 218 /*is_main_frame=*/false, |
| 218 kDefaultChildId, | 219 /*parent_is_main_frame=*/false, |
| 219 kDefaultRouteId, | 220 /*allow_download=*/true, |
| 220 MSG_ROUTING_NONE, | 221 /*is_async=*/true, content::PREVIEWS_OFF); |
| 221 false, // is_main_frame | |
| 222 false, // parent_is_main_frame | |
| 223 true, // allow_download | |
| 224 true, // is_async | |
| 225 false); // is_using_lofi | |
| 226 | 222 |
| 227 // Install a prerender throttle. | 223 // Install a prerender throttle. |
| 228 PrerenderResourceThrottle throttle(request.get()); | 224 PrerenderResourceThrottle throttle(request.get()); |
| 229 delegate.SetThrottle(&throttle); | 225 delegate.SetThrottle(&throttle); |
| 230 | 226 |
| 231 // Start the request and wait for a redirect. | 227 // Start the request and wait for a redirect. |
| 232 request->Start(); | 228 request->Start(); |
| 233 delegate.Run(); | 229 delegate.Run(); |
| 234 EXPECT_TRUE(delegate.was_deferred()); | 230 EXPECT_TRUE(delegate.was_deferred()); |
| 235 // This calls WillRedirectRequestOnUI(). | 231 // This calls WillRedirectRequestOnUI(). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 248 test_contents()->Start(); | 244 test_contents()->Start(); |
| 249 RunEvents(); | 245 RunEvents(); |
| 250 | 246 |
| 251 // Fake a request. | 247 // Fake a request. |
| 252 net::TestURLRequestContext url_request_context; | 248 net::TestURLRequestContext url_request_context; |
| 253 DeferredRedirectDelegate delegate; | 249 DeferredRedirectDelegate delegate; |
| 254 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 250 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 255 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), | 251 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), |
| 256 net::DEFAULT_PRIORITY, &delegate)); | 252 net::DEFAULT_PRIORITY, &delegate)); |
| 257 content::ResourceRequestInfo::AllocateForTesting( | 253 content::ResourceRequestInfo::AllocateForTesting( |
| 258 request.get(), | 254 request.get(), content::RESOURCE_TYPE_MAIN_FRAME, NULL, kDefaultChildId, |
| 259 content::RESOURCE_TYPE_MAIN_FRAME, | 255 kDefaultRouteId, MSG_ROUTING_NONE, |
| 260 NULL, | 256 /*is_main_frame=*/true, |
| 261 kDefaultChildId, | 257 /*parent_is_main_frame=*/false, |
| 262 kDefaultRouteId, | 258 /*allow_download=*/true, |
| 263 MSG_ROUTING_NONE, | 259 /*is_async=*/true, content::PREVIEWS_OFF); |
| 264 true, // is_main_frame | |
| 265 false, // parent_is_main_frame | |
| 266 true, // allow_download | |
| 267 true, // is_async | |
| 268 false); // is_using_lofi | |
| 269 | 260 |
| 270 // Install a prerender throttle. | 261 // Install a prerender throttle. |
| 271 PrerenderResourceThrottle throttle(request.get()); | 262 PrerenderResourceThrottle throttle(request.get()); |
| 272 delegate.SetThrottle(&throttle); | 263 delegate.SetThrottle(&throttle); |
| 273 | 264 |
| 274 // Start the request and wait for a redirect. This time, it should | 265 // Start the request and wait for a redirect. This time, it should |
| 275 // not be deferred. | 266 // not be deferred. |
| 276 request->Start(); | 267 request->Start(); |
| 277 delegate.Run(); | 268 delegate.Run(); |
| 278 // This calls WillRedirectRequestOnUI(). | 269 // This calls WillRedirectRequestOnUI(). |
| (...skipping 10 matching lines...) Expand all Loading... |
| 289 test_contents()->Start(); | 280 test_contents()->Start(); |
| 290 RunEvents(); | 281 RunEvents(); |
| 291 | 282 |
| 292 // Fake a request. | 283 // Fake a request. |
| 293 net::TestURLRequestContext url_request_context; | 284 net::TestURLRequestContext url_request_context; |
| 294 DeferredRedirectDelegate delegate; | 285 DeferredRedirectDelegate delegate; |
| 295 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( | 286 std::unique_ptr<net::URLRequest> request(url_request_context.CreateRequest( |
| 296 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), | 287 net::URLRequestMockHTTPJob::GetMockUrl("prerender/image-deferred.png"), |
| 297 net::DEFAULT_PRIORITY, &delegate)); | 288 net::DEFAULT_PRIORITY, &delegate)); |
| 298 content::ResourceRequestInfo::AllocateForTesting( | 289 content::ResourceRequestInfo::AllocateForTesting( |
| 299 request.get(), | 290 request.get(), content::RESOURCE_TYPE_XHR, NULL, kDefaultChildId, |
| 300 content::RESOURCE_TYPE_XHR, | 291 kDefaultRouteId, MSG_ROUTING_NONE, |
| 301 NULL, | 292 /*is_main_frame=*/false, |
| 302 kDefaultChildId, | 293 /*parent_is_main_frame=*/false, |
| 303 kDefaultRouteId, | 294 /*allow_download=*/true, |
| 304 MSG_ROUTING_NONE, | 295 /*is_async=*/false, content::PREVIEWS_OFF); |
| 305 false, // is_main_frame | |
| 306 false, // parent_is_main_frame | |
| 307 true, // allow_download | |
| 308 false, // is_async | |
| 309 false); // is_using_lofi | |
| 310 | 296 |
| 311 // Install a prerender throttle. | 297 // Install a prerender throttle. |
| 312 PrerenderResourceThrottle throttle(request.get()); | 298 PrerenderResourceThrottle throttle(request.get()); |
| 313 delegate.SetThrottle(&throttle); | 299 delegate.SetThrottle(&throttle); |
| 314 | 300 |
| 315 // Start the request and wait for a redirect. | 301 // Start the request and wait for a redirect. |
| 316 request->Start(); | 302 request->Start(); |
| 317 delegate.Run(); | 303 delegate.Run(); |
| 318 // This calls WillRedirectRequestOnUI(). | 304 // This calls WillRedirectRequestOnUI(). |
| 319 RunEvents(); | 305 RunEvents(); |
| 320 | 306 |
| 321 // We should have cancelled the prerender. | 307 // We should have cancelled the prerender. |
| 322 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, | 308 EXPECT_EQ(FINAL_STATUS_BAD_DEFERRED_REDIRECT, |
| 323 test_contents()->final_status()); | 309 test_contents()->final_status()); |
| 324 | 310 |
| 325 // Cleanup work so the prerender is gone. | 311 // Cleanup work so the prerender is gone. |
| 326 test_contents()->Cancel(); | 312 test_contents()->Cancel(); |
| 327 RunEvents(); | 313 RunEvents(); |
| 328 } | 314 } |
| 329 | 315 |
| 330 } // namespace prerender | 316 } // namespace prerender |
| OLD | NEW |