OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 6 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/public/browser/render_frame_host.h" | 16 #include "content/public/browser/render_frame_host.h" |
16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
17 #include "net/test/embedded_test_server/http_request.h" | 18 #include "net/test/embedded_test_server/http_request.h" |
18 #include "net/test/embedded_test_server/http_response.h" | 19 #include "net/test/embedded_test_server/http_response.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 bool is_external; | 67 bool is_external; |
67 bool should_be_recorded; | 68 bool should_be_recorded; |
68 }; | 69 }; |
69 | 70 |
70 struct RedirectEdge { | 71 struct RedirectEdge { |
71 // This response code should be returned by previous url in the chain. | 72 // This response code should be returned by previous url in the chain. |
72 net::HttpStatusCode code; | 73 net::HttpStatusCode code; |
73 GURL url; | 74 GURL url; |
74 }; | 75 }; |
75 | 76 |
77 // Helper class to track and allow waiting for ResourcePrefetchPredictor | |
78 // initialization. WARNING: OnPredictorInitialized event will not be fired if | |
79 // ResourcePrefetchPredictor is initialized before observer creation. | |
Benoit L
2016/12/19 12:32:00
nit: before the observer creation.
alexilin
2016/12/19 12:58:09
Done.
| |
76 class InitializationObserver : public TestObserver { | 80 class InitializationObserver : public TestObserver { |
77 public: | 81 public: |
78 explicit InitializationObserver(ResourcePrefetchPredictor* predictor) | 82 explicit InitializationObserver(ResourcePrefetchPredictor* predictor) |
79 : TestObserver(predictor) {} | 83 : TestObserver(predictor) {} |
80 | 84 |
81 void OnPredictorInitialized() override { run_loop_.Quit(); } | 85 void OnPredictorInitialized() override { run_loop_.Quit(); } |
82 | 86 |
83 void Wait() { run_loop_.Run(); } | 87 void Wait() { run_loop_.Run(); } |
84 | 88 |
85 private: | 89 private: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 ModifySubresourceForComparison(&subresource, match_navigation_id); | 142 ModifySubresourceForComparison(&subresource, match_navigation_id); |
139 for (auto& subresource : expected_subresources) | 143 for (auto& subresource : expected_subresources) |
140 ModifySubresourceForComparison(&subresource, match_navigation_id); | 144 ModifySubresourceForComparison(&subresource, match_navigation_id); |
141 | 145 |
142 EXPECT_THAT(actual_subresources, | 146 EXPECT_THAT(actual_subresources, |
143 testing::UnorderedElementsAreArray(expected_subresources)); | 147 testing::UnorderedElementsAreArray(expected_subresources)); |
144 } | 148 } |
145 | 149 |
146 } // namespace | 150 } // namespace |
147 | 151 |
148 // Helper class to track and allow waiting for ResourcePrefetchPredictor events. | 152 // Helper class to track and allow waiting for a single OnNavigationLearned |
149 // These events are also used to verify that ResourcePrefetchPredictor works as | 153 // event. The information provided by this event is also used to verify that |
150 // expected. | 154 // ResourcePrefetchPredictor works as expected. |
151 class ResourcePrefetchPredictorTestObserver : public TestObserver { | 155 class LearningObserver : public TestObserver { |
152 public: | 156 public: |
153 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 157 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
154 | 158 |
155 explicit ResourcePrefetchPredictorTestObserver( | 159 explicit LearningObserver(ResourcePrefetchPredictor* predictor, |
156 ResourcePrefetchPredictor* predictor, | 160 const size_t expected_url_visit_count, |
157 const size_t expected_url_visit_count, | 161 const PageRequestSummary& expected_summary, |
158 const PageRequestSummary& expected_summary, | 162 bool match_navigation_id) |
159 bool match_navigation_id) | |
160 : TestObserver(predictor), | 163 : TestObserver(predictor), |
161 url_visit_count_(expected_url_visit_count), | 164 url_visit_count_(expected_url_visit_count), |
162 summary_(expected_summary), | 165 summary_(expected_summary), |
163 match_navigation_id_(match_navigation_id) {} | 166 match_navigation_id_(match_navigation_id) {} |
164 | 167 |
165 // TestObserver: | 168 // TestObserver: |
166 void OnNavigationLearned(size_t url_visit_count, | 169 void OnNavigationLearned(size_t url_visit_count, |
167 const PageRequestSummary& summary) override { | 170 const PageRequestSummary& summary) override { |
168 EXPECT_EQ(url_visit_count, url_visit_count_); | 171 EXPECT_EQ(url_visit_count, url_visit_count_); |
169 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); | 172 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); |
170 EXPECT_EQ(summary.initial_url, summary_.initial_url); | 173 EXPECT_EQ(summary.initial_url, summary_.initial_url); |
171 CompareSubresources(summary.subresource_requests, | 174 CompareSubresources(summary.subresource_requests, |
172 summary_.subresource_requests, match_navigation_id_); | 175 summary_.subresource_requests, match_navigation_id_); |
173 run_loop_.Quit(); | 176 run_loop_.Quit(); |
174 } | 177 } |
175 | 178 |
176 void Wait() { run_loop_.Run(); } | 179 void Wait() { run_loop_.Run(); } |
177 | 180 |
178 private: | 181 private: |
179 base::RunLoop run_loop_; | 182 base::RunLoop run_loop_; |
180 size_t url_visit_count_; | 183 size_t url_visit_count_; |
181 PageRequestSummary summary_; | 184 PageRequestSummary summary_; |
182 bool match_navigation_id_; | 185 bool match_navigation_id_; |
183 | 186 |
184 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictorTestObserver); | 187 DISALLOW_COPY_AND_ASSIGN(LearningObserver); |
188 }; | |
189 | |
190 // Helper class to track and allow waiting for a single OnPrefetchingFinished | |
191 // event. No learning events should be fired while this observer is active. | |
192 class PrefetchingObserver : public TestObserver { | |
193 public: | |
194 explicit PrefetchingObserver(ResourcePrefetchPredictor* predictor, | |
195 const GURL& expected_main_frame_url) | |
196 : TestObserver(predictor), main_frame_url_(expected_main_frame_url) {} | |
197 | |
198 // TestObserver: | |
199 void OnNavigationLearned(size_t url_visit_count, | |
200 const PageRequestSummary& summary) override { | |
201 ADD_FAILURE() << "Prefetching shouldn't activate learning"; | |
202 } | |
203 | |
204 void OnPrefetchingFinished(const GURL& main_frame_url) override { | |
205 EXPECT_EQ(main_frame_url_, main_frame_url); | |
206 run_loop_.Quit(); | |
207 } | |
208 | |
209 void Wait() { run_loop_.Run(); } | |
210 | |
211 private: | |
212 base::RunLoop run_loop_; | |
213 GURL main_frame_url_; | |
214 | |
215 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver); | |
185 }; | 216 }; |
186 | 217 |
187 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { | 218 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
188 protected: | 219 protected: |
189 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 220 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
190 | 221 |
191 void SetUpCommandLine(base::CommandLine* command_line) override { | 222 void SetUpCommandLine(base::CommandLine* command_line) override { |
192 command_line->AppendSwitchASCII( | 223 command_line->AppendSwitchASCII( |
193 switches::kSpeculativeResourcePrefetching, | 224 switches::kSpeculativeResourcePrefetching, |
194 switches::kSpeculativeResourcePrefetchingEnabled); | 225 switches::kSpeculativeResourcePrefetchingEnabled); |
195 } | 226 } |
196 | 227 |
197 void SetUpOnMainThread() override { | 228 void SetUpOnMainThread() override { |
198 embedded_test_server()->RegisterRequestHandler( | 229 embedded_test_server()->RegisterRequestHandler( |
199 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, | 230 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, |
200 base::Unretained(this))); | 231 base::Unretained(this))); |
201 embedded_test_server()->RegisterRequestHandler( | 232 embedded_test_server()->RegisterRequestHandler( |
202 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, | 233 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, |
203 base::Unretained(this))); | 234 base::Unretained(this))); |
204 ASSERT_TRUE(embedded_test_server()->Start()); | 235 ASSERT_TRUE(embedded_test_server()->Start()); |
205 predictor_ = | 236 predictor_ = |
206 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); | 237 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); |
207 ASSERT_TRUE(predictor_); | 238 ASSERT_TRUE(predictor_); |
208 EnsurePredictorInitialized(); | 239 EnsurePredictorInitialized(); |
209 } | 240 } |
210 | 241 |
242 void TestLearningAndPrefetching(const GURL& main_frame_url) { | |
243 // Navigate to |main_frame_url| and check all the expectations. | |
244 NavigateToURLAndCheckSubresources(main_frame_url); | |
245 ClearCache(); | |
246 // It is needed to have at least two resource hits to trigger prefetch. | |
247 NavigateToURLAndCheckSubresources(main_frame_url); | |
248 ClearCache(); | |
249 // Prefetch all needed resources and change expectations so that all | |
250 // cacheable resources should be served from cache next navigation. | |
251 PrefetchURL(main_frame_url); | |
252 NavigateToURLAndCheckSubresources(main_frame_url); | |
253 } | |
254 | |
211 void NavigateToURLAndCheckSubresources( | 255 void NavigateToURLAndCheckSubresources( |
212 const GURL& main_frame_url, | 256 const GURL& main_frame_url, |
213 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { | 257 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { |
214 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); | 258 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); |
215 std::vector<URLRequestSummary> url_request_summaries; | 259 std::vector<URLRequestSummary> url_request_summaries; |
216 for (const auto& kv : resources_) { | 260 for (const auto& kv : resources_) { |
217 if (kv.second.is_no_store || !kv.second.should_be_recorded) | 261 if (kv.second.is_no_store || !kv.second.should_be_recorded) |
218 continue; | 262 continue; |
219 url_request_summaries.push_back( | 263 url_request_summaries.push_back( |
220 GetURLRequestSummaryForResource(endpoint_url, kv.second)); | 264 GetURLRequestSummaryForResource(endpoint_url, kv.second)); |
221 } | 265 } |
222 ResourcePrefetchPredictorTestObserver observer( | 266 LearningObserver observer( |
223 predictor_, UpdateAndGetVisitCount(main_frame_url), | 267 predictor_, UpdateAndGetVisitCount(main_frame_url), |
224 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), | 268 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), |
225 url_request_summaries), | 269 url_request_summaries), |
226 true); // Matching navigation id by default | 270 true); // Matching navigation id by default |
227 ui_test_utils::NavigateToURLWithDisposition( | 271 ui_test_utils::NavigateToURLWithDisposition( |
228 browser(), main_frame_url, disposition, | 272 browser(), main_frame_url, disposition, |
229 ui_test_utils::BROWSER_TEST_NONE); | 273 ui_test_utils::BROWSER_TEST_NONE); |
230 observer.Wait(); | 274 observer.Wait(); |
275 for (auto& kv : resources_) { | |
276 if (!kv.second.is_no_store && kv.second.should_be_recorded) | |
277 kv.second.request.was_cached = true; | |
278 } | |
279 } | |
280 | |
281 void PrefetchURL(const GURL& main_frame_url) { | |
282 PrefetchingObserver observer(predictor_, main_frame_url); | |
283 predictor_->StartPrefetching(main_frame_url, PrefetchOrigin::NAVIGATION); | |
Benoit L
2016/12/19 12:32:00
nit: What you're doing here maps more closely to "
alexilin
2016/12/19 12:58:09
I hope that the behavior of predictor in this two
Benoit L
2016/12/19 15:19:05
Good point.
I'm sure that if either of us change t
| |
284 observer.Wait(); | |
285 for (auto& kv : resources_) { | |
286 if (!kv.second.is_no_store && kv.second.should_be_recorded) | |
287 kv.second.request.was_cached = true; | |
288 } | |
231 } | 289 } |
232 | 290 |
233 ResourceSummary* AddResource(const GURL& resource_url, | 291 ResourceSummary* AddResource(const GURL& resource_url, |
234 content::ResourceType resource_type, | 292 content::ResourceType resource_type, |
235 net::RequestPriority priority) { | 293 net::RequestPriority priority) { |
236 auto pair_and_whether_inserted = | 294 auto pair_and_whether_inserted = |
237 resources_.insert(std::make_pair(resource_url, ResourceSummary())); | 295 resources_.insert(std::make_pair(resource_url, ResourceSummary())); |
238 EXPECT_TRUE(pair_and_whether_inserted.second) << resource_url | 296 EXPECT_TRUE(pair_and_whether_inserted.second) << resource_url |
239 << " was inserted twice"; | 297 << " was inserted twice"; |
240 ResourceSummary* resource = &pair_and_whether_inserted.first->second; | 298 ResourceSummary* resource = &pair_and_whether_inserted.first->second; |
(...skipping 25 matching lines...) Expand all Loading... | |
266 const std::vector<RedirectEdge>& redirect_chain) { | 324 const std::vector<RedirectEdge>& redirect_chain) { |
267 ASSERT_FALSE(redirect_chain.empty()); | 325 ASSERT_FALSE(redirect_chain.empty()); |
268 GURL current = initial_url; | 326 GURL current = initial_url; |
269 for (const auto& edge : redirect_chain) { | 327 for (const auto& edge : redirect_chain) { |
270 auto result = redirects_.insert(std::make_pair(current, edge)); | 328 auto result = redirects_.insert(std::make_pair(current, edge)); |
271 EXPECT_TRUE(result.second) << current << " already has a redirect."; | 329 EXPECT_TRUE(result.second) << current << " already has a redirect."; |
272 current = edge.url; | 330 current = edge.url; |
273 } | 331 } |
274 } | 332 } |
275 | 333 |
334 void ClearCache() { | |
335 chrome::ClearCache(browser()); | |
336 for (auto& kv : resources_) | |
337 kv.second.request.was_cached = false; | |
338 } | |
339 | |
276 // Shortcut for convenience. | 340 // Shortcut for convenience. |
277 GURL GetURL(const std::string& path) const { | 341 GURL GetURL(const std::string& path) const { |
278 return embedded_test_server()->GetURL(path); | 342 return embedded_test_server()->GetURL(path); |
279 } | 343 } |
280 | 344 |
281 void EnableHttpsServer() { | 345 void EnableHttpsServer() { |
282 ASSERT_FALSE(https_server_); | 346 ASSERT_FALSE(https_server_); |
283 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( | 347 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( |
284 net::EmbeddedTestServer::TYPE_HTTPS); | 348 net::EmbeddedTestServer::TYPE_HTTPS); |
285 https_server()->AddDefaultHandlers( | 349 https_server()->AddDefaultHandlers( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 return ++visit_count_[main_frame_url]; | 454 return ++visit_count_[main_frame_url]; |
391 } | 455 } |
392 | 456 |
393 ResourcePrefetchPredictor* predictor_; | 457 ResourcePrefetchPredictor* predictor_; |
394 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 458 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
395 std::map<GURL, ResourceSummary> resources_; | 459 std::map<GURL, ResourceSummary> resources_; |
396 std::map<GURL, RedirectEdge> redirects_; | 460 std::map<GURL, RedirectEdge> redirects_; |
397 std::map<GURL, size_t> visit_count_; | 461 std::map<GURL, size_t> visit_count_; |
398 }; | 462 }; |
399 | 463 |
400 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, LearningSimple) { | 464 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { |
401 // These resources have default priorities that correspond to | 465 // These resources have default priorities that correspond to |
402 // blink::typeToPriority function. | 466 // blink::typeToPriority function. |
403 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 467 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
404 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 468 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
405 net::HIGHEST); | 469 net::HIGHEST); |
406 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 470 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
407 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 471 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
408 net::HIGHEST); | 472 net::HIGHEST); |
409 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath)); | 473 TestLearningAndPrefetching(GetURL(kHtmlSubresourcesPath)); |
410 } | 474 } |
411 | 475 |
412 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 476 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Redirect) { |
413 LearningAfterRedirect) { | |
414 AddRedirectChain(GetURL(kRedirectPath), {{net::HTTP_MOVED_PERMANENTLY, | 477 AddRedirectChain(GetURL(kRedirectPath), {{net::HTTP_MOVED_PERMANENTLY, |
415 GetURL(kHtmlSubresourcesPath)}}); | 478 GetURL(kHtmlSubresourcesPath)}}); |
416 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 479 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
417 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 480 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
418 net::HIGHEST); | 481 net::HIGHEST); |
419 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 482 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
420 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 483 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
421 net::HIGHEST); | 484 net::HIGHEST); |
422 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); | 485 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
423 } | 486 } |
424 | 487 |
425 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 488 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, RedirectChain) { |
426 LearningAfterRedirectChain) { | |
427 AddRedirectChain(GetURL(kRedirectPath), | 489 AddRedirectChain(GetURL(kRedirectPath), |
428 {{net::HTTP_FOUND, GetURL(kRedirectPath2)}, | 490 {{net::HTTP_FOUND, GetURL(kRedirectPath2)}, |
429 {net::HTTP_MOVED_PERMANENTLY, GetURL(kRedirectPath3)}, | 491 {net::HTTP_MOVED_PERMANENTLY, GetURL(kRedirectPath3)}, |
430 {net::HTTP_FOUND, GetURL(kHtmlSubresourcesPath)}}); | 492 {net::HTTP_FOUND, GetURL(kHtmlSubresourcesPath)}}); |
431 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 493 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
432 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 494 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
433 net::HIGHEST); | 495 net::HIGHEST); |
434 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 496 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
435 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 497 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
436 net::HIGHEST); | 498 net::HIGHEST); |
437 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); | 499 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
438 } | 500 } |
439 | 501 |
440 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 502 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
441 LearningAfterHttpToHttpsRedirect) { | 503 LearningAfterHttpToHttpsRedirect) { |
442 EnableHttpsServer(); | 504 EnableHttpsServer(); |
443 AddRedirectChain(GetURL(kRedirectPath), | 505 AddRedirectChain(GetURL(kRedirectPath), |
444 {{net::HTTP_FOUND, https_server()->GetURL(kRedirectPath2)}, | 506 {{net::HTTP_MOVED_PERMANENTLY, |
445 {net::HTTP_MOVED_PERMANENTLY, | |
446 https_server()->GetURL(kHtmlSubresourcesPath)}}); | 507 https_server()->GetURL(kHtmlSubresourcesPath)}}); |
447 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, | 508 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, |
448 net::LOWEST); | 509 net::LOWEST); |
449 AddResource(https_server()->GetURL(kStylePath), | 510 AddResource(https_server()->GetURL(kStylePath), |
450 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | 511 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); |
451 AddResource(https_server()->GetURL(kScriptPath), | 512 AddResource(https_server()->GetURL(kScriptPath), |
452 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 513 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
453 AddResource(https_server()->GetURL(kFontPath), | 514 AddResource(https_server()->GetURL(kFontPath), |
454 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | 515 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); |
455 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); | 516 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); |
517 // TODO(alexilin): activate it after new NavigationID introduced. | |
518 // TestLearningAndPrefetching(GetURL(kRedirectPath)); | |
Benoit L
2016/12/19 12:32:00
nit: Don't put commented-out code. However the com
alexilin
2016/12/19 12:58:09
Done.
Is there some rule in styleguide about that
Benoit L
2016/12/19 15:19:05
I'm not sure, but I'm quite confident that no-one
alexilin
2016/12/19 15:36:13
Well, now even this never commited commented-out c
| |
456 } | 519 } |
457 | 520 |
458 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 521 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
459 LearningJavascriptDocumentWrite) { | 522 JavascriptDocumentWrite) { |
460 auto externalScript = | 523 auto externalScript = |
461 AddExternalResource(GetURL(kScriptDocumentWritePath), | 524 AddExternalResource(GetURL(kScriptDocumentWritePath), |
462 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 525 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
463 externalScript->request.mime_type = kJavascriptMime; | 526 externalScript->request.mime_type = kJavascriptMime; |
464 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 527 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
465 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 528 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
466 net::HIGHEST); | 529 net::HIGHEST); |
467 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 530 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
468 NavigateToURLAndCheckSubresources(GetURL(kHtmlDocumentWritePath)); | 531 TestLearningAndPrefetching(GetURL(kHtmlDocumentWritePath)); |
469 } | 532 } |
470 | 533 |
471 // Disabled due to flakiness (crbug.com/673028). | 534 // Disabled due to flakiness (crbug.com/673028). |
472 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 535 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
473 DISABLED_LearningJavascriptAppendChild) { | 536 JavascriptAppendChild) { |
474 auto externalScript = | 537 auto externalScript = |
475 AddExternalResource(GetURL(kScriptAppendChildPath), | 538 AddExternalResource(GetURL(kScriptAppendChildPath), |
476 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 539 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
477 externalScript->request.mime_type = kJavascriptMime; | 540 externalScript->request.mime_type = kJavascriptMime; |
478 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 541 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
479 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 542 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
480 net::HIGHEST); | 543 net::HIGHEST); |
481 // This script has net::LOWEST priority because it's executed asynchronously. | 544 // This script has net::LOWEST priority because it's executed asynchronously. |
482 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::LOWEST); | 545 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::LOWEST); |
483 NavigateToURLAndCheckSubresources(GetURL(kHtmlAppendChildPath)); | 546 TestLearningAndPrefetching(GetURL(kHtmlAppendChildPath)); |
484 } | 547 } |
485 | 548 |
486 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 549 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
487 LearningJavascriptInnerHtml) { | 550 JavascriptInnerHtml) { |
488 auto externalScript = AddExternalResource( | 551 auto externalScript = AddExternalResource( |
489 GetURL(kScriptInnerHtmlPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 552 GetURL(kScriptInnerHtmlPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
490 externalScript->request.mime_type = kJavascriptMime; | 553 externalScript->request.mime_type = kJavascriptMime; |
491 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 554 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
492 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 555 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
493 net::HIGHEST); | 556 net::HIGHEST); |
494 // https://www.w3.org/TR/2014/REC-html5-20141028/scripting-1.html#the-script-e lement | 557 // https://www.w3.org/TR/2014/REC-html5-20141028/scripting-1.html#the-script-e lement |
495 // Script elements don't execute when inserted using innerHTML attribute. | 558 // Script elements don't execute when inserted using innerHTML attribute. |
496 AddUnrecordedResources({GetURL(kScriptPath)}); | 559 AddUnrecordedResources({GetURL(kScriptPath)}); |
497 NavigateToURLAndCheckSubresources(GetURL(kHtmlInnerHtmlPath)); | 560 TestLearningAndPrefetching(GetURL(kHtmlInnerHtmlPath)); |
498 } | 561 } |
499 | 562 |
500 // Requests originated by XMLHttpRequest have content::RESOURCE_TYPE_XHR. | 563 // Requests originated by XMLHttpRequest have content::RESOURCE_TYPE_XHR. |
501 // Actual resource type is inferred from the mime-type. | 564 // Actual resource type is inferred from the mime-type. |
502 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 565 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, JavascriptXHR) { |
503 LearningJavascriptXHR) { | |
504 auto externalScript = AddExternalResource( | 566 auto externalScript = AddExternalResource( |
505 GetURL(kScriptXHRPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 567 GetURL(kScriptXHRPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
506 externalScript->request.mime_type = kJavascriptMime; | 568 externalScript->request.mime_type = kJavascriptMime; |
507 auto image = AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, | 569 auto image = AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, |
508 net::HIGHEST); | 570 net::HIGHEST); |
509 image->request.mime_type = kImageMime; | 571 image->request.mime_type = kImageMime; |
510 auto style = AddResource(GetURL(kStylePath), | 572 auto style = AddResource(GetURL(kStylePath), |
511 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | 573 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); |
512 style->request.mime_type = kStyleMime; | 574 style->request.mime_type = kStyleMime; |
513 auto script = AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, | 575 auto script = AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, |
514 net::HIGHEST); | 576 net::HIGHEST); |
515 script->request.mime_type = kJavascriptMime; | 577 script->request.mime_type = kJavascriptMime; |
516 NavigateToURLAndCheckSubresources(GetURL(kHtmlXHRPath)); | 578 TestLearningAndPrefetching(GetURL(kHtmlXHRPath)); |
517 } | 579 } |
518 | 580 |
519 // ResourcePrefetchPredictor ignores all resources requested from subframes. | 581 // ResourcePrefetchPredictor ignores all resources requested from subframes. |
520 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 582 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
521 LearningWithIframe) { | 583 IframeShouldBeIgnored) { |
522 // Included from html_iframe.html. | 584 // Included from html_iframe.html. |
523 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 585 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
524 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, | 586 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, |
525 net::HIGHEST); | 587 net::HIGHEST); |
526 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 588 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
527 // Included from <iframe src="html_subresources.html"> and not recored. | 589 // Included from <iframe src="html_subresources.html"> and not recored. |
528 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), | 590 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), |
529 GetURL(kScriptPath), GetURL(kFontPath)}); | 591 GetURL(kScriptPath), GetURL(kFontPath)}); |
530 NavigateToURLAndCheckSubresources(GetURL(kHtmlIframePath)); | 592 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); |
531 } | 593 } |
532 | 594 |
533 } // namespace predictors | 595 } // namespace predictors |
OLD | NEW |