Chromium Code Reviews| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string16.h" | 6 #include "base/strings/string16.h" |
| 7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
| 8 #include "base/task_scheduler/post_task.h" | 8 #include "base/task_scheduler/post_task.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/history/history_test_utils.h" | 10 #include "chrome/browser/history/history_test_utils.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 25 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 26 #include "net/base/escape.h" | 26 #include "net/base/escape.h" |
| 27 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
| 28 #include "net/test/embedded_test_server/request_handler_util.h" | 28 #include "net/test/embedded_test_server/request_handler_util.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 31 | 31 |
| 32 using prerender::test_utils::CreateCountingInterceptorOnIO; | 32 using prerender::test_utils::CreateCountingInterceptorOnIO; |
| 33 using prerender::test_utils::CreatePrefetchOnlyInterceptorOnIO; | |
| 33 using prerender::test_utils::DestructionWaiter; | 34 using prerender::test_utils::DestructionWaiter; |
| 34 using prerender::test_utils::RequestCounter; | 35 using prerender::test_utils::RequestCounter; |
| 35 using prerender::test_utils::TestPrerender; | 36 using prerender::test_utils::TestPrerender; |
| 36 | 37 |
| 37 namespace prerender { | 38 namespace prerender { |
| 38 | 39 |
| 39 // These URLs used for test resources must be relative with the exception of | 40 // These URLs used for test resources must be relative with the exception of |
| 40 // |kPrefetchLoaderPath|. | 41 // |kPrefetchLoaderPath|. |
| 41 const char kPrefetchImagePage[] = "prerender/prefetch_image.html"; | 42 const char kPrefetchImagePage[] = "prerender/prefetch_image.html"; |
| 42 const char kPrefetchJpeg[] = "prerender/image.jpeg"; | 43 const char kPrefetchJpeg[] = "prerender/image.jpeg"; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 76 } |
| 76 | 77 |
| 77 // As above, but specify the data path and URL separately. | 78 // As above, but specify the data path and URL separately. |
| 78 void CountRequestForUrl(const GURL& url, | 79 void CountRequestForUrl(const GURL& url, |
| 79 const std::string& path_str, | 80 const std::string& path_str, |
| 80 RequestCounter* counter) { | 81 RequestCounter* counter) { |
| 81 base::FilePath url_file = ui_test_utils::GetTestFilePath( | 82 base::FilePath url_file = ui_test_utils::GetTestFilePath( |
| 82 base::FilePath(), base::FilePath::FromUTF8Unsafe(path_str)); | 83 base::FilePath(), base::FilePath::FromUTF8Unsafe(path_str)); |
| 83 content::BrowserThread::PostTask( | 84 content::BrowserThread::PostTask( |
| 84 content::BrowserThread::IO, FROM_HERE, | 85 content::BrowserThread::IO, FROM_HERE, |
| 85 base::Bind(&CreateCountingInterceptorOnIO, url, url_file, | 86 base::Bind(&CreateCountingInterceptorOnIO, url, url_file, |
|
droger
2016/11/23 15:20:10
Could we replace this by CreatePrefetchOnlyInterce
mattcary
2016/11/23 15:28:32
It will change slightly what's tested: the Countin
droger
2016/11/23 15:37:34
Resolved offline. I did not notice that the two in
| |
| 86 counter->AsWeakPtr())); | 87 counter->AsWeakPtr())); |
| 87 } | 88 } |
| 88 | 89 |
| 89 protected: | 90 protected: |
| 90 std::unique_ptr<TestPrerender> PrefetchFromURL( | 91 std::unique_ptr<TestPrerender> PrefetchFromURL( |
| 91 const GURL& target_url, | 92 const GURL& target_url, |
| 92 FinalStatus expected_final_status) { | 93 FinalStatus expected_final_status) { |
| 93 GURL loader_url = ServeLoaderURL( | 94 GURL loader_url = ServeLoaderURL( |
| 94 kPrefetchLoaderPath, "REPLACE_WITH_PREFETCH_URL", target_url, ""); | 95 kPrefetchLoaderPath, "REPLACE_WITH_PREFETCH_URL", target_url, ""); |
| 95 std::vector<FinalStatus> expected_final_status_queue(1, | 96 std::vector<FinalStatus> expected_final_status_queue(1, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { | 263 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { |
| 263 RequestCounter script_counter; | 264 RequestCounter script_counter; |
| 264 CountRequestFor(kPrefetchScript, &script_counter); | 265 CountRequestFor(kPrefetchScript, &script_counter); |
| 265 PrefetchFromFile( | 266 PrefetchFromFile( |
| 266 "/server-redirect/?" + | 267 "/server-redirect/?" + |
| 267 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), | 268 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false), |
| 268 FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); | 269 FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); |
| 269 script_counter.WaitForCount(1); | 270 script_counter.WaitForCount(1); |
| 270 } | 271 } |
| 271 | 272 |
| 273 // Checks that the load flags are set correctly for all resources in a 301 | |
| 274 // redirect chain. | |
| 275 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301LoadFlags) { | |
| 276 std::string redirect_path = | |
| 277 "/server-redirect/?" + | |
| 278 net::EscapeQueryParamValue(MakeAbsolute(kPrefetchPage), false); | |
| 279 GURL redirect_url = src_server()->GetURL(redirect_path); | |
| 280 GURL page_url = src_server()->GetURL(MakeAbsolute(kPrefetchPage)); | |
| 281 RequestCounter redirect_counter; | |
| 282 content::BrowserThread::PostTask( | |
| 283 content::BrowserThread::IO, FROM_HERE, | |
| 284 base::Bind(&CreatePrefetchOnlyInterceptorOnIO, redirect_url, | |
| 285 redirect_counter.AsWeakPtr())); | |
| 286 RequestCounter page_counter; | |
| 287 content::BrowserThread::PostTask( | |
| 288 content::BrowserThread::IO, FROM_HERE, | |
| 289 base::Bind(&CreatePrefetchOnlyInterceptorOnIO, page_url, | |
| 290 page_counter.AsWeakPtr())); | |
| 291 PrefetchFromFile(redirect_path, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); | |
| 292 redirect_counter.WaitForCount(1); | |
| 293 page_counter.WaitForCount(1); | |
| 294 } | |
| 295 | |
| 272 // Checks that a subresource 301 redirect is followed. | 296 // Checks that a subresource 301 redirect is followed. |
| 273 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { | 297 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { |
| 274 RequestCounter script_counter; | 298 RequestCounter script_counter; |
| 275 CountRequestFor(kPrefetchScript, &script_counter); | 299 CountRequestFor(kPrefetchScript, &script_counter); |
| 276 PrefetchFromFile(kPrefetchSubresourceRedirectPage, | 300 PrefetchFromFile(kPrefetchSubresourceRedirectPage, |
| 277 FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); | 301 FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); |
| 278 script_counter.WaitForCount(1); | 302 script_counter.WaitForCount(1); |
| 279 } | 303 } |
| 280 | 304 |
| 281 // Checks a client redirect is not followed. | 305 // Checks a client redirect is not followed. |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 | 468 |
| 445 // Check that the URL that was prefetched is not in history. | 469 // Check that the URL that was prefetched is not in history. |
| 446 EXPECT_TRUE(std::find(urls.begin(), urls.end(), prefetched_url) == | 470 EXPECT_TRUE(std::find(urls.begin(), urls.end(), prefetched_url) == |
| 447 urls.end()); | 471 urls.end()); |
| 448 | 472 |
| 449 // The loader URL is the remaining entry. | 473 // The loader URL is the remaining entry. |
| 450 EXPECT_EQ(2U, urls.size()); | 474 EXPECT_EQ(2U, urls.size()); |
| 451 } | 475 } |
| 452 | 476 |
| 453 } // namespace prerender | 477 } // namespace prerender |
| OLD | NEW |