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/predictors/resource_prefetch_predictor.h" | 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 11 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 12 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/render_frame_host.h" | 20 #include "net/base/host_port_pair.h" |
| 17 #include "content/public/browser/render_process_host.h" | 21 #include "net/dns/mock_host_resolver.h" |
| 18 #include "net/test/embedded_test_server/http_request.h" | 22 #include "net/test/embedded_test_server/http_request.h" |
| 19 #include "net/test/embedded_test_server/http_response.h" | 23 #include "net/test/embedded_test_server/http_response.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 26 |
| 23 namespace predictors { | 27 namespace predictors { |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 const char kImageMime[] = "image/png"; | 31 const char kImageMime[] = "image/png"; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 std::unique(subresources->begin(), subresources->end(), | 108 std::unique(subresources->begin(), subresources->end(), |
| 105 [](const URLRequestSummary& x, const URLRequestSummary& y) { | 109 [](const URLRequestSummary& x, const URLRequestSummary& y) { |
| 106 return x.resource_url == y.resource_url; | 110 return x.resource_url == y.resource_url; |
| 107 }), | 111 }), |
| 108 subresources->end()); | 112 subresources->end()); |
| 109 } | 113 } |
| 110 | 114 |
| 111 // Fill a NavigationID with "empty" data that does not trigger | 115 // Fill a NavigationID with "empty" data that does not trigger |
| 112 // the is_valid DCHECK(). Allows comparing. | 116 // the is_valid DCHECK(). Allows comparing. |
| 113 void SetValidNavigationID(NavigationID* navigation_id) { | 117 void SetValidNavigationID(NavigationID* navigation_id) { |
| 114 navigation_id->render_process_id = 0; | 118 navigation_id->session_id = 0; |
| 115 navigation_id->render_frame_id = 0; | |
| 116 navigation_id->main_frame_url = GURL("http://127.0.0.1"); | 119 navigation_id->main_frame_url = GURL("http://127.0.0.1"); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void ModifySubresourceForComparison(URLRequestSummary* subresource, | 122 void ModifySubresourceForComparison(URLRequestSummary* subresource, |
| 120 bool match_navigation_id) { | 123 bool match_navigation_id) { |
| 121 if (!match_navigation_id) | 124 if (!match_navigation_id) |
| 122 SetValidNavigationID(&subresource->navigation_id); | 125 SetValidNavigationID(&subresource->navigation_id); |
| 123 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && | 126 if (subresource->resource_type == content::RESOURCE_TYPE_IMAGE && |
| 124 subresource->priority == net::LOWEST) { | 127 subresource->priority == net::LOWEST) { |
| 125 // Fuzzy comparison for images because an image priority can be | 128 // Fuzzy comparison for images because an image priority can be |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 url_visit_count_(expected_url_visit_count), | 167 url_visit_count_(expected_url_visit_count), |
| 165 summary_(expected_summary), | 168 summary_(expected_summary), |
| 166 match_navigation_id_(match_navigation_id) {} | 169 match_navigation_id_(match_navigation_id) {} |
| 167 | 170 |
| 168 // TestObserver: | 171 // TestObserver: |
| 169 void OnNavigationLearned(size_t url_visit_count, | 172 void OnNavigationLearned(size_t url_visit_count, |
| 170 const PageRequestSummary& summary) override { | 173 const PageRequestSummary& summary) override { |
| 171 EXPECT_EQ(url_visit_count, url_visit_count_); | 174 EXPECT_EQ(url_visit_count, url_visit_count_); |
| 172 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); | 175 EXPECT_EQ(summary.main_frame_url, summary_.main_frame_url); |
| 173 EXPECT_EQ(summary.initial_url, summary_.initial_url); | 176 EXPECT_EQ(summary.initial_url, summary_.initial_url); |
| 177 for (const auto& resource : summary.subresource_requests) | |
| 178 current_navigation_ids_.insert(resource.navigation_id); | |
| 174 CompareSubresources(summary.subresource_requests, | 179 CompareSubresources(summary.subresource_requests, |
| 175 summary_.subresource_requests, match_navigation_id_); | 180 summary_.subresource_requests, match_navigation_id_); |
| 176 run_loop_.Quit(); | 181 run_loop_.Quit(); |
| 177 } | 182 } |
| 178 | 183 |
| 179 void Wait() { run_loop_.Run(); } | 184 void Wait() { run_loop_.Run(); } |
| 180 | 185 |
| 186 std::set<NavigationID>& current_navigation_ids() { | |
| 187 return current_navigation_ids_; | |
| 188 } | |
| 189 | |
| 181 private: | 190 private: |
| 182 base::RunLoop run_loop_; | 191 base::RunLoop run_loop_; |
| 183 size_t url_visit_count_; | 192 size_t url_visit_count_; |
| 184 PageRequestSummary summary_; | 193 PageRequestSummary summary_; |
| 185 bool match_navigation_id_; | 194 bool match_navigation_id_; |
| 195 std::set<NavigationID> current_navigation_ids_; | |
| 186 | 196 |
| 187 DISALLOW_COPY_AND_ASSIGN(LearningObserver); | 197 DISALLOW_COPY_AND_ASSIGN(LearningObserver); |
| 188 }; | 198 }; |
| 189 | 199 |
| 190 // Helper class to track and allow waiting for a single OnPrefetchingFinished | 200 // Helper class to track and allow waiting for a single OnPrefetchingFinished |
| 191 // event. No learning events should be fired while this observer is active. | 201 // event. No learning events should be fired while this observer is active. |
| 192 class PrefetchingObserver : public TestObserver { | 202 class PrefetchingObserver : public TestObserver { |
| 193 public: | 203 public: |
| 194 PrefetchingObserver(ResourcePrefetchPredictor* predictor, | 204 PrefetchingObserver(ResourcePrefetchPredictor* predictor, |
| 195 const GURL& expected_main_frame_url) | 205 const GURL& expected_main_frame_url) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 219 protected: | 229 protected: |
| 220 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 230 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 221 | 231 |
| 222 void SetUpCommandLine(base::CommandLine* command_line) override { | 232 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 223 command_line->AppendSwitchASCII( | 233 command_line->AppendSwitchASCII( |
| 224 switches::kSpeculativeResourcePrefetching, | 234 switches::kSpeculativeResourcePrefetching, |
| 225 switches::kSpeculativeResourcePrefetchingEnabled); | 235 switches::kSpeculativeResourcePrefetchingEnabled); |
| 226 } | 236 } |
| 227 | 237 |
| 228 void SetUpOnMainThread() override { | 238 void SetUpOnMainThread() override { |
| 239 // Resolving all hosts to local allows us to have | |
| 240 // cross domains navigations (matching url_visit_count_, etc). | |
| 241 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 229 embedded_test_server()->RegisterRequestHandler( | 242 embedded_test_server()->RegisterRequestHandler( |
| 230 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, | 243 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, |
| 231 base::Unretained(this))); | 244 base::Unretained(this))); |
| 232 embedded_test_server()->RegisterRequestHandler( | 245 embedded_test_server()->RegisterRequestHandler( |
| 233 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, | 246 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, |
| 234 base::Unretained(this))); | 247 base::Unretained(this))); |
| 235 ASSERT_TRUE(embedded_test_server()->Start()); | 248 ASSERT_TRUE(embedded_test_server()->Start()); |
| 236 predictor_ = | 249 predictor_ = |
| 237 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); | 250 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); |
| 238 ASSERT_TRUE(predictor_); | 251 ASSERT_TRUE(predictor_); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 256 const GURL& main_frame_url, | 269 const GURL& main_frame_url, |
| 257 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { | 270 WindowOpenDisposition disposition = WindowOpenDisposition::CURRENT_TAB) { |
| 258 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); | 271 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); |
| 259 std::vector<URLRequestSummary> url_request_summaries; | 272 std::vector<URLRequestSummary> url_request_summaries; |
| 260 for (const auto& kv : resources_) { | 273 for (const auto& kv : resources_) { |
| 261 if (kv.second.is_no_store || !kv.second.should_be_recorded) | 274 if (kv.second.is_no_store || !kv.second.should_be_recorded) |
| 262 continue; | 275 continue; |
| 263 url_request_summaries.push_back( | 276 url_request_summaries.push_back( |
| 264 GetURLRequestSummaryForResource(endpoint_url, kv.second)); | 277 GetURLRequestSummaryForResource(endpoint_url, kv.second)); |
| 265 } | 278 } |
| 279 | |
| 280 bool match_navigation_id = true; | |
| 281 if (disposition != WindowOpenDisposition::CURRENT_TAB) | |
| 282 match_navigation_id = false; | |
| 283 | |
| 266 LearningObserver observer( | 284 LearningObserver observer( |
| 267 predictor_, UpdateAndGetVisitCount(main_frame_url), | 285 predictor_, UpdateAndGetVisitCount(main_frame_url), |
| 268 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), | 286 CreatePageRequestSummary(endpoint_url.spec(), main_frame_url.spec(), |
| 269 url_request_summaries), | 287 url_request_summaries), |
| 270 true); // Matching navigation id by default | 288 match_navigation_id); |
| 271 ui_test_utils::NavigateToURLWithDisposition( | 289 ui_test_utils::NavigateToURLWithDisposition( |
| 272 browser(), main_frame_url, disposition, | 290 browser(), main_frame_url, disposition, |
| 273 ui_test_utils::BROWSER_TEST_NONE); | 291 ui_test_utils::BROWSER_TEST_NONE); |
| 274 observer.Wait(); | 292 observer.Wait(); |
| 275 for (auto& kv : resources_) { | 293 for (auto& kv : resources_) { |
| 276 if (!kv.second.is_no_store && kv.second.should_be_recorded) | 294 if (!kv.second.is_no_store && kv.second.should_be_recorded) |
| 277 kv.second.request.was_cached = true; | 295 kv.second.request.was_cached = true; |
| 278 } | 296 } |
| 297 for (const auto& nav : observer.current_navigation_ids()) | |
| 298 navigation_id_history_.insert(nav); | |
| 279 } | 299 } |
| 280 | 300 |
| 281 void PrefetchURL(const GURL& main_frame_url) { | 301 void PrefetchURL(const GURL& main_frame_url) { |
| 282 PrefetchingObserver observer(predictor_, main_frame_url); | 302 PrefetchingObserver observer(predictor_, main_frame_url); |
| 283 predictor_->StartPrefetching(main_frame_url, PrefetchOrigin::EXTERNAL); | 303 predictor_->StartPrefetching(main_frame_url, PrefetchOrigin::EXTERNAL); |
| 284 observer.Wait(); | 304 observer.Wait(); |
| 285 for (auto& kv : resources_) { | 305 for (auto& kv : resources_) { |
| 286 if (!kv.second.is_no_store && kv.second.should_be_recorded) | 306 if (!kv.second.is_no_store && kv.second.should_be_recorded) |
| 287 kv.second.request.was_cached = true; | 307 kv.second.request.was_cached = true; |
| 288 } | 308 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 const std::vector<RedirectEdge>& redirect_chain) { | 344 const std::vector<RedirectEdge>& redirect_chain) { |
| 325 ASSERT_FALSE(redirect_chain.empty()); | 345 ASSERT_FALSE(redirect_chain.empty()); |
| 326 GURL current = initial_url; | 346 GURL current = initial_url; |
| 327 for (const auto& edge : redirect_chain) { | 347 for (const auto& edge : redirect_chain) { |
| 328 auto result = redirects_.insert(std::make_pair(current, edge)); | 348 auto result = redirects_.insert(std::make_pair(current, edge)); |
| 329 EXPECT_TRUE(result.second) << current << " already has a redirect."; | 349 EXPECT_TRUE(result.second) << current << " already has a redirect."; |
| 330 current = edge.url; | 350 current = edge.url; |
| 331 } | 351 } |
| 332 } | 352 } |
| 333 | 353 |
| 354 void ClearResources() { resources_.clear(); } | |
| 355 | |
| 334 void ClearCache() { | 356 void ClearCache() { |
| 335 chrome::ClearCache(browser()); | 357 chrome::ClearCache(browser()); |
| 336 for (auto& kv : resources_) | 358 for (auto& kv : resources_) |
| 337 kv.second.request.was_cached = false; | 359 kv.second.request.was_cached = false; |
| 338 } | 360 } |
| 339 | 361 |
| 340 // Shortcut for convenience. | 362 // Shortcut for convenience. |
| 341 GURL GetURL(const std::string& path) const { | 363 GURL GetURL(const std::string& path) const { |
| 342 return embedded_test_server()->GetURL(path); | 364 return embedded_test_server()->GetURL(path); |
| 343 } | 365 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 358 } | 380 } |
| 359 | 381 |
| 360 // Returns the embedded test server working over HTTPS. Must be enabled by | 382 // Returns the embedded test server working over HTTPS. Must be enabled by |
| 361 // calling EnableHttpsServer() before use. | 383 // calling EnableHttpsServer() before use. |
| 362 const net::EmbeddedTestServer* https_server() const { | 384 const net::EmbeddedTestServer* https_server() const { |
| 363 return https_server_.get(); | 385 return https_server_.get(); |
| 364 } | 386 } |
| 365 | 387 |
| 366 net::EmbeddedTestServer* https_server() { return https_server_.get(); } | 388 net::EmbeddedTestServer* https_server() { return https_server_.get(); } |
| 367 | 389 |
| 390 size_t navigation_ids_history_size() const { | |
| 391 return navigation_id_history_.size(); | |
| 392 } | |
| 393 | |
| 368 private: | 394 private: |
| 369 // ResourcePrefetchPredictor needs to be initialized before the navigation | 395 // ResourcePrefetchPredictor needs to be initialized before the navigation |
| 370 // happens otherwise this navigation will be ignored by predictor. | 396 // happens otherwise this navigation will be ignored by predictor. |
| 371 void EnsurePredictorInitialized() { | 397 void EnsurePredictorInitialized() { |
| 372 if (predictor_->initialization_state_ == | 398 if (predictor_->initialization_state_ == |
| 373 ResourcePrefetchPredictor::INITIALIZED) { | 399 ResourcePrefetchPredictor::INITIALIZED) { |
| 374 return; | 400 return; |
| 375 } | 401 } |
| 376 | 402 |
| 377 InitializationObserver observer(predictor_); | 403 InitializationObserver observer(predictor_); |
| 378 if (predictor_->initialization_state_ == | 404 if (predictor_->initialization_state_ == |
| 379 ResourcePrefetchPredictor::NOT_INITIALIZED) { | 405 ResourcePrefetchPredictor::NOT_INITIALIZED) { |
| 380 predictor_->StartInitialization(); | 406 predictor_->StartInitialization(); |
| 381 } | 407 } |
| 382 observer.Wait(); | 408 observer.Wait(); |
| 383 } | 409 } |
| 384 | 410 |
| 385 URLRequestSummary GetURLRequestSummaryForResource( | 411 URLRequestSummary GetURLRequestSummaryForResource( |
| 386 const GURL& main_frame_url, | 412 const GURL& main_frame_url, |
| 387 const ResourceSummary& resource_summary) const { | 413 const ResourceSummary& resource_summary) const { |
| 388 URLRequestSummary summary(resource_summary.request); | 414 URLRequestSummary summary(resource_summary.request); |
| 389 content::WebContents* web_contents = | 415 content::WebContents* web_contents = |
| 390 browser()->tab_strip_model()->GetActiveWebContents(); | 416 browser()->tab_strip_model()->GetActiveWebContents(); |
| 391 int process_id = web_contents->GetRenderProcessHost()->GetID(); | |
| 392 int frame_id = web_contents->GetMainFrame()->GetRoutingID(); | |
| 393 summary.navigation_id = | 417 summary.navigation_id = |
| 394 CreateNavigationID(process_id, frame_id, main_frame_url.spec()); | 418 NavigationID(web_contents, main_frame_url, base::TimeTicks::Now()); |
| 395 return summary; | 419 return summary; |
| 396 } | 420 } |
| 397 | 421 |
| 398 GURL GetRedirectEndpoint(const GURL& initial_url) const { | 422 GURL GetRedirectEndpoint(const GURL& initial_url) const { |
| 399 GURL current = initial_url; | 423 GURL current = initial_url; |
| 400 while (true) { | 424 while (true) { |
| 401 auto it = redirects_.find(current); | 425 auto it = redirects_.find(current); |
| 402 if (it == redirects_.end()) | 426 if (it == redirects_.end()) |
| 403 break; | 427 break; |
| 404 current = it->second.url; | 428 current = it->second.url; |
| 405 } | 429 } |
| 406 return current; | 430 return current; |
| 407 } | 431 } |
| 408 | 432 |
| 409 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest( | 433 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest( |
| 410 const net::test_server::HttpRequest& request) const { | 434 const net::test_server::HttpRequest& request) const { |
| 411 auto resource_it = resources_.find(request.GetURL()); | 435 GURL resource_url = request.GetURL(); |
| 436 // Retrieve the host that was used in the request because | |
| 437 // resource_url contains a resolved host (e.g. 127.0.0.1). | |
| 438 // Uses HostPortPair to ignore the port part (to avoid HTTP/HTTPS issues). | |
|
alexilin
2016/12/22 10:32:29
I didn't get this part about avoiding HTTP/HTTPS i
ahemery
2016/12/22 12:09:47
My mistake, will rephrase the comment. The idea wa
| |
| 439 if (request.headers.find("Host") != request.headers.end()) { | |
| 440 auto host_port_pair = | |
| 441 net::HostPortPair::FromString(request.headers.at("Host")); | |
| 442 GURL::Replacements replace_host; | |
| 443 replace_host.SetHostStr(host_port_pair.host()); | |
| 444 resource_url = resource_url.ReplaceComponents(replace_host); | |
| 445 } else { | |
| 446 ADD_FAILURE() << "Host header was not found in a HttpRequest"; | |
|
alexilin
2016/12/22 10:32:29
It would be also useful to include request.GetURL(
ahemery
2016/12/22 12:09:47
Done.
| |
| 447 } | |
| 448 | |
| 449 auto resource_it = resources_.find(resource_url); | |
| 412 if (resource_it == resources_.end()) | 450 if (resource_it == resources_.end()) |
| 413 return nullptr; | 451 return nullptr; |
| 414 | 452 |
| 415 const ResourceSummary& summary = resource_it->second; | 453 const ResourceSummary& summary = resource_it->second; |
| 416 if (summary.is_external) | 454 if (summary.is_external) |
| 417 return nullptr; | 455 return nullptr; |
| 418 | 456 |
| 419 auto http_response = | 457 auto http_response = |
| 420 base::MakeUnique<net::test_server::BasicHttpResponse>(); | 458 base::MakeUnique<net::test_server::BasicHttpResponse>(); |
| 421 http_response->set_code(net::HTTP_OK); | 459 http_response->set_code(net::HTTP_OK); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 452 | 490 |
| 453 size_t UpdateAndGetVisitCount(const GURL& main_frame_url) { | 491 size_t UpdateAndGetVisitCount(const GURL& main_frame_url) { |
| 454 return ++visit_count_[main_frame_url]; | 492 return ++visit_count_[main_frame_url]; |
| 455 } | 493 } |
| 456 | 494 |
| 457 ResourcePrefetchPredictor* predictor_; | 495 ResourcePrefetchPredictor* predictor_; |
| 458 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 496 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
| 459 std::map<GURL, ResourceSummary> resources_; | 497 std::map<GURL, ResourceSummary> resources_; |
| 460 std::map<GURL, RedirectEdge> redirects_; | 498 std::map<GURL, RedirectEdge> redirects_; |
| 461 std::map<GURL, size_t> visit_count_; | 499 std::map<GURL, size_t> visit_count_; |
| 500 std::set<NavigationID> navigation_id_history_; | |
| 501 }; | |
| 502 | |
| 503 // This browser test override is specifically used to have ONLY | |
| 504 // the learning part of the prefetcher without the actual prefetching. | |
| 505 // Used to avoid having caching issues for matcher. | |
|
Benoit L
2016/12/22 10:10:12
Is this still necessary? (per the offline discussi
alexilin
2016/12/22 10:32:29
It has to be done after I land the CL http://crrev
ahemery
2016/12/22 12:09:47
Rebasing off Alex changes removes the need for thi
| |
| 506 class ResourcePrefetchPredictorLearningBrowserTest | |
| 507 : public ResourcePrefetchPredictorBrowserTest { | |
| 508 protected: | |
| 509 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 510 command_line->AppendSwitchASCII( | |
| 511 switches::kSpeculativeResourcePrefetching, | |
| 512 switches::kSpeculativeResourcePrefetchingLearning); | |
| 513 } | |
| 462 }; | 514 }; |
| 463 | 515 |
| 464 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { | 516 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, Simple) { |
| 465 // These resources have default priorities that correspond to | 517 // These resources have default priorities that correspond to |
| 466 // blink::typeToPriority function. | 518 // blink::typeToPriority function. |
| 467 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 519 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| 468 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 520 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| 469 net::HIGHEST); | 521 net::HIGHEST); |
| 470 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 522 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| 471 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 523 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 493 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 545 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| 494 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 546 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| 495 net::HIGHEST); | 547 net::HIGHEST); |
| 496 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 548 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| 497 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | 549 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, |
| 498 net::HIGHEST); | 550 net::HIGHEST); |
| 499 TestLearningAndPrefetching(GetURL(kRedirectPath)); | 551 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
| 500 } | 552 } |
| 501 | 553 |
| 502 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 554 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| 503 LearningAfterHttpToHttpsRedirect) { | 555 HttpToHttpsRedirect) { |
| 504 EnableHttpsServer(); | 556 EnableHttpsServer(); |
| 505 AddRedirectChain(GetURL(kRedirectPath), | 557 AddRedirectChain(GetURL(kRedirectPath), |
| 506 {{net::HTTP_MOVED_PERMANENTLY, | 558 {{net::HTTP_MOVED_PERMANENTLY, |
| 507 https_server()->GetURL(kHtmlSubresourcesPath)}}); | 559 https_server()->GetURL(kHtmlSubresourcesPath)}}); |
| 508 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, | 560 AddResource(https_server()->GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, |
| 509 net::LOWEST); | 561 net::LOWEST); |
| 510 AddResource(https_server()->GetURL(kStylePath), | 562 AddResource(https_server()->GetURL(kStylePath), |
| 511 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | 563 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); |
| 512 AddResource(https_server()->GetURL(kScriptPath), | 564 AddResource(https_server()->GetURL(kScriptPath), |
| 513 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 565 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| 514 AddResource(https_server()->GetURL(kFontPath), | 566 AddResource(https_server()->GetURL(kFontPath), |
| 515 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | 567 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); |
| 516 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); | 568 TestLearningAndPrefetching(GetURL(kRedirectPath)); |
| 517 // TODO(alexilin): Test learning and prefetching once crbug.com/650246 is | |
| 518 // fixed. | |
| 519 } | 569 } |
| 520 | 570 |
| 521 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | 571 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, |
| 522 JavascriptDocumentWrite) { | 572 JavascriptDocumentWrite) { |
| 523 auto externalScript = | 573 auto externalScript = |
| 524 AddExternalResource(GetURL(kScriptDocumentWritePath), | 574 AddExternalResource(GetURL(kScriptDocumentWritePath), |
| 525 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 575 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| 526 externalScript->request.mime_type = kJavascriptMime; | 576 externalScript->request.mime_type = kJavascriptMime; |
| 527 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 577 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| 528 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | 578 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | 634 AddResource(GetURL(kImagePath2), content::RESOURCE_TYPE_IMAGE, net::LOWEST); |
| 585 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, | 635 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, |
| 586 net::HIGHEST); | 636 net::HIGHEST); |
| 587 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | 637 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); |
| 588 // Included from <iframe src="html_subresources.html"> and not recored. | 638 // Included from <iframe src="html_subresources.html"> and not recored. |
| 589 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), | 639 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), |
| 590 GetURL(kScriptPath), GetURL(kFontPath)}); | 640 GetURL(kScriptPath), GetURL(kFontPath)}); |
| 591 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); | 641 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); |
| 592 } | 642 } |
| 593 | 643 |
| 644 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorBrowserTest, | |
| 645 CrossSiteLearning) { | |
| 646 AddResource(embedded_test_server()->GetURL("foo.com", kImagePath), | |
| 647 content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
| 648 AddResource(embedded_test_server()->GetURL("foo.com", kStylePath), | |
| 649 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | |
| 650 AddResource(embedded_test_server()->GetURL("foo.com", kScriptPath), | |
| 651 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
| 652 AddResource(embedded_test_server()->GetURL("foo.com", kFontPath), | |
| 653 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | |
| 654 TestLearningAndPrefetching( | |
| 655 embedded_test_server()->GetURL("foo.com", kHtmlSubresourcesPath)); | |
| 656 ClearResources(); | |
| 657 | |
| 658 AddResource(embedded_test_server()->GetURL("bar.com", kImagePath), | |
| 659 content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
| 660 AddResource(embedded_test_server()->GetURL("bar.com", kStylePath), | |
| 661 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); | |
| 662 AddResource(embedded_test_server()->GetURL("bar.com", kScriptPath), | |
| 663 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
| 664 AddResource(embedded_test_server()->GetURL("bar.com", kFontPath), | |
| 665 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); | |
| 666 TestLearningAndPrefetching( | |
| 667 embedded_test_server()->GetURL("bar.com", kHtmlSubresourcesPath)); | |
| 668 } | |
| 669 | |
| 670 // In this test we are trying to assess if : | |
| 671 // - Reloading in the same tab is using the same NavigationID. | |
| 672 // - Navigation into a new tab, window or popup yields different NavigationID's. | |
| 673 // - Navigating twice to a new browser/popup yields different NavigationID's. | |
| 674 IN_PROC_BROWSER_TEST_F(ResourcePrefetchPredictorLearningBrowserTest, | |
| 675 SessionIdBehavingAsExpected) { | |
| 676 AddResource(GetURL(kImagePath), content::RESOURCE_TYPE_IMAGE, net::LOWEST); | |
| 677 AddResource(GetURL(kStylePath), content::RESOURCE_TYPE_STYLESHEET, | |
| 678 net::HIGHEST); | |
| 679 AddResource(GetURL(kScriptPath), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); | |
| 680 AddResource(GetURL(kFontPath), content::RESOURCE_TYPE_FONT_RESOURCE, | |
| 681 net::HIGHEST); | |
| 682 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath)); | |
| 683 EXPECT_EQ(navigation_ids_history_size(), 1U); | |
| 684 ClearCache(); | |
| 685 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath)); | |
| 686 EXPECT_EQ(navigation_ids_history_size(), 1U); | |
| 687 ClearCache(); | |
| 688 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
| 689 WindowOpenDisposition::NEW_BACKGROUND_TAB); | |
| 690 EXPECT_EQ(navigation_ids_history_size(), 2U); | |
| 691 ClearCache(); | |
| 692 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
| 693 WindowOpenDisposition::NEW_WINDOW); | |
| 694 EXPECT_EQ(navigation_ids_history_size(), 3U); | |
| 695 ClearCache(); | |
| 696 NavigateToURLAndCheckSubresources(GetURL(kHtmlSubresourcesPath), | |
| 697 WindowOpenDisposition::NEW_POPUP); | |
| 698 EXPECT_EQ(navigation_ids_history_size(), 4U); | |
| 699 } | |
| 700 | |
| 594 } // namespace predictors | 701 } // namespace predictors |
| OLD | NEW |