Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 using testing::StrictMock; | 35 using testing::StrictMock; |
| 36 using testing::UnorderedElementsAre; | 36 using testing::UnorderedElementsAre; |
| 37 | 37 |
| 38 namespace predictors { | 38 namespace predictors { |
| 39 | 39 |
| 40 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 40 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 41 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 41 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
| 42 using PrefetchDataMap = ResourcePrefetchPredictorTables::PrefetchDataMap; | 42 using PrefetchDataMap = ResourcePrefetchPredictorTables::PrefetchDataMap; |
| 43 using RedirectDataMap = ResourcePrefetchPredictorTables::RedirectDataMap; | 43 using RedirectDataMap = ResourcePrefetchPredictorTables::RedirectDataMap; |
| 44 using ManifestDataMap = ResourcePrefetchPredictorTables::ManifestDataMap; | 44 using ManifestDataMap = ResourcePrefetchPredictorTables::ManifestDataMap; |
| 45 using OriginDataMap = ResourcePrefetchPredictorTables::OriginDataMap; | |
| 45 | 46 |
| 46 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | 47 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( |
| 47 const char* headers) { | 48 const char* headers) { |
| 48 return make_scoped_refptr(new net::HttpResponseHeaders( | 49 return make_scoped_refptr(new net::HttpResponseHeaders( |
| 49 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); | 50 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); |
| 50 } | 51 } |
| 51 | 52 |
| 52 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { | 53 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { |
| 53 void OnResponseStarted(net::URLRequest* request, int net_error) override {} | 54 void OnResponseStarted(net::URLRequest* request, int net_error) override {} |
| 54 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} | 55 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 private: | 123 private: |
| 123 net::HttpResponseInfo response_info_; | 124 net::HttpResponseInfo response_info_; |
| 124 std::string mime_type_; | 125 std::string mime_type_; |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 class MockResourcePrefetchPredictorTables | 128 class MockResourcePrefetchPredictorTables |
| 128 : public ResourcePrefetchPredictorTables { | 129 : public ResourcePrefetchPredictorTables { |
| 129 public: | 130 public: |
| 130 MockResourcePrefetchPredictorTables() { } | 131 MockResourcePrefetchPredictorTables() { } |
| 131 | 132 |
| 132 MOCK_METHOD5(GetAllData, | 133 MOCK_METHOD6(GetAllData, |
| 133 void(PrefetchDataMap* url_data_map, | 134 void(PrefetchDataMap* url_data_map, |
| 134 PrefetchDataMap* host_data_map, | 135 PrefetchDataMap* host_data_map, |
| 135 RedirectDataMap* url_redirect_data_map, | 136 RedirectDataMap* url_redirect_data_map, |
| 136 RedirectDataMap* host_redirect_data_map, | 137 RedirectDataMap* host_redirect_data_map, |
| 137 ManifestDataMap* manifest_data_map)); | 138 ManifestDataMap* manifest_data_map, |
| 139 OriginDataMap* origin_data_map)); | |
| 138 MOCK_METHOD4(UpdateData, | 140 MOCK_METHOD4(UpdateData, |
| 139 void(const PrefetchData& url_data, | 141 void(const PrefetchData& url_data, |
| 140 const PrefetchData& host_data, | 142 const PrefetchData& host_data, |
| 141 const RedirectData& url_redirect_data, | 143 const RedirectData& url_redirect_data, |
| 142 const RedirectData& host_redirect_data)); | 144 const RedirectData& host_redirect_data)); |
| 143 MOCK_METHOD2(UpdateManifestData, | 145 MOCK_METHOD2(UpdateManifestData, |
| 144 void(const std::string& host, | 146 void(const std::string& host, |
| 145 const precache::PrecacheManifest& manifest_data)); | 147 const precache::PrecacheManifest& manifest_data)); |
| 148 MOCK_METHOD1(UpdateOriginData, void(const OriginData& origin_data)); | |
| 146 MOCK_METHOD2(DeleteResourceData, | 149 MOCK_METHOD2(DeleteResourceData, |
| 147 void(const std::vector<std::string>& urls, | 150 void(const std::vector<std::string>& urls, |
| 148 const std::vector<std::string>& hosts)); | 151 const std::vector<std::string>& hosts)); |
| 152 MOCK_METHOD1(DeleteOriginData, void(const std::vector<std::string>& hosts)); | |
| 149 MOCK_METHOD2(DeleteSingleResourceDataPoint, | 153 MOCK_METHOD2(DeleteSingleResourceDataPoint, |
| 150 void(const std::string& key, PrefetchKeyType key_type)); | 154 void(const std::string& key, PrefetchKeyType key_type)); |
| 151 MOCK_METHOD2(DeleteRedirectData, | 155 MOCK_METHOD2(DeleteRedirectData, |
| 152 void(const std::vector<std::string>& urls, | 156 void(const std::vector<std::string>& urls, |
| 153 const std::vector<std::string>& hosts)); | 157 const std::vector<std::string>& hosts)); |
| 154 MOCK_METHOD2(DeleteSingleRedirectDataPoint, | 158 MOCK_METHOD2(DeleteSingleRedirectDataPoint, |
| 155 void(const std::string& key, PrefetchKeyType key_type)); | 159 void(const std::string& key, PrefetchKeyType key_type)); |
| 156 MOCK_METHOD1(DeleteManifestData, void(const std::vector<std::string>& hosts)); | 160 MOCK_METHOD1(DeleteManifestData, void(const std::vector<std::string>& hosts)); |
| 157 MOCK_METHOD0(DeleteAllData, void()); | 161 MOCK_METHOD0(DeleteAllData, void()); |
| 158 | 162 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 void ResetPredictor() { | 234 void ResetPredictor() { |
| 231 ResourcePrefetchPredictorConfig config; | 235 ResourcePrefetchPredictorConfig config; |
| 232 config.max_urls_to_track = 3; | 236 config.max_urls_to_track = 3; |
| 233 config.max_hosts_to_track = 2; | 237 config.max_hosts_to_track = 2; |
| 234 config.min_url_visit_count = 2; | 238 config.min_url_visit_count = 2; |
| 235 config.max_resources_per_entry = 4; | 239 config.max_resources_per_entry = 4; |
| 236 config.max_consecutive_misses = 2; | 240 config.max_consecutive_misses = 2; |
| 237 config.min_resource_confidence_to_trigger_prefetch = 0.5; | 241 config.min_resource_confidence_to_trigger_prefetch = 0.5; |
| 238 config.is_url_learning_enabled = true; | 242 config.is_url_learning_enabled = true; |
| 239 config.is_manifests_enabled = true; | 243 config.is_manifests_enabled = true; |
| 244 config.is_origin_prediction_enabled = true; | |
| 240 | 245 |
| 241 config.mode |= ResourcePrefetchPredictorConfig::LEARNING; | 246 config.mode |= ResourcePrefetchPredictorConfig::LEARNING; |
| 242 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); | 247 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); |
| 243 predictor_->set_mock_tables(mock_tables_); | 248 predictor_->set_mock_tables(mock_tables_); |
| 244 } | 249 } |
| 245 | 250 |
| 246 void InitializeSampleData(); | 251 void InitializeSampleData(); |
| 247 void TestRedirectStatusHistogram( | 252 void TestRedirectStatusHistogram( |
| 248 const std::string& predictor_initial_key, | 253 const std::string& predictor_initial_key, |
| 249 const std::string& predictor_key, | 254 const std::string& predictor_key, |
| 250 const std::string& navigation_initial_url, | 255 const std::string& navigation_initial_url, |
| 251 const std::string& navigation_url, | 256 const std::string& navigation_url, |
| 252 ResourcePrefetchPredictor::RedirectStatus expected_status); | 257 ResourcePrefetchPredictor::RedirectStatus expected_status); |
| 253 | 258 |
| 254 content::TestBrowserThreadBundle thread_bundle_; | 259 content::TestBrowserThreadBundle thread_bundle_; |
| 255 std::unique_ptr<TestingProfile> profile_; | 260 std::unique_ptr<TestingProfile> profile_; |
| 256 net::TestURLRequestContext url_request_context_; | 261 net::TestURLRequestContext url_request_context_; |
| 257 | 262 |
| 258 std::unique_ptr<ResourcePrefetchPredictor> predictor_; | 263 std::unique_ptr<ResourcePrefetchPredictor> predictor_; |
| 259 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_; | 264 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_; |
| 260 | 265 |
| 261 PrefetchDataMap test_url_data_; | 266 PrefetchDataMap test_url_data_; |
| 262 PrefetchDataMap test_host_data_; | 267 PrefetchDataMap test_host_data_; |
| 263 RedirectDataMap test_url_redirect_data_; | 268 RedirectDataMap test_url_redirect_data_; |
| 264 RedirectDataMap test_host_redirect_data_; | 269 RedirectDataMap test_host_redirect_data_; |
| 265 ManifestDataMap test_manifest_data_; | 270 ManifestDataMap test_manifest_data_; |
| 271 OriginDataMap test_origin_data_; | |
| 266 PrefetchData empty_resource_data_; | 272 PrefetchData empty_resource_data_; |
| 267 RedirectData empty_redirect_data_; | 273 RedirectData empty_redirect_data_; |
| 268 | 274 |
| 269 MockURLRequestJobFactory url_request_job_factory_; | 275 MockURLRequestJobFactory url_request_job_factory_; |
| 270 EmptyURLRequestDelegate url_request_delegate_; | 276 EmptyURLRequestDelegate url_request_delegate_; |
| 271 | 277 |
| 272 std::unique_ptr<base::HistogramTester> histogram_tester_; | 278 std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 273 }; | 279 }; |
| 274 | 280 |
| 275 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() | 281 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 293 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS)); | 299 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS)); |
| 294 // Initialize the predictor with empty data. | 300 // Initialize the predictor with empty data. |
| 295 ResetPredictor(); | 301 ResetPredictor(); |
| 296 EXPECT_EQ(predictor_->initialization_state_, | 302 EXPECT_EQ(predictor_->initialization_state_, |
| 297 ResourcePrefetchPredictor::NOT_INITIALIZED); | 303 ResourcePrefetchPredictor::NOT_INITIALIZED); |
| 298 EXPECT_CALL(*mock_tables_.get(), | 304 EXPECT_CALL(*mock_tables_.get(), |
| 299 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 305 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 300 Pointee(ContainerEq(PrefetchDataMap())), | 306 Pointee(ContainerEq(PrefetchDataMap())), |
| 301 Pointee(ContainerEq(RedirectDataMap())), | 307 Pointee(ContainerEq(RedirectDataMap())), |
| 302 Pointee(ContainerEq(RedirectDataMap())), | 308 Pointee(ContainerEq(RedirectDataMap())), |
| 303 Pointee(ContainerEq(ManifestDataMap())))); | 309 Pointee(ContainerEq(ManifestDataMap())), |
| 310 Pointee(ContainerEq(OriginDataMap())))); | |
| 304 InitializePredictor(); | 311 InitializePredictor(); |
| 305 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 312 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 306 EXPECT_EQ(predictor_->initialization_state_, | 313 EXPECT_EQ(predictor_->initialization_state_, |
| 307 ResourcePrefetchPredictor::INITIALIZED); | 314 ResourcePrefetchPredictor::INITIALIZED); |
| 308 | 315 |
| 309 url_request_context_.set_job_factory(&url_request_job_factory_); | 316 url_request_context_.set_job_factory(&url_request_job_factory_); |
| 310 | 317 |
| 311 histogram_tester_.reset(new base::HistogramTester()); | 318 histogram_tester_.reset(new base::HistogramTester()); |
| 312 } | 319 } |
| 313 | 320 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 InitializePrecacheResource(google.add_resource(), | 442 InitializePrecacheResource(google.add_resource(), |
| 436 "http://static.google.com/style.css", 0.333); | 443 "http://static.google.com/style.css", 0.333); |
| 437 | 444 |
| 438 precache::PrecacheManifest facebook = CreateManifestData(12); | 445 precache::PrecacheManifest facebook = CreateManifestData(12); |
| 439 InitializePrecacheResource(facebook.add_resource(), | 446 InitializePrecacheResource(facebook.add_resource(), |
| 440 "http://fb.com/static.css", 0.99); | 447 "http://fb.com/static.css", 0.99); |
| 441 | 448 |
| 442 test_manifest_data_.insert(std::make_pair("google.com", google)); | 449 test_manifest_data_.insert(std::make_pair("google.com", google)); |
| 443 test_manifest_data_.insert(std::make_pair("facebook.com", facebook)); | 450 test_manifest_data_.insert(std::make_pair("facebook.com", facebook)); |
| 444 } | 451 } |
| 452 | |
| 453 { // Origin data. | |
| 454 OriginData google = CreateOriginData("google.com", 12); | |
| 455 InitializeOriginStat(google.add_origins(), "https://static.google.com", 12, | |
| 456 0, 0, 3., false, true); | |
| 457 InitializeOriginStat(google.add_origins(), "https://cats.google.com", 12, 0, | |
| 458 0, 5., true, true); | |
| 459 test_origin_data_.insert({"google.com", google}); | |
| 460 | |
| 461 OriginData twitter = CreateOriginData("twitter.com", 42); | |
| 462 InitializeOriginStat(twitter.add_origins(), "https://static.twitter.com", | |
| 463 12, 0, 0, 3., false, true); | |
| 464 InitializeOriginStat(twitter.add_origins(), "https://random.140chars.com", | |
| 465 12, 0, 0, 3., false, true); | |
| 466 test_origin_data_.insert({"twitter.com", twitter}); | |
| 467 } | |
| 445 } | 468 } |
| 446 | 469 |
| 447 void ResourcePrefetchPredictorTest::TestRedirectStatusHistogram( | 470 void ResourcePrefetchPredictorTest::TestRedirectStatusHistogram( |
| 448 const std::string& predictor_initial_key, | 471 const std::string& predictor_initial_key, |
| 449 const std::string& predictor_key, | 472 const std::string& predictor_key, |
| 450 const std::string& navigation_initial_url, | 473 const std::string& navigation_initial_url, |
| 451 const std::string& navigation_url, | 474 const std::string& navigation_url, |
| 452 ResourcePrefetchPredictor::RedirectStatus expected_status) { | 475 ResourcePrefetchPredictor::RedirectStatus expected_status) { |
| 453 // Database initialization. | 476 // Database initialization. |
| 454 const std::string& script_url = "https://cdn.google.com/script.js"; | 477 const std::string& script_url = "https://cdn.google.com/script.js"; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 465 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10, | 488 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10, |
| 466 0, 0); | 489 0, 0); |
| 467 predictor_->host_redirect_table_cache_->insert( | 490 predictor_->host_redirect_table_cache_->insert( |
| 468 std::make_pair(redirect.primary_key(), redirect)); | 491 std::make_pair(redirect.primary_key(), redirect)); |
| 469 } | 492 } |
| 470 | 493 |
| 471 // Navigation simulation. | 494 // Navigation simulation. |
| 472 using testing::_; | 495 using testing::_; |
| 473 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)) | 496 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)) |
| 474 .Times(testing::AtLeast(1)); | 497 .Times(testing::AtLeast(1)); |
| 498 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); | |
| 499 | |
| 475 URLRequestSummary initial = | 500 URLRequestSummary initial = |
| 476 CreateURLRequestSummary(1, navigation_initial_url); | 501 CreateURLRequestSummary(1, navigation_initial_url); |
| 477 predictor_->RecordURLRequest(initial); | 502 predictor_->RecordURLRequest(initial); |
| 478 | 503 |
| 479 if (navigation_initial_url != navigation_url) { | 504 if (navigation_initial_url != navigation_url) { |
| 480 URLRequestSummary redirect = | 505 URLRequestSummary redirect = |
| 481 CreateRedirectRequestSummary(1, navigation_initial_url, navigation_url); | 506 CreateRedirectRequestSummary(1, navigation_initial_url, navigation_url); |
| 482 predictor_->RecordURLRedirect(redirect); | 507 predictor_->RecordURLRedirect(redirect); |
| 483 } | 508 } |
| 484 NavigationID navigation_id = CreateNavigationID(1, navigation_url); | 509 NavigationID navigation_id = CreateNavigationID(1, navigation_url); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 506 static_cast<int>(ResourceData_Priority_REQUEST_PRIORITY_HIGHEST), | 531 static_cast<int>(ResourceData_Priority_REQUEST_PRIORITY_HIGHEST), |
| 507 "Database/Net priority mismatch: Maximum"); | 532 "Database/Net priority mismatch: Maximum"); |
| 508 | 533 |
| 509 // Tests that the predictor initializes correctly without any data. | 534 // Tests that the predictor initializes correctly without any data. |
| 510 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { | 535 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { |
| 511 EXPECT_TRUE(predictor_->url_table_cache_->empty()); | 536 EXPECT_TRUE(predictor_->url_table_cache_->empty()); |
| 512 EXPECT_TRUE(predictor_->host_table_cache_->empty()); | 537 EXPECT_TRUE(predictor_->host_table_cache_->empty()); |
| 513 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty()); | 538 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty()); |
| 514 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty()); | 539 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty()); |
| 515 EXPECT_TRUE(predictor_->manifest_table_cache_->empty()); | 540 EXPECT_TRUE(predictor_->manifest_table_cache_->empty()); |
| 541 EXPECT_TRUE(predictor_->origin_table_cache_->empty()); | |
| 516 } | 542 } |
| 517 | 543 |
| 518 // Tests that the history and the db tables data are loaded correctly. | 544 // Tests that the history and the db tables data are loaded correctly. |
| 519 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) { | 545 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) { |
| 520 AddUrlToHistory("http://www.google.com/", 4); | 546 AddUrlToHistory("http://www.google.com/", 4); |
| 521 AddUrlToHistory("http://www.yahoo.com/", 2); | 547 AddUrlToHistory("http://www.yahoo.com/", 2); |
| 522 | 548 |
| 523 EXPECT_CALL(*mock_tables_.get(), | 549 EXPECT_CALL(*mock_tables_.get(), |
| 524 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 550 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 525 Pointee(ContainerEq(PrefetchDataMap())), | 551 Pointee(ContainerEq(PrefetchDataMap())), |
| 526 Pointee(ContainerEq(RedirectDataMap())), | 552 Pointee(ContainerEq(RedirectDataMap())), |
| 527 Pointee(ContainerEq(RedirectDataMap())), | 553 Pointee(ContainerEq(RedirectDataMap())), |
| 528 Pointee(ContainerEq(ManifestDataMap())))) | 554 Pointee(ContainerEq(ManifestDataMap())), |
| 555 Pointee(ContainerEq(OriginDataMap())))) | |
| 529 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 556 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 530 SetArgPointee<1>(test_host_data_), | 557 SetArgPointee<1>(test_host_data_), |
| 531 SetArgPointee<2>(test_url_redirect_data_), | 558 SetArgPointee<2>(test_url_redirect_data_), |
| 532 SetArgPointee<3>(test_host_redirect_data_), | 559 SetArgPointee<3>(test_host_redirect_data_), |
| 533 SetArgPointee<4>(test_manifest_data_))); | 560 SetArgPointee<4>(test_manifest_data_), |
| 561 SetArgPointee<5>(test_origin_data_))); | |
| 534 | 562 |
| 535 ResetPredictor(); | 563 ResetPredictor(); |
| 536 InitializePredictor(); | 564 InitializePredictor(); |
| 537 | 565 |
| 538 // Test that the internal variables correctly initialized. | 566 // Test that the internal variables correctly initialized. |
| 539 EXPECT_EQ(predictor_->initialization_state_, | 567 EXPECT_EQ(predictor_->initialization_state_, |
| 540 ResourcePrefetchPredictor::INITIALIZED); | 568 ResourcePrefetchPredictor::INITIALIZED); |
| 541 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 569 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 542 | 570 |
| 543 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); | 571 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); |
| 544 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); | 572 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); |
| 545 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); | 573 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); |
| 546 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); | 574 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); |
| 547 EXPECT_EQ(test_manifest_data_, *predictor_->manifest_table_cache_); | 575 EXPECT_EQ(test_manifest_data_, *predictor_->manifest_table_cache_); |
| 576 EXPECT_EQ(test_origin_data_, *predictor_->origin_table_cache_); | |
| 548 } | 577 } |
| 549 | 578 |
| 550 // Single navigation but history count is low, so should not record. | 579 // Single navigation but history count is low, so should not record. |
| 551 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { | 580 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { |
| 552 const int kVisitCount = 1; | 581 const int kVisitCount = 1; |
| 553 AddUrlToHistory("https://www.google.com", kVisitCount); | 582 AddUrlToHistory("https://www.google.com", kVisitCount); |
| 554 | 583 |
| 555 URLRequestSummary main_frame = | 584 URLRequestSummary main_frame = |
| 556 CreateURLRequestSummary(1, "http://www.google.com"); | 585 CreateURLRequestSummary(1, "http://www.google.com"); |
| 557 predictor_->RecordURLRequest(main_frame); | 586 predictor_->RecordURLRequest(main_frame); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 net::MEDIUM, false, false); | 622 net::MEDIUM, false, false); |
| 594 InitializeResourceData( | 623 InitializeResourceData( |
| 595 host_data.add_resources(), "https://google.com/script1.js", | 624 host_data.add_resources(), "https://google.com/script1.js", |
| 596 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | 625 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 597 InitializeResourceData( | 626 InitializeResourceData( |
| 598 host_data.add_resources(), "https://google.com/script2.js", | 627 host_data.add_resources(), "https://google.com/script2.js", |
| 599 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 628 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 600 EXPECT_CALL(*mock_tables_.get(), | 629 EXPECT_CALL(*mock_tables_.get(), |
| 601 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 630 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 602 empty_redirect_data_)); | 631 empty_redirect_data_)); |
| 632 OriginData origin_data = CreateOriginData("www.google.com"); | |
| 633 InitializeOriginStat(origin_data.add_origins(), "https://google.com/", 1, 0, | |
| 634 0, 1., false, true); | |
| 635 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(origin_data)); | |
| 603 | 636 |
| 604 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 637 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 605 profile_->BlockUntilHistoryProcessesPendingRequests(); | 638 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 606 } | 639 } |
| 607 | 640 |
| 608 // Single navigation that will be recorded. Will check for duplicate | 641 // Single navigation that will be recorded. Will check for duplicate |
| 609 // resources and also for number of resources saved. | 642 // resources and also for number of resources saved. |
| 610 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 643 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
| 611 const int kVisitCount = 4; | 644 const int kVisitCount = 4; |
| 612 AddUrlToHistory("http://www.google.com", kVisitCount); | 645 AddUrlToHistory("http://www.google.com", kVisitCount); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 637 1, "http://www.google.com", "http://google.com/image1.png", | 670 1, "http://www.google.com", "http://google.com/image1.png", |
| 638 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 671 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 639 predictor_->RecordURLResponse(resources.back()); | 672 predictor_->RecordURLResponse(resources.back()); |
| 640 resources.push_back(CreateURLRequestSummary( | 673 resources.push_back(CreateURLRequestSummary( |
| 641 1, "http://www.google.com", "http://google.com/image2.png", | 674 1, "http://www.google.com", "http://google.com/image2.png", |
| 642 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 675 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 643 predictor_->RecordURLResponse(resources.back()); | 676 predictor_->RecordURLResponse(resources.back()); |
| 644 resources.push_back(CreateURLRequestSummary( | 677 resources.push_back(CreateURLRequestSummary( |
| 645 1, "http://www.google.com", "http://google.com/style2.css", | 678 1, "http://www.google.com", "http://google.com/style2.css", |
| 646 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); | 679 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
| 680 | |
| 681 auto no_store = CreateURLRequestSummary( | |
|
alexilin
2017/04/11 09:42:19
I'd test subresource redirect case as well to be s
Benoit L
2017/04/11 14:20:13
Thank you, turns out that it was incorrect!
| |
| 682 1, "http://www.google.com", | |
| 683 "http://static.google.com/style2-no-store.css", | |
| 684 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | |
| 685 no_store.is_no_store = true; | |
| 686 predictor_->RecordURLResponse(no_store); | |
| 687 | |
| 647 predictor_->RecordURLResponse(resources.back()); | 688 predictor_->RecordURLResponse(resources.back()); |
| 648 | 689 |
| 649 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 690 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
| 650 predictor_.get()); | 691 predictor_.get()); |
| 651 EXPECT_CALL(mock_observer, | 692 EXPECT_CALL(mock_observer, |
| 652 OnNavigationLearned( | 693 OnNavigationLearned( |
| 653 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 694 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 654 "http://www.google.com", | 695 "http://www.google.com", |
| 655 resources))); | 696 resources))); |
| 656 | 697 |
| 657 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 698 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| 658 InitializeResourceData(url_data.add_resources(), | 699 InitializeResourceData(url_data.add_resources(), |
| 659 "http://google.com/style1.css", | 700 "http://google.com/style1.css", |
| 660 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | 701 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 661 net::MEDIUM, false, false); | 702 net::MEDIUM, false, false); |
| 662 InitializeResourceData( | 703 InitializeResourceData( |
| 663 url_data.add_resources(), "http://google.com/script1.js", | 704 url_data.add_resources(), "http://google.com/script1.js", |
| 664 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | 705 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 665 InitializeResourceData( | 706 InitializeResourceData( |
| 666 url_data.add_resources(), "http://google.com/script2.js", | 707 url_data.add_resources(), "http://google.com/script2.js", |
| 667 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 708 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 668 InitializeResourceData(url_data.add_resources(), | 709 InitializeResourceData(url_data.add_resources(), |
| 669 "http://google.com/style2.css", | 710 "http://google.com/style2.css", |
| 670 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, | 711 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, |
| 671 net::MEDIUM, false, false); | 712 net::MEDIUM, false, false); |
| 672 EXPECT_CALL(*mock_tables_.get(), | 713 EXPECT_CALL(*mock_tables_.get(), |
| 673 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, | 714 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, |
| 674 empty_redirect_data_)); | 715 empty_redirect_data_)); |
| 675 | 716 |
| 717 OriginData origin_data = CreateOriginData("www.google.com"); | |
| 718 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/", | |
| 719 1, 0, 0, 2., true, true); | |
| 720 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0, | |
| 721 1., false, true); | |
| 722 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(origin_data)); | |
| 723 | |
| 676 PrefetchData host_data = CreatePrefetchData("www.google.com"); | 724 PrefetchData host_data = CreatePrefetchData("www.google.com"); |
| 677 host_data.mutable_resources()->CopyFrom(url_data.resources()); | 725 host_data.mutable_resources()->CopyFrom(url_data.resources()); |
| 678 EXPECT_CALL(*mock_tables_.get(), | 726 EXPECT_CALL(*mock_tables_.get(), |
| 679 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 727 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 680 empty_redirect_data_)); | 728 empty_redirect_data_)); |
| 681 | 729 |
| 682 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 730 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 683 profile_->BlockUntilHistoryProcessesPendingRequests(); | 731 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 684 } | 732 } |
| 685 | 733 |
| 686 // Tests that navigation is recorded correctly for URL already present in | 734 // Tests that navigation is recorded correctly for URL already present in |
| 687 // the database cache. | 735 // the database cache. |
| 688 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { | 736 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { |
| 689 const int kVisitCount = 4; | 737 const int kVisitCount = 4; |
| 690 AddUrlToHistory("http://www.google.com", kVisitCount); | 738 AddUrlToHistory("http://www.google.com", kVisitCount); |
| 691 | 739 |
| 692 EXPECT_CALL(*mock_tables_.get(), | 740 EXPECT_CALL(*mock_tables_.get(), |
| 693 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 741 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 694 Pointee(ContainerEq(PrefetchDataMap())), | 742 Pointee(ContainerEq(PrefetchDataMap())), |
| 695 Pointee(ContainerEq(RedirectDataMap())), | 743 Pointee(ContainerEq(RedirectDataMap())), |
| 696 Pointee(ContainerEq(RedirectDataMap())), | 744 Pointee(ContainerEq(RedirectDataMap())), |
| 697 Pointee(ContainerEq(ManifestDataMap())))) | 745 Pointee(ContainerEq(ManifestDataMap())), |
| 746 Pointee(ContainerEq(OriginDataMap())))) | |
| 698 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 747 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 699 SetArgPointee<1>(test_host_data_))); | 748 SetArgPointee<1>(test_host_data_))); |
| 700 ResetPredictor(); | 749 ResetPredictor(); |
| 701 InitializePredictor(); | 750 InitializePredictor(); |
| 702 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 751 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 703 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 752 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 704 | 753 |
| 705 URLRequestSummary main_frame = CreateURLRequestSummary( | 754 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 706 1, "http://www.google.com", "http://www.google.com", | 755 1, "http://www.google.com", "http://www.google.com", |
| 707 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 756 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 730 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 779 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 731 predictor_->RecordURLResponse(resources.back()); | 780 predictor_->RecordURLResponse(resources.back()); |
| 732 resources.push_back(CreateURLRequestSummary( | 781 resources.push_back(CreateURLRequestSummary( |
| 733 1, "http://www.google.com", "http://google.com/image2.png", | 782 1, "http://www.google.com", "http://google.com/image2.png", |
| 734 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 783 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 735 predictor_->RecordURLResponse(resources.back()); | 784 predictor_->RecordURLResponse(resources.back()); |
| 736 resources.push_back(CreateURLRequestSummary( | 785 resources.push_back(CreateURLRequestSummary( |
| 737 1, "http://www.google.com", "http://google.com/style2.css", | 786 1, "http://www.google.com", "http://google.com/style2.css", |
| 738 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); | 787 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
| 739 predictor_->RecordURLResponse(resources.back()); | 788 predictor_->RecordURLResponse(resources.back()); |
| 789 auto no_store = CreateURLRequestSummary( | |
| 790 1, "http://www.google.com", | |
| 791 "http://static.google.com/style2-no-store.css", | |
| 792 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | |
| 793 no_store.is_no_store = true; | |
| 794 predictor_->RecordURLResponse(no_store); | |
| 740 | 795 |
| 741 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 796 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
| 742 predictor_.get()); | 797 predictor_.get()); |
| 743 EXPECT_CALL(mock_observer, | 798 EXPECT_CALL(mock_observer, |
| 744 OnNavigationLearned( | 799 OnNavigationLearned( |
| 745 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 800 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 746 "http://www.google.com", | 801 "http://www.google.com", |
| 747 resources))); | 802 resources))); |
| 748 | 803 |
| 749 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 804 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 779 host_data.add_resources(), "http://google.com/script2.js", | 834 host_data.add_resources(), "http://google.com/script2.js", |
| 780 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 835 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 781 InitializeResourceData(host_data.add_resources(), | 836 InitializeResourceData(host_data.add_resources(), |
| 782 "http://google.com/style2.css", | 837 "http://google.com/style2.css", |
| 783 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, | 838 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, |
| 784 net::MEDIUM, false, false); | 839 net::MEDIUM, false, false); |
| 785 EXPECT_CALL(*mock_tables_.get(), | 840 EXPECT_CALL(*mock_tables_.get(), |
| 786 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 841 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 787 empty_redirect_data_)); | 842 empty_redirect_data_)); |
| 788 | 843 |
| 844 OriginData origin_data = CreateOriginData("www.google.com"); | |
| 845 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/", | |
| 846 1, 0, 0, 2., true, true); | |
| 847 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0, | |
| 848 1., false, true); | |
| 849 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(origin_data)); | |
| 850 | |
| 789 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 851 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 790 profile_->BlockUntilHistoryProcessesPendingRequests(); | 852 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 791 } | 853 } |
| 792 | 854 |
| 793 // Tests that a URL is deleted before another is added if the cache is full. | 855 // Tests that a URL is deleted before another is added if the cache is full. |
| 794 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { | 856 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { |
| 795 const int kVisitCount = 4; | 857 const int kVisitCount = 4; |
| 796 AddUrlToHistory("http://www.nike.com/", kVisitCount); | 858 AddUrlToHistory("http://www.nike.com/", kVisitCount); |
| 797 | 859 |
| 798 EXPECT_CALL(*mock_tables_.get(), | 860 EXPECT_CALL(*mock_tables_.get(), |
| 799 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 861 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 800 Pointee(ContainerEq(PrefetchDataMap())), | 862 Pointee(ContainerEq(PrefetchDataMap())), |
| 801 Pointee(ContainerEq(RedirectDataMap())), | 863 Pointee(ContainerEq(RedirectDataMap())), |
| 802 Pointee(ContainerEq(RedirectDataMap())), | 864 Pointee(ContainerEq(RedirectDataMap())), |
| 803 Pointee(ContainerEq(ManifestDataMap())))) | 865 Pointee(ContainerEq(ManifestDataMap())), |
| 866 Pointee(ContainerEq(OriginDataMap())))) | |
| 804 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 867 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 805 SetArgPointee<1>(test_host_data_))); | 868 SetArgPointee<1>(test_host_data_), |
| 869 SetArgPointee<5>(test_origin_data_))); | |
| 806 ResetPredictor(); | 870 ResetPredictor(); |
| 807 InitializePredictor(); | 871 InitializePredictor(); |
| 808 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 872 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 809 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 873 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 874 EXPECT_EQ(2U, predictor_->origin_table_cache_->size()); | |
| 810 | 875 |
| 811 URLRequestSummary main_frame = CreateURLRequestSummary( | 876 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 812 1, "http://www.nike.com", "http://www.nike.com", | 877 1, "http://www.nike.com", "http://www.nike.com", |
| 813 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 878 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 814 predictor_->RecordURLRequest(main_frame); | 879 predictor_->RecordURLRequest(main_frame); |
| 815 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 880 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 816 | 881 |
| 817 URLRequestSummary resource1 = CreateURLRequestSummary( | 882 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 818 1, "http://www.nike.com", "http://nike.com/style1.css", | 883 1, "http://www.nike.com", "http://nike.com/style1.css", |
| 819 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 884 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 830 kVisitCount, CreatePageRequestSummary( | 895 kVisitCount, CreatePageRequestSummary( |
| 831 "http://www.nike.com", "http://www.nike.com", | 896 "http://www.nike.com", "http://www.nike.com", |
| 832 {resource1, resource2}))); | 897 {resource1, resource2}))); |
| 833 | 898 |
| 834 EXPECT_CALL(*mock_tables_.get(), | 899 EXPECT_CALL(*mock_tables_.get(), |
| 835 DeleteSingleResourceDataPoint("http://www.google.com/", | 900 DeleteSingleResourceDataPoint("http://www.google.com/", |
| 836 PREFETCH_KEY_TYPE_URL)); | 901 PREFETCH_KEY_TYPE_URL)); |
| 837 EXPECT_CALL(*mock_tables_.get(), | 902 EXPECT_CALL(*mock_tables_.get(), |
| 838 DeleteSingleResourceDataPoint("www.facebook.com", | 903 DeleteSingleResourceDataPoint("www.facebook.com", |
| 839 PREFETCH_KEY_TYPE_HOST)); | 904 PREFETCH_KEY_TYPE_HOST)); |
| 905 EXPECT_CALL(*mock_tables_.get(), | |
| 906 DeleteOriginData(std::vector<std::string>({"google.com"}))); | |
| 840 | 907 |
| 841 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); | 908 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); |
| 842 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", | 909 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", |
| 843 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | 910 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 844 net::MEDIUM, false, false); | 911 net::MEDIUM, false, false); |
| 845 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", | 912 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", |
| 846 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, | 913 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, |
| 847 net::MEDIUM, false, false); | 914 net::MEDIUM, false, false); |
| 848 EXPECT_CALL(*mock_tables_.get(), | 915 EXPECT_CALL(*mock_tables_.get(), |
| 849 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, | 916 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, |
| 850 empty_redirect_data_)); | 917 empty_redirect_data_)); |
| 851 | 918 |
| 852 PrefetchData host_data = CreatePrefetchData("www.nike.com"); | 919 PrefetchData host_data = CreatePrefetchData("www.nike.com"); |
| 853 host_data.mutable_resources()->CopyFrom(url_data.resources()); | 920 host_data.mutable_resources()->CopyFrom(url_data.resources()); |
| 854 EXPECT_CALL(*mock_tables_.get(), | 921 EXPECT_CALL(*mock_tables_.get(), |
| 855 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 922 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 856 empty_redirect_data_)); | 923 empty_redirect_data_)); |
| 857 | 924 |
| 925 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(testing::_)); | |
| 926 | |
| 858 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 927 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 859 profile_->BlockUntilHistoryProcessesPendingRequests(); | 928 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 860 } | 929 } |
| 861 | 930 |
| 862 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { | 931 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { |
| 863 const int kVisitCount = 4; | 932 const int kVisitCount = 4; |
| 864 AddUrlToHistory("https://facebook.com/google", kVisitCount); | 933 AddUrlToHistory("https://facebook.com/google", kVisitCount); |
| 865 | 934 |
| 866 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); | 935 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); |
| 867 predictor_->RecordURLRequest(fb1); | 936 predictor_->RecordURLRequest(fb1); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 914 // the database cache. | 983 // the database cache. |
| 915 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { | 984 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { |
| 916 const int kVisitCount = 7; | 985 const int kVisitCount = 7; |
| 917 AddUrlToHistory("https://facebook.com/google", kVisitCount); | 986 AddUrlToHistory("https://facebook.com/google", kVisitCount); |
| 918 | 987 |
| 919 EXPECT_CALL(*mock_tables_.get(), | 988 EXPECT_CALL(*mock_tables_.get(), |
| 920 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 989 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 921 Pointee(ContainerEq(PrefetchDataMap())), | 990 Pointee(ContainerEq(PrefetchDataMap())), |
| 922 Pointee(ContainerEq(RedirectDataMap())), | 991 Pointee(ContainerEq(RedirectDataMap())), |
| 923 Pointee(ContainerEq(RedirectDataMap())), | 992 Pointee(ContainerEq(RedirectDataMap())), |
| 924 Pointee(ContainerEq(ManifestDataMap())))) | 993 Pointee(ContainerEq(ManifestDataMap())), |
| 994 Pointee(ContainerEq(OriginDataMap())))) | |
| 925 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), | 995 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), |
| 926 SetArgPointee<3>(test_host_redirect_data_))); | 996 SetArgPointee<3>(test_host_redirect_data_))); |
| 927 ResetPredictor(); | 997 ResetPredictor(); |
| 928 InitializePredictor(); | 998 InitializePredictor(); |
| 929 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); | 999 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); |
| 930 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); | 1000 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); |
| 931 | 1001 |
| 932 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); | 1002 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); |
| 933 predictor_->RecordURLRequest(fb1); | 1003 predictor_->RecordURLRequest(fb1); |
| 934 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 1004 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 | 1063 |
| 994 predictor_->OnManifestFetched("google.com", manifest); | 1064 predictor_->OnManifestFetched("google.com", manifest); |
| 995 } | 1065 } |
| 996 | 1066 |
| 997 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) { | 1067 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) { |
| 998 EXPECT_CALL(*mock_tables_.get(), | 1068 EXPECT_CALL(*mock_tables_.get(), |
| 999 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 1069 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 1000 Pointee(ContainerEq(PrefetchDataMap())), | 1070 Pointee(ContainerEq(PrefetchDataMap())), |
| 1001 Pointee(ContainerEq(RedirectDataMap())), | 1071 Pointee(ContainerEq(RedirectDataMap())), |
| 1002 Pointee(ContainerEq(RedirectDataMap())), | 1072 Pointee(ContainerEq(RedirectDataMap())), |
| 1003 Pointee(ContainerEq(ManifestDataMap())))) | 1073 Pointee(ContainerEq(ManifestDataMap())), |
| 1074 Pointee(ContainerEq(OriginDataMap())))) | |
| 1004 .WillOnce(SetArgPointee<4>(test_manifest_data_)); | 1075 .WillOnce(SetArgPointee<4>(test_manifest_data_)); |
| 1005 ResetPredictor(); | 1076 ResetPredictor(); |
| 1006 InitializePredictor(); | 1077 InitializePredictor(); |
| 1007 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); | 1078 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); |
| 1008 | 1079 |
| 1009 precache::PrecacheManifest manifest = CreateManifestData(1); | 1080 precache::PrecacheManifest manifest = CreateManifestData(1); |
| 1010 InitializePrecacheResource(manifest.add_resource(), | 1081 InitializePrecacheResource(manifest.add_resource(), |
| 1011 "http://google.com/image.jpg", 0.1); | 1082 "http://google.com/image.jpg", 0.1); |
| 1012 | 1083 |
| 1013 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest)); | 1084 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest)); |
| 1014 | 1085 |
| 1015 predictor_->OnManifestFetched("google.com", manifest); | 1086 predictor_->OnManifestFetched("google.com", manifest); |
| 1016 } | 1087 } |
| 1017 | 1088 |
| 1018 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) { | 1089 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) { |
| 1019 EXPECT_CALL(*mock_tables_.get(), | 1090 EXPECT_CALL(*mock_tables_.get(), |
| 1020 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 1091 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 1021 Pointee(ContainerEq(PrefetchDataMap())), | 1092 Pointee(ContainerEq(PrefetchDataMap())), |
| 1022 Pointee(ContainerEq(RedirectDataMap())), | 1093 Pointee(ContainerEq(RedirectDataMap())), |
| 1023 Pointee(ContainerEq(RedirectDataMap())), | 1094 Pointee(ContainerEq(RedirectDataMap())), |
| 1024 Pointee(ContainerEq(ManifestDataMap())))) | 1095 Pointee(ContainerEq(ManifestDataMap())), |
| 1096 Pointee(ContainerEq(OriginDataMap())))) | |
| 1025 .WillOnce(SetArgPointee<4>(test_manifest_data_)); | 1097 .WillOnce(SetArgPointee<4>(test_manifest_data_)); |
| 1026 ResetPredictor(); | 1098 ResetPredictor(); |
| 1027 InitializePredictor(); | 1099 InitializePredictor(); |
| 1028 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); | 1100 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); |
| 1029 | 1101 |
| 1030 precache::PrecacheManifest manifest = CreateManifestData(1); | 1102 precache::PrecacheManifest manifest = CreateManifestData(1); |
| 1031 InitializePrecacheResource(manifest.add_resource(), | 1103 InitializePrecacheResource(manifest.add_resource(), |
| 1032 "http://en.wikipedia.org/logo.png", 1.0); | 1104 "http://en.wikipedia.org/logo.png", 1.0); |
| 1033 | 1105 |
| 1034 EXPECT_CALL(*mock_tables_.get(), | 1106 EXPECT_CALL(*mock_tables_.get(), |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1753 predictor_->url_table_cache_->insert( | 1825 predictor_->url_table_cache_->insert( |
| 1754 std::make_pair(www_google_url.primary_key(), www_google_url)); | 1826 std::make_pair(www_google_url.primary_key(), www_google_url)); |
| 1755 | 1827 |
| 1756 urls.clear(); | 1828 urls.clear(); |
| 1757 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction)); | 1829 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction)); |
| 1758 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); | 1830 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); |
| 1759 } | 1831 } |
| 1760 | 1832 |
| 1761 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) { | 1833 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) { |
| 1762 using testing::_; | 1834 using testing::_; |
| 1763 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)); | 1835 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)) |
| 1836 .Times(testing::AtLeast(1)); | |
| 1837 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); | |
| 1764 | 1838 |
| 1765 // Fill the database with 3 resources: 1 useful, 2 useless. | 1839 // Fill the database with 3 resources: 1 useful, 2 useless. |
| 1766 const std::string main_frame_url = "http://google.com/?query=cats"; | 1840 const std::string main_frame_url = "http://google.com/?query=cats"; |
| 1767 PrefetchData google = CreatePrefetchData("google.com", 1); | 1841 PrefetchData google = CreatePrefetchData("google.com", 1); |
| 1768 | 1842 |
| 1769 const std::string script_url = "https://cdn.google.com/script.js"; | 1843 const std::string script_url = "https://cdn.google.com/script.js"; |
| 1770 InitializeResourceData(google.add_resources(), script_url, | 1844 InitializeResourceData(google.add_resources(), script_url, |
| 1771 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, | 1845 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, |
| 1772 net::MEDIUM, false, false); | 1846 net::MEDIUM, false, false); |
| 1773 InitializeResourceData(google.add_resources(), script_url + "foo", | 1847 InitializeResourceData(google.add_resources(), script_url + "foo", |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1860 predictor_->host_table_cache_->insert( | 1934 predictor_->host_table_cache_->insert( |
| 1861 std::make_pair(google.primary_key(), google)); | 1935 std::make_pair(google.primary_key(), google)); |
| 1862 | 1936 |
| 1863 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 1937 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); |
| 1864 predictor_->StopPrefetching(GURL(main_frame_url)); | 1938 predictor_->StopPrefetching(GURL(main_frame_url)); |
| 1865 histogram_tester_->ExpectTotalCount( | 1939 histogram_tester_->ExpectTotalCount( |
| 1866 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); | 1940 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); |
| 1867 } | 1941 } |
| 1868 | 1942 |
| 1869 } // namespace predictors | 1943 } // namespace predictors |
| OLD | NEW |