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/prerender/prerender_handle.h" | 9 #include "chrome/browser/prerender/prerender_handle.h" |
| 10 #include "chrome/browser/prerender/prerender_manager.h" | 10 #include "chrome/browser/prerender/prerender_manager.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 std::unique_ptr<TestPrerender> test_prerender = | 122 std::unique_ptr<TestPrerender> test_prerender = |
| 123 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); | 123 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); |
| 124 main_counter.WaitForCount(1); | 124 main_counter.WaitForCount(1); |
| 125 script_counter.WaitForCount(1); | 125 script_counter.WaitForCount(1); |
| 126 script2_counter.WaitForCount(0); | 126 script2_counter.WaitForCount(0); |
| 127 | 127 |
| 128 // Verify that the page load did not happen. | 128 // Verify that the page load did not happen. |
| 129 test_prerender->WaitForLoads(0); | 129 test_prerender->WaitForLoads(0); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Check that a prefetch followed by a load produces the approriate | |
| 133 // histograms. Note that other histogram testing is done in | |
| 134 // browser/page_load_metrics, in particular, testing the combinations of | |
| 135 // Warm/Cold and Cacheable/NoCacheable. | |
| 136 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchHistograms) { | |
| 137 RequestCounter main_counter; | |
| 138 CountRequestFor(kPrefetchPage, &main_counter); | |
| 139 RequestCounter script_counter; | |
| 140 CountRequestFor(kPrefetchScript, &script_counter); | |
| 141 | |
| 142 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_NOSTATE_PREFETCH_FINISHED); | |
|
pasko
2016/11/18 15:56:56
PrefetchFromFile waits for Stop (i.e. when all pre
mattcary
2016/11/18 16:13:28
Done.
| |
| 143 main_counter.WaitForCount(1); | |
| 144 script_counter.WaitForCount(1); | |
| 145 histogram_tester().ExpectTotalCount( | |
| 146 "Prerender.websame_NoStatePrefetchTTFCP.Warm", 0); | |
| 147 | |
| 148 test_utils::FirstContentfulPaintManagerWaiter* fcp_waiter = | |
| 149 test_utils::FirstContentfulPaintManagerWaiter::Create( | |
| 150 GetPrerenderManager()); | |
| 151 ui_test_utils::NavigateToURL( | |
| 152 current_browser(), src_server()->GetURL(MakeAbsolute(kPrefetchPage))); | |
| 153 fcp_waiter->Wait(); | |
| 154 | |
| 155 histogram_tester().ExpectTotalCount( | |
| 156 "Prerender.websame_NoStatePrefetchTTFCP.Warm.Cacheable", 1); | |
| 157 histogram_tester().ExpectTotalCount( | |
| 158 "Prerender.websame_NoStatePrefetchResponseTypes", 2); | |
| 159 } | |
| 160 | |
| 132 // Checks the prefetch of an img tag. | 161 // Checks the prefetch of an img tag. |
| 133 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { | 162 IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { |
| 134 RequestCounter image_counter; | 163 RequestCounter image_counter; |
| 135 CountRequestFor(kPrefetchJpeg, &image_counter); | 164 CountRequestFor(kPrefetchJpeg, &image_counter); |
| 136 base::StringPairs replacement_text; | 165 base::StringPairs replacement_text; |
| 137 replacement_text.push_back( | 166 replacement_text.push_back( |
| 138 std::make_pair("REPLACE_WITH_IMAGE_URL", MakeAbsolute(kPrefetchJpeg))); | 167 std::make_pair("REPLACE_WITH_IMAGE_URL", MakeAbsolute(kPrefetchJpeg))); |
| 139 std::string main_page_path; | 168 std::string main_page_path; |
| 140 net::test_server::GetFilePathWithReplacements( | 169 net::test_server::GetFilePathWithReplacements( |
| 141 kPrefetchImagePage, replacement_text, &main_page_path); | 170 kPrefetchImagePage, replacement_text, &main_page_path); |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 // special way. | 414 // special way. |
| 386 // TODO(mattcary): since the prerender will count itself as loaded even if the | 415 // TODO(mattcary): since the prerender will count itself as loaded even if the |
| 387 // fetch of the main resource fails, the test doesn't actually confirm what we | 416 // fetch of the main resource fails, the test doesn't actually confirm what we |
| 388 // want it to confirm. This may be fixed by planned changes to the prerender | 417 // want it to confirm. This may be fixed by planned changes to the prerender |
| 389 // lifecycle. | 418 // lifecycle. |
| 390 std::unique_ptr<TestPrerender> prerender = | 419 std::unique_ptr<TestPrerender> prerender = |
| 391 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_SAFE_BROWSING); | 420 PrefetchFromFile(kPrefetchPage, FINAL_STATUS_SAFE_BROWSING); |
| 392 } | 421 } |
| 393 | 422 |
| 394 } // namespace prerender | 423 } // namespace prerender |
| OLD | NEW |