Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_unittest.cc

Issue 2796783004: predictors: Add origin learning. (Closed)
Patch Set: , Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor_test_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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
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
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
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
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 26 matching lines...) Expand all
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));
647 predictor_->RecordURLResponse(resources.back()); 680 predictor_->RecordURLResponse(resources.back());
648 681
682 auto no_store = CreateURLRequestSummary(
683 1, "http://www.google.com",
684 "http://static.google.com/style2-no-store.css",
685 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
686 no_store.is_no_store = true;
687 predictor_->RecordURLResponse(no_store);
688
689 auto redirected = CreateURLRequestSummary(
690 1, "http://www.google.com", "http://reader.google.com/style.css",
691 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
692 redirected.redirect_url = GURL("http://dev.null.google.com/style.css");
693
694 predictor_->RecordURLRedirect(redirected);
695 redirected.is_no_store = true;
696 redirected.request_url = redirected.redirect_url;
697 redirected.redirect_url = GURL();
698
699 predictor_->RecordURLResponse(redirected);
700
649 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 701 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(
650 predictor_.get()); 702 predictor_.get());
651 EXPECT_CALL(mock_observer, 703 EXPECT_CALL(mock_observer,
652 OnNavigationLearned( 704 OnNavigationLearned(
653 kVisitCount, CreatePageRequestSummary("http://www.google.com", 705 kVisitCount, CreatePageRequestSummary("http://www.google.com",
654 "http://www.google.com", 706 "http://www.google.com",
655 resources))); 707 resources)));
656 708
657 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 709 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
658 InitializeResourceData(url_data.add_resources(), 710 InitializeResourceData(url_data.add_resources(),
659 "http://google.com/style1.css", 711 "http://google.com/style1.css",
660 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, 712 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
661 net::MEDIUM, false, false); 713 net::MEDIUM, false, false);
662 InitializeResourceData( 714 InitializeResourceData(
663 url_data.add_resources(), "http://google.com/script1.js", 715 url_data.add_resources(), "http://google.com/script1.js",
664 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); 716 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false);
665 InitializeResourceData( 717 InitializeResourceData(
666 url_data.add_resources(), "http://google.com/script2.js", 718 url_data.add_resources(), "http://google.com/script2.js",
667 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); 719 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false);
668 InitializeResourceData(url_data.add_resources(), 720 InitializeResourceData(url_data.add_resources(),
669 "http://google.com/style2.css", 721 "http://google.com/style2.css",
670 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, 722 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0,
671 net::MEDIUM, false, false); 723 net::MEDIUM, false, false);
672 EXPECT_CALL(*mock_tables_.get(), 724 EXPECT_CALL(*mock_tables_.get(),
673 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, 725 UpdateData(url_data, empty_resource_data_, empty_redirect_data_,
674 empty_redirect_data_)); 726 empty_redirect_data_));
675 727
728 OriginData origin_data = CreateOriginData("www.google.com");
729 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/",
730 1, 0, 0, 2., true, true);
731 InitializeOriginStat(origin_data.add_origins(), "http://dev.null.google.com/",
732 1, 0, 0, 4., true, true);
733 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0,
734 1., false, true);
735 InitializeOriginStat(origin_data.add_origins(), "http://reader.google.com/",
736 1, 0, 0, 3., false, true);
737 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(origin_data));
738
676 PrefetchData host_data = CreatePrefetchData("www.google.com"); 739 PrefetchData host_data = CreatePrefetchData("www.google.com");
677 host_data.mutable_resources()->CopyFrom(url_data.resources()); 740 host_data.mutable_resources()->CopyFrom(url_data.resources());
678 EXPECT_CALL(*mock_tables_.get(), 741 EXPECT_CALL(*mock_tables_.get(),
679 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 742 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
680 empty_redirect_data_)); 743 empty_redirect_data_));
681 744
682 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 745 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
683 profile_->BlockUntilHistoryProcessesPendingRequests(); 746 profile_->BlockUntilHistoryProcessesPendingRequests();
684 } 747 }
685 748
686 // Tests that navigation is recorded correctly for URL already present in 749 // Tests that navigation is recorded correctly for URL already present in
687 // the database cache. 750 // the database cache.
688 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { 751 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
689 const int kVisitCount = 4; 752 const int kVisitCount = 4;
690 AddUrlToHistory("http://www.google.com", kVisitCount); 753 AddUrlToHistory("http://www.google.com", kVisitCount);
691 754
692 EXPECT_CALL(*mock_tables_.get(), 755 EXPECT_CALL(*mock_tables_.get(),
693 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 756 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
694 Pointee(ContainerEq(PrefetchDataMap())), 757 Pointee(ContainerEq(PrefetchDataMap())),
695 Pointee(ContainerEq(RedirectDataMap())), 758 Pointee(ContainerEq(RedirectDataMap())),
696 Pointee(ContainerEq(RedirectDataMap())), 759 Pointee(ContainerEq(RedirectDataMap())),
697 Pointee(ContainerEq(ManifestDataMap())))) 760 Pointee(ContainerEq(ManifestDataMap())),
761 Pointee(ContainerEq(OriginDataMap()))))
698 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 762 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
699 SetArgPointee<1>(test_host_data_))); 763 SetArgPointee<1>(test_host_data_)));
700 ResetPredictor(); 764 ResetPredictor();
701 InitializePredictor(); 765 InitializePredictor();
702 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); 766 EXPECT_EQ(3U, predictor_->url_table_cache_->size());
703 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); 767 EXPECT_EQ(2U, predictor_->host_table_cache_->size());
704 768
705 URLRequestSummary main_frame = CreateURLRequestSummary( 769 URLRequestSummary main_frame = CreateURLRequestSummary(
706 1, "http://www.google.com", "http://www.google.com", 770 1, "http://www.google.com", "http://www.google.com",
707 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); 771 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
(...skipping 22 matching lines...) Expand all
730 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 794 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
731 predictor_->RecordURLResponse(resources.back()); 795 predictor_->RecordURLResponse(resources.back());
732 resources.push_back(CreateURLRequestSummary( 796 resources.push_back(CreateURLRequestSummary(
733 1, "http://www.google.com", "http://google.com/image2.png", 797 1, "http://www.google.com", "http://google.com/image2.png",
734 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 798 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
735 predictor_->RecordURLResponse(resources.back()); 799 predictor_->RecordURLResponse(resources.back());
736 resources.push_back(CreateURLRequestSummary( 800 resources.push_back(CreateURLRequestSummary(
737 1, "http://www.google.com", "http://google.com/style2.css", 801 1, "http://www.google.com", "http://google.com/style2.css",
738 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); 802 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
739 predictor_->RecordURLResponse(resources.back()); 803 predictor_->RecordURLResponse(resources.back());
804 auto no_store = CreateURLRequestSummary(
805 1, "http://www.google.com",
806 "http://static.google.com/style2-no-store.css",
807 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
808 no_store.is_no_store = true;
809 predictor_->RecordURLResponse(no_store);
740 810
741 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 811 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(
742 predictor_.get()); 812 predictor_.get());
743 EXPECT_CALL(mock_observer, 813 EXPECT_CALL(mock_observer,
744 OnNavigationLearned( 814 OnNavigationLearned(
745 kVisitCount, CreatePageRequestSummary("http://www.google.com", 815 kVisitCount, CreatePageRequestSummary("http://www.google.com",
746 "http://www.google.com", 816 "http://www.google.com",
747 resources))); 817 resources)));
748 818
749 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 819 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
(...skipping 29 matching lines...) Expand all
779 host_data.add_resources(), "http://google.com/script2.js", 849 host_data.add_resources(), "http://google.com/script2.js",
780 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); 850 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false);
781 InitializeResourceData(host_data.add_resources(), 851 InitializeResourceData(host_data.add_resources(),
782 "http://google.com/style2.css", 852 "http://google.com/style2.css",
783 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, 853 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0,
784 net::MEDIUM, false, false); 854 net::MEDIUM, false, false);
785 EXPECT_CALL(*mock_tables_.get(), 855 EXPECT_CALL(*mock_tables_.get(),
786 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 856 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
787 empty_redirect_data_)); 857 empty_redirect_data_));
788 858
859 OriginData origin_data = CreateOriginData("www.google.com");
860 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/",
861 1, 0, 0, 2., true, true);
862 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0,
863 1., false, true);
864 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(origin_data));
865
789 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 866 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
790 profile_->BlockUntilHistoryProcessesPendingRequests(); 867 profile_->BlockUntilHistoryProcessesPendingRequests();
791 } 868 }
792 869
793 // Tests that a URL is deleted before another is added if the cache is full. 870 // Tests that a URL is deleted before another is added if the cache is full.
794 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { 871 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
795 const int kVisitCount = 4; 872 const int kVisitCount = 4;
796 AddUrlToHistory("http://www.nike.com/", kVisitCount); 873 AddUrlToHistory("http://www.nike.com/", kVisitCount);
797 874
798 EXPECT_CALL(*mock_tables_.get(), 875 EXPECT_CALL(*mock_tables_.get(),
799 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 876 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
800 Pointee(ContainerEq(PrefetchDataMap())), 877 Pointee(ContainerEq(PrefetchDataMap())),
801 Pointee(ContainerEq(RedirectDataMap())), 878 Pointee(ContainerEq(RedirectDataMap())),
802 Pointee(ContainerEq(RedirectDataMap())), 879 Pointee(ContainerEq(RedirectDataMap())),
803 Pointee(ContainerEq(ManifestDataMap())))) 880 Pointee(ContainerEq(ManifestDataMap())),
881 Pointee(ContainerEq(OriginDataMap()))))
804 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 882 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
805 SetArgPointee<1>(test_host_data_))); 883 SetArgPointee<1>(test_host_data_),
884 SetArgPointee<5>(test_origin_data_)));
806 ResetPredictor(); 885 ResetPredictor();
807 InitializePredictor(); 886 InitializePredictor();
808 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); 887 EXPECT_EQ(3U, predictor_->url_table_cache_->size());
809 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); 888 EXPECT_EQ(2U, predictor_->host_table_cache_->size());
889 EXPECT_EQ(2U, predictor_->origin_table_cache_->size());
810 890
811 URLRequestSummary main_frame = CreateURLRequestSummary( 891 URLRequestSummary main_frame = CreateURLRequestSummary(
812 1, "http://www.nike.com", "http://www.nike.com", 892 1, "http://www.nike.com", "http://www.nike.com",
813 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); 893 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
814 predictor_->RecordURLRequest(main_frame); 894 predictor_->RecordURLRequest(main_frame);
815 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 895 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
816 896
817 URLRequestSummary resource1 = CreateURLRequestSummary( 897 URLRequestSummary resource1 = CreateURLRequestSummary(
818 1, "http://www.nike.com", "http://nike.com/style1.css", 898 1, "http://www.nike.com", "http://nike.com/style1.css",
819 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); 899 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
(...skipping 10 matching lines...) Expand all
830 kVisitCount, CreatePageRequestSummary( 910 kVisitCount, CreatePageRequestSummary(
831 "http://www.nike.com", "http://www.nike.com", 911 "http://www.nike.com", "http://www.nike.com",
832 {resource1, resource2}))); 912 {resource1, resource2})));
833 913
834 EXPECT_CALL(*mock_tables_.get(), 914 EXPECT_CALL(*mock_tables_.get(),
835 DeleteSingleResourceDataPoint("http://www.google.com/", 915 DeleteSingleResourceDataPoint("http://www.google.com/",
836 PREFETCH_KEY_TYPE_URL)); 916 PREFETCH_KEY_TYPE_URL));
837 EXPECT_CALL(*mock_tables_.get(), 917 EXPECT_CALL(*mock_tables_.get(),
838 DeleteSingleResourceDataPoint("www.facebook.com", 918 DeleteSingleResourceDataPoint("www.facebook.com",
839 PREFETCH_KEY_TYPE_HOST)); 919 PREFETCH_KEY_TYPE_HOST));
920 EXPECT_CALL(*mock_tables_.get(),
921 DeleteOriginData(std::vector<std::string>({"google.com"})));
840 922
841 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); 923 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/");
842 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", 924 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css",
843 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, 925 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
844 net::MEDIUM, false, false); 926 net::MEDIUM, false, false);
845 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", 927 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png",
846 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, 928 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0,
847 net::MEDIUM, false, false); 929 net::MEDIUM, false, false);
848 EXPECT_CALL(*mock_tables_.get(), 930 EXPECT_CALL(*mock_tables_.get(),
849 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, 931 UpdateData(url_data, empty_resource_data_, empty_redirect_data_,
850 empty_redirect_data_)); 932 empty_redirect_data_));
851 933
852 PrefetchData host_data = CreatePrefetchData("www.nike.com"); 934 PrefetchData host_data = CreatePrefetchData("www.nike.com");
853 host_data.mutable_resources()->CopyFrom(url_data.resources()); 935 host_data.mutable_resources()->CopyFrom(url_data.resources());
854 EXPECT_CALL(*mock_tables_.get(), 936 EXPECT_CALL(*mock_tables_.get(),
855 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 937 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
856 empty_redirect_data_)); 938 empty_redirect_data_));
857 939
940 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(testing::_));
941
858 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 942 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
859 profile_->BlockUntilHistoryProcessesPendingRequests(); 943 profile_->BlockUntilHistoryProcessesPendingRequests();
860 } 944 }
861 945
862 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { 946 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) {
863 const int kVisitCount = 4; 947 const int kVisitCount = 4;
864 AddUrlToHistory("https://facebook.com/google", kVisitCount); 948 AddUrlToHistory("https://facebook.com/google", kVisitCount);
865 949
866 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); 950 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google");
867 predictor_->RecordURLRequest(fb1); 951 predictor_->RecordURLRequest(fb1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // the database cache. 998 // the database cache.
915 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { 999 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) {
916 const int kVisitCount = 7; 1000 const int kVisitCount = 7;
917 AddUrlToHistory("https://facebook.com/google", kVisitCount); 1001 AddUrlToHistory("https://facebook.com/google", kVisitCount);
918 1002
919 EXPECT_CALL(*mock_tables_.get(), 1003 EXPECT_CALL(*mock_tables_.get(),
920 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 1004 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
921 Pointee(ContainerEq(PrefetchDataMap())), 1005 Pointee(ContainerEq(PrefetchDataMap())),
922 Pointee(ContainerEq(RedirectDataMap())), 1006 Pointee(ContainerEq(RedirectDataMap())),
923 Pointee(ContainerEq(RedirectDataMap())), 1007 Pointee(ContainerEq(RedirectDataMap())),
924 Pointee(ContainerEq(ManifestDataMap())))) 1008 Pointee(ContainerEq(ManifestDataMap())),
1009 Pointee(ContainerEq(OriginDataMap()))))
925 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), 1010 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_),
926 SetArgPointee<3>(test_host_redirect_data_))); 1011 SetArgPointee<3>(test_host_redirect_data_)));
927 ResetPredictor(); 1012 ResetPredictor();
928 InitializePredictor(); 1013 InitializePredictor();
929 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); 1014 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size());
930 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); 1015 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size());
931 1016
932 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); 1017 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google");
933 predictor_->RecordURLRequest(fb1); 1018 predictor_->RecordURLRequest(fb1);
934 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 1019 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 1078
994 predictor_->OnManifestFetched("google.com", manifest); 1079 predictor_->OnManifestFetched("google.com", manifest);
995 } 1080 }
996 1081
997 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) { 1082 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) {
998 EXPECT_CALL(*mock_tables_.get(), 1083 EXPECT_CALL(*mock_tables_.get(),
999 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 1084 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
1000 Pointee(ContainerEq(PrefetchDataMap())), 1085 Pointee(ContainerEq(PrefetchDataMap())),
1001 Pointee(ContainerEq(RedirectDataMap())), 1086 Pointee(ContainerEq(RedirectDataMap())),
1002 Pointee(ContainerEq(RedirectDataMap())), 1087 Pointee(ContainerEq(RedirectDataMap())),
1003 Pointee(ContainerEq(ManifestDataMap())))) 1088 Pointee(ContainerEq(ManifestDataMap())),
1089 Pointee(ContainerEq(OriginDataMap()))))
1004 .WillOnce(SetArgPointee<4>(test_manifest_data_)); 1090 .WillOnce(SetArgPointee<4>(test_manifest_data_));
1005 ResetPredictor(); 1091 ResetPredictor();
1006 InitializePredictor(); 1092 InitializePredictor();
1007 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); 1093 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size());
1008 1094
1009 precache::PrecacheManifest manifest = CreateManifestData(1); 1095 precache::PrecacheManifest manifest = CreateManifestData(1);
1010 InitializePrecacheResource(manifest.add_resource(), 1096 InitializePrecacheResource(manifest.add_resource(),
1011 "http://google.com/image.jpg", 0.1); 1097 "http://google.com/image.jpg", 0.1);
1012 1098
1013 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest)); 1099 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest));
1014 1100
1015 predictor_->OnManifestFetched("google.com", manifest); 1101 predictor_->OnManifestFetched("google.com", manifest);
1016 } 1102 }
1017 1103
1018 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) { 1104 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) {
1019 EXPECT_CALL(*mock_tables_.get(), 1105 EXPECT_CALL(*mock_tables_.get(),
1020 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 1106 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
1021 Pointee(ContainerEq(PrefetchDataMap())), 1107 Pointee(ContainerEq(PrefetchDataMap())),
1022 Pointee(ContainerEq(RedirectDataMap())), 1108 Pointee(ContainerEq(RedirectDataMap())),
1023 Pointee(ContainerEq(RedirectDataMap())), 1109 Pointee(ContainerEq(RedirectDataMap())),
1024 Pointee(ContainerEq(ManifestDataMap())))) 1110 Pointee(ContainerEq(ManifestDataMap())),
1111 Pointee(ContainerEq(OriginDataMap()))))
1025 .WillOnce(SetArgPointee<4>(test_manifest_data_)); 1112 .WillOnce(SetArgPointee<4>(test_manifest_data_));
1026 ResetPredictor(); 1113 ResetPredictor();
1027 InitializePredictor(); 1114 InitializePredictor();
1028 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); 1115 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size());
1029 1116
1030 precache::PrecacheManifest manifest = CreateManifestData(1); 1117 precache::PrecacheManifest manifest = CreateManifestData(1);
1031 InitializePrecacheResource(manifest.add_resource(), 1118 InitializePrecacheResource(manifest.add_resource(),
1032 "http://en.wikipedia.org/logo.png", 1.0); 1119 "http://en.wikipedia.org/logo.png", 1.0);
1033 1120
1034 EXPECT_CALL(*mock_tables_.get(), 1121 EXPECT_CALL(*mock_tables_.get(),
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 predictor_->url_table_cache_->insert( 1840 predictor_->url_table_cache_->insert(
1754 std::make_pair(www_google_url.primary_key(), www_google_url)); 1841 std::make_pair(www_google_url.primary_key(), www_google_url));
1755 1842
1756 urls.clear(); 1843 urls.clear();
1757 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction)); 1844 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
1758 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); 1845 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url)));
1759 } 1846 }
1760 1847
1761 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) { 1848 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) {
1762 using testing::_; 1849 using testing::_;
1763 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)); 1850 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _))
1851 .Times(testing::AtLeast(1));
1852 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_));
1764 1853
1765 // Fill the database with 3 resources: 1 useful, 2 useless. 1854 // Fill the database with 3 resources: 1 useful, 2 useless.
1766 const std::string main_frame_url = "http://google.com/?query=cats"; 1855 const std::string main_frame_url = "http://google.com/?query=cats";
1767 PrefetchData google = CreatePrefetchData("google.com", 1); 1856 PrefetchData google = CreatePrefetchData("google.com", 1);
1768 1857
1769 const std::string script_url = "https://cdn.google.com/script.js"; 1858 const std::string script_url = "https://cdn.google.com/script.js";
1770 InitializeResourceData(google.add_resources(), script_url, 1859 InitializeResourceData(google.add_resources(), script_url,
1771 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, 1860 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1,
1772 net::MEDIUM, false, false); 1861 net::MEDIUM, false, false);
1773 InitializeResourceData(google.add_resources(), script_url + "foo", 1862 InitializeResourceData(google.add_resources(), script_url + "foo",
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 predictor_->host_table_cache_->insert( 1949 predictor_->host_table_cache_->insert(
1861 std::make_pair(google.primary_key(), google)); 1950 std::make_pair(google.primary_key(), google));
1862 1951
1863 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); 1952 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL);
1864 predictor_->StopPrefetching(GURL(main_frame_url)); 1953 predictor_->StopPrefetching(GURL(main_frame_url));
1865 histogram_tester_->ExpectTotalCount( 1954 histogram_tester_->ExpectTotalCount(
1866 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); 1955 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1);
1867 } 1956 }
1868 1957
1869 } // namespace predictors 1958 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor_test_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698