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

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

Issue 2796783004: predictors: Add origin learning. (Closed)
Patch Set: Advancing our amazing database version number. 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
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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 private: 125 private:
125 net::HttpResponseInfo response_info_; 126 net::HttpResponseInfo response_info_;
126 std::string mime_type_; 127 std::string mime_type_;
127 }; 128 };
128 129
129 class MockResourcePrefetchPredictorTables 130 class MockResourcePrefetchPredictorTables
130 : public ResourcePrefetchPredictorTables { 131 : public ResourcePrefetchPredictorTables {
131 public: 132 public:
132 MockResourcePrefetchPredictorTables() { } 133 MockResourcePrefetchPredictorTables() { }
133 134
134 MOCK_METHOD5(GetAllData, 135 MOCK_METHOD6(GetAllData,
135 void(PrefetchDataMap* url_data_map, 136 void(PrefetchDataMap* url_data_map,
136 PrefetchDataMap* host_data_map, 137 PrefetchDataMap* host_data_map,
137 RedirectDataMap* url_redirect_data_map, 138 RedirectDataMap* url_redirect_data_map,
138 RedirectDataMap* host_redirect_data_map, 139 RedirectDataMap* host_redirect_data_map,
139 ManifestDataMap* manifest_data_map)); 140 ManifestDataMap* manifest_data_map,
141 OriginDataMap* origin_data_map));
140 MOCK_METHOD4(UpdateData, 142 MOCK_METHOD4(UpdateData,
141 void(const PrefetchData& url_data, 143 void(const PrefetchData& url_data,
142 const PrefetchData& host_data, 144 const PrefetchData& host_data,
143 const RedirectData& url_redirect_data, 145 const RedirectData& url_redirect_data,
144 const RedirectData& host_redirect_data)); 146 const RedirectData& host_redirect_data));
145 MOCK_METHOD2(UpdateManifestData, 147 MOCK_METHOD2(UpdateManifestData,
146 void(const std::string& host, 148 void(const std::string& host,
147 const precache::PrecacheManifest& manifest_data)); 149 const precache::PrecacheManifest& manifest_data));
150 MOCK_METHOD2(UpdateOriginData,
151 void(const std::string& host, const OriginData& origin_data));
148 MOCK_METHOD2(DeleteResourceData, 152 MOCK_METHOD2(DeleteResourceData,
149 void(const std::vector<std::string>& urls, 153 void(const std::vector<std::string>& urls,
150 const std::vector<std::string>& hosts)); 154 const std::vector<std::string>& hosts));
155 MOCK_METHOD1(DeleteOriginData, void(const std::vector<std::string>& hosts));
151 MOCK_METHOD2(DeleteSingleResourceDataPoint, 156 MOCK_METHOD2(DeleteSingleResourceDataPoint,
152 void(const std::string& key, PrefetchKeyType key_type)); 157 void(const std::string& key, PrefetchKeyType key_type));
153 MOCK_METHOD2(DeleteRedirectData, 158 MOCK_METHOD2(DeleteRedirectData,
154 void(const std::vector<std::string>& urls, 159 void(const std::vector<std::string>& urls,
155 const std::vector<std::string>& hosts)); 160 const std::vector<std::string>& hosts));
156 MOCK_METHOD2(DeleteSingleRedirectDataPoint, 161 MOCK_METHOD2(DeleteSingleRedirectDataPoint,
157 void(const std::string& key, PrefetchKeyType key_type)); 162 void(const std::string& key, PrefetchKeyType key_type));
158 MOCK_METHOD1(DeleteManifestData, void(const std::vector<std::string>& hosts)); 163 MOCK_METHOD1(DeleteManifestData, void(const std::vector<std::string>& hosts));
159 MOCK_METHOD0(DeleteAllData, void()); 164 MOCK_METHOD0(DeleteAllData, void());
160 165
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 236
232 void ResetPredictor() { 237 void ResetPredictor() {
233 ResourcePrefetchPredictorConfig config; 238 ResourcePrefetchPredictorConfig config;
234 config.max_urls_to_track = 3; 239 config.max_urls_to_track = 3;
235 config.max_hosts_to_track = 2; 240 config.max_hosts_to_track = 2;
236 config.min_url_visit_count = 2; 241 config.min_url_visit_count = 2;
237 config.max_resources_per_entry = 4; 242 config.max_resources_per_entry = 4;
238 config.max_consecutive_misses = 2; 243 config.max_consecutive_misses = 2;
239 config.min_resource_confidence_to_trigger_prefetch = 0.5; 244 config.min_resource_confidence_to_trigger_prefetch = 0.5;
240 config.is_url_learning_enabled = true; 245 config.is_url_learning_enabled = true;
246 config.is_origin_prediction_enabled = true;
241 247
242 config.mode |= ResourcePrefetchPredictorConfig::LEARNING; 248 config.mode |= ResourcePrefetchPredictorConfig::LEARNING;
243 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get())); 249 predictor_.reset(new ResourcePrefetchPredictor(config, profile_.get()));
244 predictor_->set_mock_tables(mock_tables_); 250 predictor_->set_mock_tables(mock_tables_);
245 } 251 }
246 252
247 void InitializeSampleData(); 253 void InitializeSampleData();
248 void TestRedirectStatusHistogram( 254 void TestRedirectStatusHistogram(
249 const std::string& predictor_initial_key, 255 const std::string& predictor_initial_key,
250 const std::string& predictor_key, 256 const std::string& predictor_key,
251 const std::string& navigation_initial_url, 257 const std::string& navigation_initial_url,
252 const std::string& navigation_url, 258 const std::string& navigation_url,
253 ResourcePrefetchPredictor::RedirectStatus expected_status); 259 ResourcePrefetchPredictor::RedirectStatus expected_status);
254 260
255 content::TestBrowserThreadBundle thread_bundle_; 261 content::TestBrowserThreadBundle thread_bundle_;
256 std::unique_ptr<TestingProfile> profile_; 262 std::unique_ptr<TestingProfile> profile_;
257 net::TestURLRequestContext url_request_context_; 263 net::TestURLRequestContext url_request_context_;
258 264
259 std::unique_ptr<ResourcePrefetchPredictor> predictor_; 265 std::unique_ptr<ResourcePrefetchPredictor> predictor_;
260 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_; 266 scoped_refptr<StrictMock<MockResourcePrefetchPredictorTables>> mock_tables_;
261 267
262 PrefetchDataMap test_url_data_; 268 PrefetchDataMap test_url_data_;
263 PrefetchDataMap test_host_data_; 269 PrefetchDataMap test_host_data_;
264 RedirectDataMap test_url_redirect_data_; 270 RedirectDataMap test_url_redirect_data_;
265 RedirectDataMap test_host_redirect_data_; 271 RedirectDataMap test_host_redirect_data_;
266 ManifestDataMap test_manifest_data_; 272 ManifestDataMap test_manifest_data_;
273 OriginDataMap test_origin_data_;
267 PrefetchData empty_resource_data_; 274 PrefetchData empty_resource_data_;
268 RedirectData empty_redirect_data_; 275 RedirectData empty_redirect_data_;
269 276
270 MockURLRequestJobFactory url_request_job_factory_; 277 MockURLRequestJobFactory url_request_job_factory_;
271 EmptyURLRequestDelegate url_request_delegate_; 278 EmptyURLRequestDelegate url_request_delegate_;
272 279
273 std::unique_ptr<base::HistogramTester> histogram_tester_; 280 std::unique_ptr<base::HistogramTester> histogram_tester_;
274 }; 281 };
275 282
276 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest() 283 ResourcePrefetchPredictorTest::ResourcePrefetchPredictorTest()
(...skipping 17 matching lines...) Expand all
294 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS)); 301 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS));
295 // Initialize the predictor with empty data. 302 // Initialize the predictor with empty data.
296 ResetPredictor(); 303 ResetPredictor();
297 EXPECT_EQ(predictor_->initialization_state_, 304 EXPECT_EQ(predictor_->initialization_state_,
298 ResourcePrefetchPredictor::NOT_INITIALIZED); 305 ResourcePrefetchPredictor::NOT_INITIALIZED);
299 EXPECT_CALL(*mock_tables_.get(), 306 EXPECT_CALL(*mock_tables_.get(),
300 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 307 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
301 Pointee(ContainerEq(PrefetchDataMap())), 308 Pointee(ContainerEq(PrefetchDataMap())),
302 Pointee(ContainerEq(RedirectDataMap())), 309 Pointee(ContainerEq(RedirectDataMap())),
303 Pointee(ContainerEq(RedirectDataMap())), 310 Pointee(ContainerEq(RedirectDataMap())),
304 Pointee(ContainerEq(ManifestDataMap())))); 311 Pointee(ContainerEq(ManifestDataMap())),
312 Pointee(ContainerEq(OriginDataMap()))));
305 InitializePredictor(); 313 InitializePredictor();
306 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); 314 EXPECT_TRUE(predictor_->inflight_navigations_.empty());
307 EXPECT_EQ(predictor_->initialization_state_, 315 EXPECT_EQ(predictor_->initialization_state_,
308 ResourcePrefetchPredictor::INITIALIZED); 316 ResourcePrefetchPredictor::INITIALIZED);
309 317
310 url_request_context_.set_job_factory(&url_request_job_factory_); 318 url_request_context_.set_job_factory(&url_request_job_factory_);
311 319
312 histogram_tester_.reset(new base::HistogramTester()); 320 histogram_tester_.reset(new base::HistogramTester());
313 } 321 }
314 322
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 InitializePrecacheResource(google.add_resource(), 444 InitializePrecacheResource(google.add_resource(),
437 "http://static.google.com/style.css", 0.333); 445 "http://static.google.com/style.css", 0.333);
438 446
439 precache::PrecacheManifest facebook = CreateManifestData(12); 447 precache::PrecacheManifest facebook = CreateManifestData(12);
440 InitializePrecacheResource(facebook.add_resource(), 448 InitializePrecacheResource(facebook.add_resource(),
441 "http://fb.com/static.css", 0.99); 449 "http://fb.com/static.css", 0.99);
442 450
443 test_manifest_data_.insert(std::make_pair("google.com", google)); 451 test_manifest_data_.insert(std::make_pair("google.com", google));
444 test_manifest_data_.insert(std::make_pair("facebook.com", facebook)); 452 test_manifest_data_.insert(std::make_pair("facebook.com", facebook));
445 } 453 }
454
455 { // Origin data.
456 OriginData google = CreateOriginData("google.com", 12);
457 InitializeOriginStat(google.add_origins(), "https://static.google.com", 12,
458 0, 0, 3., false, true);
459 InitializeOriginStat(google.add_origins(), "https://cats.google.com", 12, 0,
460 0, 5., true, true);
461 test_origin_data_.insert({"google.com", google});
462
463 OriginData twitter = CreateOriginData("twitter.com", 42);
464 InitializeOriginStat(twitter.add_origins(), "https://static.twitter.com",
465 12, 0, 0, 3., false, true);
466 InitializeOriginStat(twitter.add_origins(), "https://random.140chars.com",
467 12, 0, 0, 3., false, true);
468 test_origin_data_.insert({"twitter.com", twitter});
469 }
446 } 470 }
447 471
448 void ResourcePrefetchPredictorTest::TestRedirectStatusHistogram( 472 void ResourcePrefetchPredictorTest::TestRedirectStatusHistogram(
449 const std::string& predictor_initial_key, 473 const std::string& predictor_initial_key,
450 const std::string& predictor_key, 474 const std::string& predictor_key,
451 const std::string& navigation_initial_url, 475 const std::string& navigation_initial_url,
452 const std::string& navigation_url, 476 const std::string& navigation_url,
453 ResourcePrefetchPredictor::RedirectStatus expected_status) { 477 ResourcePrefetchPredictor::RedirectStatus expected_status) {
454 // Database initialization. 478 // Database initialization.
455 const std::string& script_url = "https://cdn.google.com/script.js"; 479 const std::string& script_url = "https://cdn.google.com/script.js";
(...skipping 10 matching lines...) Expand all
466 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10, 490 InitializeRedirectStat(redirect.add_redirect_endpoints(), predictor_key, 10,
467 0, 0); 491 0, 0);
468 predictor_->host_redirect_table_cache_->insert( 492 predictor_->host_redirect_table_cache_->insert(
469 std::make_pair(redirect.primary_key(), redirect)); 493 std::make_pair(redirect.primary_key(), redirect));
470 } 494 }
471 495
472 // Navigation simulation. 496 // Navigation simulation.
473 using testing::_; 497 using testing::_;
474 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)) 498 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _))
475 .Times(testing::AtLeast(1)); 499 .Times(testing::AtLeast(1));
500 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_, _))
501 .Times(testing::AtLeast(1));
alexilin 2017/04/10 14:58:28 nit: I suppose it should be called exactly once. G
Benoit L 2017/04/11 09:04:05 Done.
502
476 URLRequestSummary initial = 503 URLRequestSummary initial =
477 CreateURLRequestSummary(1, navigation_initial_url); 504 CreateURLRequestSummary(1, navigation_initial_url);
478 predictor_->RecordURLRequest(initial); 505 predictor_->RecordURLRequest(initial);
479 506
480 if (navigation_initial_url != navigation_url) { 507 if (navigation_initial_url != navigation_url) {
481 URLRequestSummary redirect = 508 URLRequestSummary redirect =
482 CreateRedirectRequestSummary(1, navigation_initial_url, navigation_url); 509 CreateRedirectRequestSummary(1, navigation_initial_url, navigation_url);
483 predictor_->RecordURLRedirect(redirect); 510 predictor_->RecordURLRedirect(redirect);
484 } 511 }
485 NavigationID navigation_id = CreateNavigationID(1, navigation_url); 512 NavigationID navigation_id = CreateNavigationID(1, navigation_url);
(...skipping 21 matching lines...) Expand all
507 static_cast<int>(ResourceData_Priority_REQUEST_PRIORITY_HIGHEST), 534 static_cast<int>(ResourceData_Priority_REQUEST_PRIORITY_HIGHEST),
508 "Database/Net priority mismatch: Maximum"); 535 "Database/Net priority mismatch: Maximum");
509 536
510 // Tests that the predictor initializes correctly without any data. 537 // Tests that the predictor initializes correctly without any data.
511 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) { 538 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeEmpty) {
512 EXPECT_TRUE(predictor_->url_table_cache_->empty()); 539 EXPECT_TRUE(predictor_->url_table_cache_->empty());
513 EXPECT_TRUE(predictor_->host_table_cache_->empty()); 540 EXPECT_TRUE(predictor_->host_table_cache_->empty());
514 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty()); 541 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty());
515 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty()); 542 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty());
516 EXPECT_TRUE(predictor_->manifest_table_cache_->empty()); 543 EXPECT_TRUE(predictor_->manifest_table_cache_->empty());
544 EXPECT_TRUE(predictor_->origin_table_cache_->empty());
517 } 545 }
518 546
519 // Tests that the history and the db tables data are loaded correctly. 547 // Tests that the history and the db tables data are loaded correctly.
520 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) { 548 TEST_F(ResourcePrefetchPredictorTest, LazilyInitializeWithData) {
521 AddUrlToHistory("http://www.google.com/", 4); 549 AddUrlToHistory("http://www.google.com/", 4);
522 AddUrlToHistory("http://www.yahoo.com/", 2); 550 AddUrlToHistory("http://www.yahoo.com/", 2);
523 551
524 EXPECT_CALL(*mock_tables_.get(), 552 EXPECT_CALL(*mock_tables_.get(),
525 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 553 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
526 Pointee(ContainerEq(PrefetchDataMap())), 554 Pointee(ContainerEq(PrefetchDataMap())),
527 Pointee(ContainerEq(RedirectDataMap())), 555 Pointee(ContainerEq(RedirectDataMap())),
528 Pointee(ContainerEq(RedirectDataMap())), 556 Pointee(ContainerEq(RedirectDataMap())),
529 Pointee(ContainerEq(ManifestDataMap())))) 557 Pointee(ContainerEq(ManifestDataMap())),
558 Pointee(ContainerEq(OriginDataMap()))))
530 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 559 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
531 SetArgPointee<1>(test_host_data_), 560 SetArgPointee<1>(test_host_data_),
532 SetArgPointee<2>(test_url_redirect_data_), 561 SetArgPointee<2>(test_url_redirect_data_),
533 SetArgPointee<3>(test_host_redirect_data_), 562 SetArgPointee<3>(test_host_redirect_data_),
534 SetArgPointee<4>(test_manifest_data_))); 563 SetArgPointee<4>(test_manifest_data_),
564 SetArgPointee<5>(test_origin_data_)));
535 565
536 ResetPredictor(); 566 ResetPredictor();
537 InitializePredictor(); 567 InitializePredictor();
538 568
539 // Test that the internal variables correctly initialized. 569 // Test that the internal variables correctly initialized.
540 EXPECT_EQ(predictor_->initialization_state_, 570 EXPECT_EQ(predictor_->initialization_state_,
541 ResourcePrefetchPredictor::INITIALIZED); 571 ResourcePrefetchPredictor::INITIALIZED);
542 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); 572 EXPECT_TRUE(predictor_->inflight_navigations_.empty());
543 573
544 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); 574 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_);
545 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); 575 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_);
546 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); 576 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_);
547 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); 577 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_);
548 EXPECT_EQ(test_manifest_data_, *predictor_->manifest_table_cache_); 578 EXPECT_EQ(test_manifest_data_, *predictor_->manifest_table_cache_);
579 EXPECT_EQ(test_origin_data_, *predictor_->origin_table_cache_);
549 } 580 }
550 581
551 // Single navigation but history count is low, so should not record. 582 // Single navigation but history count is low, so should not record.
552 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { 583 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) {
553 const int kVisitCount = 1; 584 const int kVisitCount = 1;
554 AddUrlToHistory("https://www.google.com", kVisitCount); 585 AddUrlToHistory("https://www.google.com", kVisitCount);
555 586
556 URLRequestSummary main_frame = 587 URLRequestSummary main_frame =
557 CreateURLRequestSummary(1, "http://www.google.com"); 588 CreateURLRequestSummary(1, "http://www.google.com");
558 predictor_->RecordURLRequest(main_frame); 589 predictor_->RecordURLRequest(main_frame);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 net::MEDIUM, false, false); 625 net::MEDIUM, false, false);
595 InitializeResourceData( 626 InitializeResourceData(
596 host_data.add_resources(), "https://google.com/script1.js", 627 host_data.add_resources(), "https://google.com/script1.js",
597 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); 628 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false);
598 InitializeResourceData( 629 InitializeResourceData(
599 host_data.add_resources(), "https://google.com/script2.js", 630 host_data.add_resources(), "https://google.com/script2.js",
600 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); 631 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false);
601 EXPECT_CALL(*mock_tables_.get(), 632 EXPECT_CALL(*mock_tables_.get(),
602 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 633 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
603 empty_redirect_data_)); 634 empty_redirect_data_));
635 OriginData origin_data = CreateOriginData("www.google.com");
636 InitializeOriginStat(origin_data.add_origins(), "https://google.com/", 1, 0,
637 0, 1., false, true);
638 EXPECT_CALL(*mock_tables_.get(),
639 UpdateOriginData("www.google.com", origin_data));
604 640
605 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 641 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
606 profile_->BlockUntilHistoryProcessesPendingRequests(); 642 profile_->BlockUntilHistoryProcessesPendingRequests();
607 } 643 }
608 644
609 // Single navigation that will be recorded. Will check for duplicate 645 // Single navigation that will be recorded. Will check for duplicate
610 // resources and also for number of resources saved. 646 // resources and also for number of resources saved.
611 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { 647 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) {
612 const int kVisitCount = 4; 648 const int kVisitCount = 4;
613 AddUrlToHistory("http://www.google.com", kVisitCount); 649 AddUrlToHistory("http://www.google.com", kVisitCount);
(...skipping 24 matching lines...) Expand all
638 1, "http://www.google.com", "http://google.com/image1.png", 674 1, "http://www.google.com", "http://google.com/image1.png",
639 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 675 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
640 predictor_->RecordURLResponse(resources.back()); 676 predictor_->RecordURLResponse(resources.back());
641 resources.push_back(CreateURLRequestSummary( 677 resources.push_back(CreateURLRequestSummary(
642 1, "http://www.google.com", "http://google.com/image2.png", 678 1, "http://www.google.com", "http://google.com/image2.png",
643 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 679 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
644 predictor_->RecordURLResponse(resources.back()); 680 predictor_->RecordURLResponse(resources.back());
645 resources.push_back(CreateURLRequestSummary( 681 resources.push_back(CreateURLRequestSummary(
646 1, "http://www.google.com", "http://google.com/style2.css", 682 1, "http://www.google.com", "http://google.com/style2.css",
647 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); 683 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
684
685 auto no_store = CreateURLRequestSummary(
686 1, "http://www.google.com",
687 "http://static.google.com/style2-no-store.css",
688 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
689 no_store.is_no_store = true;
690 predictor_->RecordURLResponse(no_store);
691
648 predictor_->RecordURLResponse(resources.back()); 692 predictor_->RecordURLResponse(resources.back());
649 693
650 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 694 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(
651 predictor_.get()); 695 predictor_.get());
652 EXPECT_CALL(mock_observer, 696 EXPECT_CALL(mock_observer,
653 OnNavigationLearned( 697 OnNavigationLearned(
654 kVisitCount, CreatePageRequestSummary("http://www.google.com", 698 kVisitCount, CreatePageRequestSummary("http://www.google.com",
655 "http://www.google.com", 699 "http://www.google.com",
656 resources))); 700 resources)));
657 701
658 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 702 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
659 InitializeResourceData(url_data.add_resources(), 703 InitializeResourceData(url_data.add_resources(),
660 "http://google.com/style1.css", 704 "http://google.com/style1.css",
661 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, 705 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
662 net::MEDIUM, false, false); 706 net::MEDIUM, false, false);
663 InitializeResourceData( 707 InitializeResourceData(
664 url_data.add_resources(), "http://google.com/script1.js", 708 url_data.add_resources(), "http://google.com/script1.js",
665 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); 709 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false);
666 InitializeResourceData( 710 InitializeResourceData(
667 url_data.add_resources(), "http://google.com/script2.js", 711 url_data.add_resources(), "http://google.com/script2.js",
668 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); 712 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false);
669 InitializeResourceData(url_data.add_resources(), 713 InitializeResourceData(url_data.add_resources(),
670 "http://google.com/style2.css", 714 "http://google.com/style2.css",
671 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, 715 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0,
672 net::MEDIUM, false, false); 716 net::MEDIUM, false, false);
673 EXPECT_CALL(*mock_tables_.get(), 717 EXPECT_CALL(*mock_tables_.get(),
674 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, 718 UpdateData(url_data, empty_resource_data_, empty_redirect_data_,
675 empty_redirect_data_)); 719 empty_redirect_data_));
676 720
721 OriginData origin_data = CreateOriginData("www.google.com");
722 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/",
723 1, 0, 0, 2., true, true);
724 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0,
725 1., false, true);
726 EXPECT_CALL(*mock_tables_.get(),
727 UpdateOriginData("www.google.com", origin_data));
728
677 PrefetchData host_data = CreatePrefetchData("www.google.com"); 729 PrefetchData host_data = CreatePrefetchData("www.google.com");
678 host_data.mutable_resources()->CopyFrom(url_data.resources()); 730 host_data.mutable_resources()->CopyFrom(url_data.resources());
679 EXPECT_CALL(*mock_tables_.get(), 731 EXPECT_CALL(*mock_tables_.get(),
680 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 732 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
681 empty_redirect_data_)); 733 empty_redirect_data_));
682 734
683 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 735 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
684 profile_->BlockUntilHistoryProcessesPendingRequests(); 736 profile_->BlockUntilHistoryProcessesPendingRequests();
685 } 737 }
686 738
687 // Tests that navigation is recorded correctly for URL already present in 739 // Tests that navigation is recorded correctly for URL already present in
688 // the database cache. 740 // the database cache.
689 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { 741 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) {
690 const int kVisitCount = 4; 742 const int kVisitCount = 4;
691 AddUrlToHistory("http://www.google.com", kVisitCount); 743 AddUrlToHistory("http://www.google.com", kVisitCount);
692 744
693 EXPECT_CALL(*mock_tables_.get(), 745 EXPECT_CALL(*mock_tables_.get(),
694 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 746 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
695 Pointee(ContainerEq(PrefetchDataMap())), 747 Pointee(ContainerEq(PrefetchDataMap())),
696 Pointee(ContainerEq(RedirectDataMap())), 748 Pointee(ContainerEq(RedirectDataMap())),
697 Pointee(ContainerEq(RedirectDataMap())), 749 Pointee(ContainerEq(RedirectDataMap())),
698 Pointee(ContainerEq(ManifestDataMap())))) 750 Pointee(ContainerEq(ManifestDataMap())),
751 Pointee(ContainerEq(OriginDataMap()))))
699 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 752 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
700 SetArgPointee<1>(test_host_data_))); 753 SetArgPointee<1>(test_host_data_)));
701 ResetPredictor(); 754 ResetPredictor();
702 InitializePredictor(); 755 InitializePredictor();
703 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); 756 EXPECT_EQ(3U, predictor_->url_table_cache_->size());
704 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); 757 EXPECT_EQ(2U, predictor_->host_table_cache_->size());
705 758
706 URLRequestSummary main_frame = CreateURLRequestSummary( 759 URLRequestSummary main_frame = CreateURLRequestSummary(
707 1, "http://www.google.com", "http://www.google.com", 760 1, "http://www.google.com", "http://www.google.com",
708 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); 761 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
(...skipping 22 matching lines...) Expand all
731 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 784 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
732 predictor_->RecordURLResponse(resources.back()); 785 predictor_->RecordURLResponse(resources.back());
733 resources.push_back(CreateURLRequestSummary( 786 resources.push_back(CreateURLRequestSummary(
734 1, "http://www.google.com", "http://google.com/image2.png", 787 1, "http://www.google.com", "http://google.com/image2.png",
735 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); 788 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false));
736 predictor_->RecordURLResponse(resources.back()); 789 predictor_->RecordURLResponse(resources.back());
737 resources.push_back(CreateURLRequestSummary( 790 resources.push_back(CreateURLRequestSummary(
738 1, "http://www.google.com", "http://google.com/style2.css", 791 1, "http://www.google.com", "http://google.com/style2.css",
739 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); 792 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true));
740 predictor_->RecordURLResponse(resources.back()); 793 predictor_->RecordURLResponse(resources.back());
794 auto no_store = CreateURLRequestSummary(
795 1, "http://www.google.com",
796 "http://static.google.com/style2-no-store.css",
797 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true);
798 no_store.is_no_store = true;
799 predictor_->RecordURLResponse(no_store);
741 800
742 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( 801 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer(
743 predictor_.get()); 802 predictor_.get());
744 EXPECT_CALL(mock_observer, 803 EXPECT_CALL(mock_observer,
745 OnNavigationLearned( 804 OnNavigationLearned(
746 kVisitCount, CreatePageRequestSummary("http://www.google.com", 805 kVisitCount, CreatePageRequestSummary("http://www.google.com",
747 "http://www.google.com", 806 "http://www.google.com",
748 resources))); 807 resources)));
749 808
750 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); 809 PrefetchData url_data = CreatePrefetchData("http://www.google.com/");
(...skipping 29 matching lines...) Expand all
780 host_data.add_resources(), "http://google.com/script2.js", 839 host_data.add_resources(), "http://google.com/script2.js",
781 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); 840 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false);
782 InitializeResourceData(host_data.add_resources(), 841 InitializeResourceData(host_data.add_resources(),
783 "http://google.com/style2.css", 842 "http://google.com/style2.css",
784 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, 843 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0,
785 net::MEDIUM, false, false); 844 net::MEDIUM, false, false);
786 EXPECT_CALL(*mock_tables_.get(), 845 EXPECT_CALL(*mock_tables_.get(),
787 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 846 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
788 empty_redirect_data_)); 847 empty_redirect_data_));
789 848
849 OriginData origin_data = CreateOriginData("www.google.com");
850 InitializeOriginStat(origin_data.add_origins(), "http://static.google.com/",
851 1, 0, 0, 2., true, true);
852 InitializeOriginStat(origin_data.add_origins(), "http://google.com/", 1, 0, 0,
853 1., false, true);
854 EXPECT_CALL(*mock_tables_.get(),
855 UpdateOriginData("www.google.com", origin_data));
856
790 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 857 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
791 profile_->BlockUntilHistoryProcessesPendingRequests(); 858 profile_->BlockUntilHistoryProcessesPendingRequests();
792 } 859 }
793 860
794 // Tests that a URL is deleted before another is added if the cache is full. 861 // Tests that a URL is deleted before another is added if the cache is full.
795 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { 862 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) {
796 const int kVisitCount = 4; 863 const int kVisitCount = 4;
797 AddUrlToHistory("http://www.nike.com/", kVisitCount); 864 AddUrlToHistory("http://www.nike.com/", kVisitCount);
798 865
799 EXPECT_CALL(*mock_tables_.get(), 866 EXPECT_CALL(*mock_tables_.get(),
800 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 867 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
801 Pointee(ContainerEq(PrefetchDataMap())), 868 Pointee(ContainerEq(PrefetchDataMap())),
802 Pointee(ContainerEq(RedirectDataMap())), 869 Pointee(ContainerEq(RedirectDataMap())),
803 Pointee(ContainerEq(RedirectDataMap())), 870 Pointee(ContainerEq(RedirectDataMap())),
804 Pointee(ContainerEq(ManifestDataMap())))) 871 Pointee(ContainerEq(ManifestDataMap())),
872 Pointee(ContainerEq(OriginDataMap()))))
805 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), 873 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_),
806 SetArgPointee<1>(test_host_data_))); 874 SetArgPointee<1>(test_host_data_),
875 SetArgPointee<5>(test_origin_data_)));
807 ResetPredictor(); 876 ResetPredictor();
808 InitializePredictor(); 877 InitializePredictor();
809 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); 878 EXPECT_EQ(3U, predictor_->url_table_cache_->size());
810 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); 879 EXPECT_EQ(2U, predictor_->host_table_cache_->size());
880 EXPECT_EQ(2U, predictor_->origin_table_cache_->size());
811 881
812 URLRequestSummary main_frame = CreateURLRequestSummary( 882 URLRequestSummary main_frame = CreateURLRequestSummary(
813 1, "http://www.nike.com", "http://www.nike.com", 883 1, "http://www.nike.com", "http://www.nike.com",
814 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); 884 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false);
815 predictor_->RecordURLRequest(main_frame); 885 predictor_->RecordURLRequest(main_frame);
816 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 886 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
817 887
818 URLRequestSummary resource1 = CreateURLRequestSummary( 888 URLRequestSummary resource1 = CreateURLRequestSummary(
819 1, "http://www.nike.com", "http://nike.com/style1.css", 889 1, "http://www.nike.com", "http://nike.com/style1.css",
820 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); 890 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
(...skipping 10 matching lines...) Expand all
831 kVisitCount, CreatePageRequestSummary( 901 kVisitCount, CreatePageRequestSummary(
832 "http://www.nike.com", "http://www.nike.com", 902 "http://www.nike.com", "http://www.nike.com",
833 {resource1, resource2}))); 903 {resource1, resource2})));
834 904
835 EXPECT_CALL(*mock_tables_.get(), 905 EXPECT_CALL(*mock_tables_.get(),
836 DeleteSingleResourceDataPoint("http://www.google.com/", 906 DeleteSingleResourceDataPoint("http://www.google.com/",
837 PREFETCH_KEY_TYPE_URL)); 907 PREFETCH_KEY_TYPE_URL));
838 EXPECT_CALL(*mock_tables_.get(), 908 EXPECT_CALL(*mock_tables_.get(),
839 DeleteSingleResourceDataPoint("www.facebook.com", 909 DeleteSingleResourceDataPoint("www.facebook.com",
840 PREFETCH_KEY_TYPE_HOST)); 910 PREFETCH_KEY_TYPE_HOST));
911 EXPECT_CALL(*mock_tables_.get(),
912 DeleteOriginData(std::vector<std::string>({"google.com"})));
841 913
842 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); 914 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/");
843 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", 915 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css",
844 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, 916 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
845 net::MEDIUM, false, false); 917 net::MEDIUM, false, false);
846 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", 918 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png",
847 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, 919 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0,
848 net::MEDIUM, false, false); 920 net::MEDIUM, false, false);
849 EXPECT_CALL(*mock_tables_.get(), 921 EXPECT_CALL(*mock_tables_.get(),
850 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, 922 UpdateData(url_data, empty_resource_data_, empty_redirect_data_,
851 empty_redirect_data_)); 923 empty_redirect_data_));
852 924
853 PrefetchData host_data = CreatePrefetchData("www.nike.com"); 925 PrefetchData host_data = CreatePrefetchData("www.nike.com");
854 host_data.mutable_resources()->CopyFrom(url_data.resources()); 926 host_data.mutable_resources()->CopyFrom(url_data.resources());
855 EXPECT_CALL(*mock_tables_.get(), 927 EXPECT_CALL(*mock_tables_.get(),
856 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, 928 UpdateData(empty_resource_data_, host_data, empty_redirect_data_,
857 empty_redirect_data_)); 929 empty_redirect_data_));
858 930
931 EXPECT_CALL(*mock_tables_.get(),
932 UpdateOriginData("www.nike.com", testing::_));
933
859 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); 934 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
860 profile_->BlockUntilHistoryProcessesPendingRequests(); 935 profile_->BlockUntilHistoryProcessesPendingRequests();
861 } 936 }
862 937
863 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { 938 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) {
864 const int kVisitCount = 4; 939 const int kVisitCount = 4;
865 AddUrlToHistory("https://facebook.com/google", kVisitCount); 940 AddUrlToHistory("https://facebook.com/google", kVisitCount);
866 941
867 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); 942 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google");
868 predictor_->RecordURLRequest(fb1); 943 predictor_->RecordURLRequest(fb1);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // the database cache. 990 // the database cache.
916 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { 991 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) {
917 const int kVisitCount = 7; 992 const int kVisitCount = 7;
918 AddUrlToHistory("https://facebook.com/google", kVisitCount); 993 AddUrlToHistory("https://facebook.com/google", kVisitCount);
919 994
920 EXPECT_CALL(*mock_tables_.get(), 995 EXPECT_CALL(*mock_tables_.get(),
921 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 996 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
922 Pointee(ContainerEq(PrefetchDataMap())), 997 Pointee(ContainerEq(PrefetchDataMap())),
923 Pointee(ContainerEq(RedirectDataMap())), 998 Pointee(ContainerEq(RedirectDataMap())),
924 Pointee(ContainerEq(RedirectDataMap())), 999 Pointee(ContainerEq(RedirectDataMap())),
925 Pointee(ContainerEq(ManifestDataMap())))) 1000 Pointee(ContainerEq(ManifestDataMap())),
1001 Pointee(ContainerEq(OriginDataMap()))))
926 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), 1002 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_),
927 SetArgPointee<3>(test_host_redirect_data_))); 1003 SetArgPointee<3>(test_host_redirect_data_)));
928 ResetPredictor(); 1004 ResetPredictor();
929 InitializePredictor(); 1005 InitializePredictor();
930 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); 1006 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size());
931 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); 1007 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size());
932 1008
933 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); 1009 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google");
934 predictor_->RecordURLRequest(fb1); 1010 predictor_->RecordURLRequest(fb1);
935 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); 1011 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 1070
995 predictor_->OnManifestFetched("google.com", manifest); 1071 predictor_->OnManifestFetched("google.com", manifest);
996 } 1072 }
997 1073
998 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) { 1074 TEST_F(ResourcePrefetchPredictorTest, ManifestHostInDB) {
999 EXPECT_CALL(*mock_tables_.get(), 1075 EXPECT_CALL(*mock_tables_.get(),
1000 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 1076 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
1001 Pointee(ContainerEq(PrefetchDataMap())), 1077 Pointee(ContainerEq(PrefetchDataMap())),
1002 Pointee(ContainerEq(RedirectDataMap())), 1078 Pointee(ContainerEq(RedirectDataMap())),
1003 Pointee(ContainerEq(RedirectDataMap())), 1079 Pointee(ContainerEq(RedirectDataMap())),
1004 Pointee(ContainerEq(ManifestDataMap())))) 1080 Pointee(ContainerEq(ManifestDataMap())),
1081 Pointee(ContainerEq(OriginDataMap()))))
1005 .WillOnce(SetArgPointee<4>(test_manifest_data_)); 1082 .WillOnce(SetArgPointee<4>(test_manifest_data_));
1006 ResetPredictor(); 1083 ResetPredictor();
1007 InitializePredictor(); 1084 InitializePredictor();
1008 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); 1085 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size());
1009 1086
1010 precache::PrecacheManifest manifest = CreateManifestData(1); 1087 precache::PrecacheManifest manifest = CreateManifestData(1);
1011 InitializePrecacheResource(manifest.add_resource(), 1088 InitializePrecacheResource(manifest.add_resource(),
1012 "http://google.com/image.jpg", 0.1); 1089 "http://google.com/image.jpg", 0.1);
1013 1090
1014 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest)); 1091 EXPECT_CALL(*mock_tables_.get(), UpdateManifestData("google.com", manifest));
1015 1092
1016 predictor_->OnManifestFetched("google.com", manifest); 1093 predictor_->OnManifestFetched("google.com", manifest);
1017 } 1094 }
1018 1095
1019 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) { 1096 TEST_F(ResourcePrefetchPredictorTest, ManifestHostNotInDBAndDBFull) {
1020 EXPECT_CALL(*mock_tables_.get(), 1097 EXPECT_CALL(*mock_tables_.get(),
1021 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), 1098 GetAllData(Pointee(ContainerEq(PrefetchDataMap())),
1022 Pointee(ContainerEq(PrefetchDataMap())), 1099 Pointee(ContainerEq(PrefetchDataMap())),
1023 Pointee(ContainerEq(RedirectDataMap())), 1100 Pointee(ContainerEq(RedirectDataMap())),
1024 Pointee(ContainerEq(RedirectDataMap())), 1101 Pointee(ContainerEq(RedirectDataMap())),
1025 Pointee(ContainerEq(ManifestDataMap())))) 1102 Pointee(ContainerEq(ManifestDataMap())),
1103 Pointee(ContainerEq(OriginDataMap()))))
1026 .WillOnce(SetArgPointee<4>(test_manifest_data_)); 1104 .WillOnce(SetArgPointee<4>(test_manifest_data_));
1027 ResetPredictor(); 1105 ResetPredictor();
1028 InitializePredictor(); 1106 InitializePredictor();
1029 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size()); 1107 EXPECT_EQ(2U, predictor_->manifest_table_cache_->size());
1030 1108
1031 precache::PrecacheManifest manifest = CreateManifestData(1); 1109 precache::PrecacheManifest manifest = CreateManifestData(1);
1032 InitializePrecacheResource(manifest.add_resource(), 1110 InitializePrecacheResource(manifest.add_resource(),
1033 "http://en.wikipedia.org/logo.png", 1.0); 1111 "http://en.wikipedia.org/logo.png", 1.0);
1034 1112
1035 EXPECT_CALL(*mock_tables_.get(), 1113 EXPECT_CALL(*mock_tables_.get(),
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 std::make_pair(www_google_url.primary_key(), www_google_url)); 1806 std::make_pair(www_google_url.primary_key(), www_google_url));
1729 1807
1730 urls.clear(); 1808 urls.clear();
1731 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction)); 1809 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &prediction));
1732 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); 1810 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url)));
1733 } 1811 }
1734 1812
1735 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) { 1813 TEST_F(ResourcePrefetchPredictorTest, TestPrecisionRecallHistograms) {
1736 using testing::_; 1814 using testing::_;
1737 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _)); 1815 EXPECT_CALL(*mock_tables_.get(), UpdateData(_, _, _, _));
1816 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_, _));
1738 1817
1739 // Fill the database with 3 resources: 1 useful, 2 useless. 1818 // Fill the database with 3 resources: 1 useful, 2 useless.
1740 const std::string main_frame_url = "http://google.com/?query=cats"; 1819 const std::string main_frame_url = "http://google.com/?query=cats";
1741 PrefetchData google = CreatePrefetchData("google.com", 1); 1820 PrefetchData google = CreatePrefetchData("google.com", 1);
1742 1821
1743 const std::string script_url = "https://cdn.google.com/script.js"; 1822 const std::string script_url = "https://cdn.google.com/script.js";
1744 InitializeResourceData(google.add_resources(), script_url, 1823 InitializeResourceData(google.add_resources(), script_url,
1745 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, 1824 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1,
1746 net::MEDIUM, false, false); 1825 net::MEDIUM, false, false);
1747 InitializeResourceData(google.add_resources(), script_url + "foo", 1826 InitializeResourceData(google.add_resources(), script_url + "foo",
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 predictor_->host_table_cache_->insert( 1913 predictor_->host_table_cache_->insert(
1835 std::make_pair(google.primary_key(), google)); 1914 std::make_pair(google.primary_key(), google));
1836 1915
1837 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); 1916 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL);
1838 predictor_->StopPrefetching(GURL(main_frame_url)); 1917 predictor_->StopPrefetching(GURL(main_frame_url));
1839 histogram_tester_->ExpectTotalCount( 1918 histogram_tester_->ExpectTotalCount(
1840 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); 1919 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1);
1841 } 1920 }
1842 1921
1843 } // namespace predictors 1922 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698