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 <stddef.h> | |
6 | |
7 #include <set> | |
8 | |
5 #include "base/command_line.h" | 9 #include "base/command_line.h" |
6 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 10 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
7 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 11 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
8 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 12 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
9 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 13 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 14 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
11 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 15 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
12 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/render_frame_host.h" | 22 #include "net/base/host_port_pair.h" |
19 #include "content/public/browser/render_process_host.h" | 23 #include "net/dns/mock_host_resolver.h" |
20 #include "net/test/embedded_test_server/http_request.h" | 24 #include "net/test/embedded_test_server/http_request.h" |
21 #include "net/test/embedded_test_server/http_response.h" | 25 #include "net/test/embedded_test_server/http_response.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
24 | 28 |
25 namespace predictors { | 29 namespace predictors { |
26 | 30 |
27 namespace { | 31 namespace { |
28 | 32 |
33 const char kFooHost[] = "foo.com"; | |
34 const char kBarHost[] = "bar.com"; | |
35 | |
29 const char kImageMime[] = "image/png"; | 36 const char kImageMime[] = "image/png"; |
30 const char kStyleMime[] = "text/css"; | 37 const char kStyleMime[] = "text/css"; |
31 const char kJavascriptMime[] = "application/javascript"; | 38 const char kJavascriptMime[] = "application/javascript"; |
32 | 39 |
33 // Paths to resources handled by a custom request handler. They return empty | 40 // Paths to resources handled by a custom request handler. They return empty |
34 // responses with controllable response headers. | 41 // responses with controllable response headers. |
35 const char kImagePath[] = "/handled-by-test/image.png"; | 42 const char kImagePath[] = "/handled-by-test/image.png"; |
36 const char kImagePath2[] = "/handled-by-test/image2.png"; | 43 const char kImagePath2[] = "/handled-by-test/image2.png"; |
37 const char kStylePath[] = "/handled-by-test/style.css"; | 44 const char kStylePath[] = "/handled-by-test/style.css"; |
38 const char kStylePath2[] = "/handled-by-test/style2.css"; | 45 const char kStylePath2[] = "/handled-by-test/style2.css"; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 std::unique(subresources->begin(), subresources->end(), | 132 std::unique(subresources->begin(), subresources->end(), |
126 [](const URLRequestSummary& x, const URLRequestSummary& y) { | 133 [](const URLRequestSummary& x, const URLRequestSummary& y) { |
127 return x.resource_url == y.resource_url; | 134 return x.resource_url == y.resource_url; |
128 }), | 135 }), |
129 subresources->end()); | 136 subresources->end()); |
130 } | 137 } |
131 | 138 |
132 // Fill a NavigationID with "empty" data that does not trigger | 139 // Fill a NavigationID with "empty" data that does not trigger |
133 // the is_valid DCHECK(). Allows comparing. | 140 // the is_valid DCHECK(). Allows comparing. |
134 void SetValidNavigationID(NavigationID* navigation_id) { | 141 void SetValidNavigationID(NavigationID* navigation_id) { |
135 navigation_id->render_process_id = 0; | 142 navigation_id->tab_id = 0; |
136 navigation_id->render_frame_id = 0; | |
137 navigation_id->main_frame_url = GURL("http://127.0.0.1"); | 143 navigation_id->main_frame_url = GURL("http://127.0.0.1"); |
138 } | 144 } |
139 | 145 |
140 void ModifySubresourceForComparison(URLRequestSummary* subresource, | 146 void ModifySubresourceForComparison(URLRequestSummary* subresource, |
141 bool match_navigation_id) { | 147 bool match_navigation_id) { |
142 if (!match_navigation_id) | 148 if (!match_navigation_id) |
143 SetValidNavigationID(&subresource->navigation_id); | 149 SetValidNavigationID(&subresource->navigation_id); |
144 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && | 150 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && |
145 subresource->priority == net::LOWEST) { | 151 subresource->priority == net::LOWEST) { |
146 // Fuzzy comparison for images because an image priority can be | 152 // Fuzzy comparison for images because an image priority can be |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 url_visit_count_(expected_url_visit_count), | 191 url_visit_count_(expected_url_visit_count), |
186 summary_(expected_summary), | 192 summary_(expected_summary), |
187 match_navigation_id_(match_navigation_id) {} | 193 match_navigation_id_(match_navigation_id) {} |
188 | 194 |
189 // TestObserver: | 195 // TestObserver: |
190 void OnNavigationLearned(size_t url_visit_count, | 196 void OnNavigationLearned(size_t url_visit_count, |
191 const PageRequestSummary& summary) override { | 197 const PageRequestSummary& summary) override { |
192 EXPECT_EQ(url_visit_count, url_visit_count_); | 198 EXPECT_EQ(url_visit_count, url_visit_count_); |
193 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); | 199 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); |
194 EXPECT_EQ(summary.initial_url, summary_.initial_url); | 200 EXPECT_EQ(summary.initial_url, summary_.initial_url); |
201 for (const auto& resource : summary.subresource_requests) | |
202 current_navigation_ids_.insert(resource.navigation_id); | |
195 CompareSubresources(summary.subresource_requests, | 203 CompareSubresources(summary.subresource_requests, |
196 summary_.subresource_requests, match_navigation_id_); | 204 summary_.subresource_requests, match_navigation_id_); |
197 run_loop_.Quit(); | 205 run_loop_.Quit(); |
198 } | 206 } |
199 | 207 |
200 void Wait() { run_loop_.Run(); } | 208 void Wait() { run_loop_.Run(); } |
201 | 209 |
210 std::set<NavigationID>& current_navigation_ids() { | |
211 return current_navigation_ids_; | |
212 } | |
213 | |
202 private: | 214 private: |
203 base::RunLoop run_loop_; | 215 base::RunLoop run_loop_; |
204 size_t url_visit_count_; | 216 size_t url_visit_count_; |
205 PageRequestSummary summary_; | 217 PageRequestSummary summary_; |
206 bool match_navigation_id_; | 218 bool match_navigation_id_; |
219 std::set<NavigationID> current_navigation_ids_; | |
207 | 220 |
208 DISALLOW_COPY_AND_ASSIGN(LearningObserver); | 221 DISALLOW_COPY_AND_ASSIGN(LearningObserver); |
209 }; | 222 }; |
210 | 223 |
211 // Helper class to track and allow waiting for a single OnPrefetchingFinished | 224 // Helper class to track and allow waiting for a single OnPrefetchingFinished |
212 // event. No learning events should be fired while this observer is active. | 225 // event. No learning events should be fired while this observer is active. |
213 class PrefetchingObserver : public TestObserver { | 226 class PrefetchingObserver : public TestObserver { |
214 public: | 227 public: |
215 PrefetchingObserver(ResourcePrefetchPredictor* predictor, | 228 PrefetchingObserver(ResourcePrefetchPredictor* predictor, |
216 const GURL& expected_main_frame_url) | 229 const GURL& expected_main_frame_url) |
(...skipping 23 matching lines...) Expand all Loading... | |
240 protected: | 253 protected: |
241 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 254 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
242 | 255 |
243 void SetUpCommandLine(base::CommandLine* command_line) override { | 256 void SetUpCommandLine(base::CommandLine* command_line) override { |
244 command_line->AppendSwitchASCII( | 257 command_line->AppendSwitchASCII( |
245 switches::kSpeculativeResourcePrefetching, | 258 switches::kSpeculativeResourcePrefetching, |
246 switches::kSpeculativeResourcePrefetchingEnabledExternal); | 259 switches::kSpeculativeResourcePrefetchingEnabledExternal); |
247 } | 260 } |
248 | 261 |
249 void SetUpOnMainThread() override { | 262 void SetUpOnMainThread() override { |
263 // Resolving all hosts to local allows us to have | |
264 // cross domains navigations (matching url_visit_count_, etc). | |
265 host_resolver()->AddRule("*", "127.0.0.1"); | |
250 embedded_test_server()->RegisterRequestHandler( | 266 embedded_test_server()->RegisterRequestHandler( |
251 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, | 267 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, |
252 base::Unretained(this))); | 268 base::Unretained(this))); |
253 embedded_test_server()->RegisterRequestHandler( | 269 embedded_test_server()->RegisterRequestHandler( |
254 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, | 270 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, |
255 base::Unretained(this))); | 271 base::Unretained(this))); |
256 ASSERT_TRUE(embedded_test_server()->Start()); | 272 ASSERT_TRUE(embedded_test_server()->Start()); |
257 predictor_ = | 273 predictor_ = |
258 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); | 274 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); |
259 ASSERT_TRUE(predictor_); | 275 ASSERT_TRUE(predictor_); |
(...skipping 17 matching lines...) Expand all Loading... | |
277 const GURL& main_frame_url, | 293 const GURL& main_frame_url, |
278 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { | 294 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { |
279 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); | 295 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); |
280 std::vector<URLRequestSummary> url_request_summaries; | 296 std::vector<URLRequestSummary> url_request_summaries; |
281 for (const auto& kv : resources_) { | 297 for (const auto& kv : resources_) { |
282 if (kv.second.is_no_store || !kv.second.should_be_recorded) | 298 if (kv.second.is_no_store || !kv.second.should_be_recorded) |
283 continue; | 299 continue; |
284 url_request_summaries.push_back( | 300 url_request_summaries.push_back( |
285 GetURLRequestSummaryForResource(endpoint_url, kv.second)); | 301 GetURLRequestSummaryForResource(endpoint_url, kv.second)); |
286 } | 302 } |
303 | |
304 bool match_navigation_id = | |
305 disposition == WindowOpenDisposition::CURRENT_TAB; | |
306 | |
287 LearningObserver observer( | 307 LearningObserver observer( |
288 predictor_, UpdateAndGetVisitCount(main_frame_url), | 308 predictor_, UpdateAndGetVisitCount(main_frame_url), |
289 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), | 309 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), |
290 url_request_summaries), | 310 url_request_summaries), |
291 true); // Matching navigation id by default | 311 match_navigation_id); |
292 ui_test_utils::NavigateToURLWithDisposition( | 312 ui_test_utils::NavigateToURLWithDisposition( |
293 browser(), main_frame_url, disposition, | 313 browser(), main_frame_url, disposition, |
294 ui_test_utils::BROWSER_TEST_NONE); | 314 ui_test_utils::BROWSER_TEST_NONE); |
295 observer.Wait(); | 315 observer.Wait(); |
296 for (auto& kv : resources_) { | 316 for (auto& kv : resources_) { |
297 if (!kv.second.is_no_store && kv.second.should_be_recorded) | 317 if (!kv.second.is_no_store && kv.second.should_be_recorded) |
298 kv.second.request.was_cached = true; | 318 kv.second.request.was_cached = true; |
299 } | 319 } |
320 for (const auto& nav : observer.current_navigation_ids()) | |
321 navigation_id_history_.insert(nav); | |
300 } | 322 } |
301 | 323 |
302 void PrefetchURL(const GURL& main_frame_url) { | 324 void PrefetchURL(const GURL& main_frame_url) { |
303 PrefetchingObserver observer(predictor_, main_frame_url); | 325 PrefetchingObserver observer(predictor_, main_frame_url); |
304 predictor_->StartPrefetching(main_frame_url, PrefetchOrigin::EXTERNAL); | 326 predictor_->StartPrefetching(main_frame_url, PrefetchOrigin::EXTERNAL); |
305 observer.Wait(); | 327 observer.Wait(); |
306 for (auto& kv : resources_) { | 328 for (auto& kv : resources_) { |
307 if (!kv.second.is_no_store && kv.second.should_be_recorded) | 329 if (!kv.second.is_no_store && kv.second.should_be_recorded) |
308 kv.second.request.was_cached = true; | 330 kv.second.request.was_cached = true; |
309 } | 331 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 const std::vector<RedirectEdge>& redirect_chain) { | 367 const std::vector<RedirectEdge>& redirect_chain) { |
346 ASSERT_FALSE(redirect_chain.empty()); | 368 ASSERT_FALSE(redirect_chain.empty()); |
347 GURL current = initial_url; | 369 GURL current = initial_url; |
348 for (const auto& edge : redirect_chain) { | 370 for (const auto& edge : redirect_chain) { |
349 auto result = redirects_.insert(std::make_pair(current, edge)); | 371 auto result = redirects_.insert(std::make_pair(current, edge)); |
350 EXPECT_TRUE(result.second) << current << " already has a redirect."; | 372 EXPECT_TRUE(result.second) << current << " already has a redirect."; |
351 current = edge.url; | 373 current = edge.url; |
352 } | 374 } |
353 } | 375 } |
354 | 376 |
377 void ClearResources() { resources_.clear(); } | |
378 | |
355 void ClearCache() { | 379 void ClearCache() { |
356 BrowsingDataRemover* remover = | 380 BrowsingDataRemover* remover = |
357 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 381 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); |
358 BrowsingDataRemoverObserver observer(remover); | 382 BrowsingDataRemoverObserver observer(remover); |
359 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(), | 383 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(), |
360 BrowsingDataRemover::REMOVE_CACHE, | 384 BrowsingDataRemover::REMOVE_CACHE, |
361 BrowsingDataHelper::UNPROTECTED_WEB, &observer); | 385 BrowsingDataHelper::UNPROTECTED_WEB, &observer); |
362 observer.Wait(); | 386 observer.Wait(); |
363 | 387 |
364 for (auto& kv : resources_) | 388 for (auto& kv : resources_) |
(...skipping 21 matching lines...) Expand all Loading... | |
386 } | 410 } |
387 | 411 |
388 // Returns the embedded test server working over HTTPS. Must be enabled by | 412 // Returns the embedded test server working over HTTPS. Must be enabled by |
389 // calling EnableHttpsServer() before use. | 413 // calling EnableHttpsServer() before use. |
390 const net::EmbeddedTestServer* https_server() const { | 414 const net::EmbeddedTestServer* https_server() const { |
391 return https_server_.get(); | 415 return https_server_.get(); |
392 } | 416 } |
393 | 417 |
394 net::EmbeddedTestServer* https_server() { return https_server_.get(); } | 418 net::EmbeddedTestServer* https_server() { return https_server_.get(); } |
395 | 419 |
420 size_t navigation_ids_history_size() const { | |
421 return navigation_id_history_.size(); | |
422 } | |
423 | |
396 private: | 424 private: |
397 // ResourcePrefetchPredictor needs to be initialized before the navigation | 425 // ResourcePrefetchPredictor needs to be initialized before the navigation |
398 // happens otherwise this navigation will be ignored by predictor. | 426 // happens otherwise this navigation will be ignored by predictor. |
399 void EnsurePredictorInitialized() { | 427 void EnsurePredictorInitialized() { |
400 if (predictor_->initialization_state_ == | 428 if (predictor_->initialization_state_ == |
401 ResourcePrefetchPredictor::INITIALIZED) { | 429 ResourcePrefetchPredictor::INITIALIZED) { |
402 return; | 430 return; |
403 } | 431 } |
404 | 432 |
405 InitializationObserver observer(predictor_); | 433 InitializationObserver observer(predictor_); |
406 if (predictor_->initialization_state_ == | 434 if (predictor_->initialization_state_ == |
407 ResourcePrefetchPredictor::NOT_INITIALIZED) { | 435 ResourcePrefetchPredictor::NOT_INITIALIZED) { |
408 predictor_->StartInitialization(); | 436 predictor_->StartInitialization(); |
409 } | 437 } |
410 observer.Wait(); | 438 observer.Wait(); |
411 } | 439 } |
412 | 440 |
413 URLRequestSummary GetURLRequestSummaryForResource( | 441 URLRequestSummary GetURLRequestSummaryForResource( |
414 const GURL& main_frame_url, | 442 const GURL& main_frame_url, |
415 const ResourceSummary& resource_summary) const { | 443 const ResourceSummary& resource_summary) const { |
416 URLRequestSummary summary(resource_summary.request); | 444 URLRequestSummary summary(resource_summary.request); |
417 content::WebContents* web_contents = | 445 content::WebContents* web_contents = |
418 browser()->tab_strip_model()->GetActiveWebContents(); | 446 browser()->tab_strip_model()->GetActiveWebContents(); |
419 int process_id = web_contents->GetRenderProcessHost()->GetID(); | |
420 int frame_id = web_contents->GetMainFrame()->GetRoutingID(); | |
421 summary.navigation_id = | 447 summary.navigation_id = |
422 CreateNavigationID(process_id, frame_id, main_frame_url.spec()); | 448 NavigationID(web_contents, main_frame_url, base::TimeTicks::Now()); |
423 return summary; | 449 return summary; |
424 } | 450 } |
425 | 451 |
426 GURL GetRedirectEndpoint(const GURL& initial_url) const { | 452 GURL GetRedirectEndpoint(const GURL& initial_url) const { |
427 GURL current = initial_url; | 453 GURL current = initial_url; |
428 while (true) { | 454 while (true) { |
429 auto it = redirects_.find(current); | 455 auto it = redirects_.find(current); |
430 if (it == redirects_.end()) | 456 if (it == redirects_.end()) |
431 break; | 457 break; |
432 current = it->second.url; | 458 current = it->second.url; |
433 } | 459 } |
434 return current; | 460 return current; |
435 } | 461 } |
436 | 462 |
437 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest( | 463 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest( |
438 const net::test_server::HttpRequest& request) const { | 464 const net::test_server::HttpRequest& request) const { |
439 auto resource_it = resources_.find(request.GetURL()); | 465 GURL resource_url = request.GetURL(); |
466 // Retrieve the host that was used in the request because | |
467 // resource_url contains a resolved host (e.g. 127.0.0.1). | |
468 if (request.headers.find("Host") != request.headers.end()) { | |
469 auto host_port_pair = | |
470 net::HostPortPair::FromString(request.headers.at("Host")); | |
471 GURL::Replacements replace_host; | |
472 replace_host.SetHostStr(host_port_pair.host()); | |
473 resource_url = resource_url.ReplaceComponents(replace_host); | |
474 } else { | |
475 ADD_FAILURE() << "Host header was not found in a HttpRequest to url: " | |
476 << resource_url.spec(); | |
477 } | |
478 | |
479 auto resource_it = resources_.find(resource_url); | |
440 if (resource_it == resources_.end()) | 480 if (resource_it == resources_.end()) |
441 return nullptr; | 481 return nullptr; |
442 | 482 |
443 const ResourceSummary& summary = resource_it->second; | 483 const ResourceSummary& summary = resource_it->second; |
444 if (summary.is_external) | 484 if (summary.is_external) |
445 return nullptr; | 485 return nullptr; |
446 | 486 |
447 auto http_response = | 487 auto http_response = |
448 base::MakeUnique<net::test_server::BasicHttpResponse>(); | 488 base::MakeUnique<net::test_server::BasicHttpResponse>(); |
449 http_response->set_code(net::HTTP_OK); | 489 http_response->set_code(net::HTTP_OK); |
(...skipping 30 matching lines...) Expand all Loading... | |
480 | 520 |
481 size_t UpdateAndGetVisitCount(const GURL& main_frame_url) { | 521 size_t UpdateAndGetVisitCount(const GURL& main_frame_url) { |
482 return ++visit_count_[main_frame_url]; | 522 return ++visit_count_[main_frame_url]; |
483 } | 523 } |
484 | 524 |
485 ResourcePrefetchPredictor* predictor_; | 525 ResourcePrefetchPredictor* predictor_; |
486 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 526 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
487 std::map<GURL, ResourceSummary> resources_; | 527 std::map<GURL, ResourceSummary> resources_; |
488 std::map<GURL, RedirectEdge> redirects_; | 528 std::map<GURL, RedirectEdge> redirects_; |
489 std::map<GURL, size_t> visit_count_; | 529 std::map<GURL, size_t> visit_count_; |
530 std::set<NavigationID> navigation_id_history_; | |
490 }; | 531 }; |
491 | 532 |
492 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { | 533 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { |
493 // These resources have default priorities that correspond to | 534 // These resources have default priorities that correspond to |
494 // blink::typeToPriority function. | 535 // blink::typeToPriority function. |
495 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 536 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
496 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 537 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
497 net::HIGHEST); | 538 net::HIGHEST); |
498 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 539 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
499 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 540 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
(...skipping 21 matching lines...) Expand all Loading... | |
521 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 562 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
522 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 563 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
523 net::HIGHEST); | 564 net::HIGHEST); |
524 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 565 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
525 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 566 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
526 net::HIGHEST); | 567 net::HIGHEST); |
527 TestLearningAndPrefetching(GetURL(kRedirectPath)); | 568 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
528 } | 569 } |
529 | 570 |
530 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 571 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
531 LearningAfterHttpToHttpsRedirect) { | 572 HttpToHttpsRedirect) { |
532 EnableHttpsServer(); | 573 EnableHttpsServer(); |
533 AddRedirectChain(GetURL(kRedirectPath), | 574 AddRedirectChain(GetURL(kRedirectPath), |
534 {{net::HTTP_MOVED_PERMANENTLY, | 575 {{net::HTTP_MOVED_PERMANENTLY, |
535 https_server()->GetURL(kHtmlSubresourcesPath)}}); | 576 https_server()->GetURL(kHtmlSubresourcesPath)}}); |
536 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, | 577 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, |
537 net::LOWEST); | 578 net::LOWEST); |
538 AddResource(https_server()->GetURL(kStylePath), | 579 AddResource(https_server()->GetURL(kStylePath), |
539 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | 580 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); |
540 AddResource(https_server()->GetURL(kScriptPath), | 581 AddResource(https_server()->GetURL(kScriptPath), |
541 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 582 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
542 AddResource(https_server()->GetURL(kFontPath), | 583 AddResource(https_server()->GetURL(kFontPath), |
543 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | 584 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); |
544 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); | 585 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
545 // TODO(alexilin): Test learning and prefetching once crbug.com/650246 is | |
546 // fixed. | |
547 } | 586 } |
548 | 587 |
549 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 588 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
550 JavascriptDocumentWrite) { | 589 JavascriptDocumentWrite) { |
551 auto externalScript = | 590 auto externalScript = |
552 AddExternalResource(GetURL(kScriptDocumentWritePath), | 591 AddExternalResource(GetURL(kScriptDocumentWritePath), |
553 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 592 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
554 externalScript->request.mime_type = kJavascriptMime; | 593 externalScript->request.mime_type = kJavascriptMime; |
555 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 594 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
556 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 595 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
612 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 651 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
613 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, | 652 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, |
614 net::HIGHEST); | 653 net::HIGHEST); |
615 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 654 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
616 // Included from <iframe src="html_subresources.html"> and not recored. | 655 // Included from <iframe src="html_subresources.html"> and not recored. |
617 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), | 656 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), |
618 GetURL(kScriptPath), GetURL(kFontPath)}); | 657 GetURL(kScriptPath), GetURL(kFontPath)}); |
619 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); | 658 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); |
620 } | 659 } |
621 | 660 |
661 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | |
662 CrossSiteNavigation) { | |
663 AddResource(embedded_test_server()->GetURL(kFooHost, kImagePath), | |
664 content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
665 AddResource(embedded_test_server()->GetURL(kFooHost, kStylePath), | |
666 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | |
667 AddResource(embedded_test_server()->GetURL(kFooHost, kScriptPath), | |
668 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
669 AddResource(embedded_test_server()->GetURL(kFooHost, kFontPath), | |
670 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | |
671 TestLearningAndPrefetching( | |
672 embedded_test_server()->GetURL(kFooHost, kHtmlSubresourcesPath)); | |
673 ClearResources(); | |
674 | |
675 AddResource(embedded_test_server()->GetURL(kBarHost, kImagePath), | |
676 content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
677 AddResource(embedded_test_server()->GetURL(kBarHost, kStylePath), | |
678 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | |
679 AddResource(embedded_test_server()->GetURL(kBarHost, kScriptPath), | |
680 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
681 AddResource(embedded_test_server()->GetURL(kBarHost, kFontPath), | |
682 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | |
683 // Navigating to kBarHost, although done in the same tab, will generate a new | |
684 // process because of cross domain behavior of PlzNavigate. | |
alexilin
2016/12/22 15:40:58
I think that the reasoning isn't quite correct.
Th
| |
685 TestLearningAndPrefetching( | |
686 embedded_test_server()->GetURL(kBarHost, kHtmlSubresourcesPath)); | |
687 } | |
688 | |
689 // In this test we are trying to assess if : | |
690 // - Reloading in the same tab is using the same NavigationID. | |
691 // - Navigation into a new tab, window or popup yields different NavigationID's. | |
692 // - Navigating twice to a new browser/popup yields different NavigationID's. | |
693 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | |
694 TabIdBehavingAsExpected) { | |
695 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
696 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | |
697 net::HIGHEST); | |
698 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
699 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | |
700 net::HIGHEST); | |
701 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath)); | |
702 EXPECT_EQ(navigation_ids_history_size(), 1U); | |
703 ClearCache(); | |
704 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath)); | |
705 EXPECT_EQ(navigation_ids_history_size(), 1U); | |
706 ClearCache(); | |
707 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
708 WindowOpenDisposition::NEW_BACKGROUND_TAB); | |
709 EXPECT_EQ(navigation_ids_history_size(), 2U); | |
710 ClearCache(); | |
711 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
712 WindowOpenDisposition::NEW_WINDOW); | |
713 EXPECT_EQ(navigation_ids_history_size(), 3U); | |
714 ClearCache(); | |
715 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
716 WindowOpenDisposition::NEW_POPUP); | |
717 EXPECT_EQ(navigation_ids_history_size(), 4U); | |
718 } | |
719 | |
622 } // namespace predictors | 720 } // namespace predictors |
OLD | NEW |