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