| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 6 | 6 |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 using testing::ContainerEq; | 30 using testing::ContainerEq; |
| 31 using testing::Pointee; | 31 using testing::Pointee; |
| 32 using testing::SetArgPointee; | 32 using testing::SetArgPointee; |
| 33 using testing::StrictMock; | 33 using testing::StrictMock; |
| 34 using testing::UnorderedElementsAre; | 34 using testing::UnorderedElementsAre; |
| 35 | 35 |
| 36 namespace predictors { | 36 namespace predictors { |
| 37 | 37 |
| 38 typedef ResourcePrefetchPredictor::URLRequestSummary URLRequestSummary; | 38 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 39 typedef ResourcePrefetchPredictorTables::PrefetchDataMap PrefetchDataMap; | 39 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
| 40 typedef ResourcePrefetchPredictorTables::RedirectDataMap RedirectDataMap; | 40 using PrefetchDataMap = ResourcePrefetchPredictorTables::PrefetchDataMap; |
| 41 using RedirectDataMap = ResourcePrefetchPredictorTables::RedirectDataMap; |
| 41 | 42 |
| 42 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( | 43 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders( |
| 43 const char* headers) { | 44 const char* headers) { |
| 44 return make_scoped_refptr(new net::HttpResponseHeaders( | 45 return make_scoped_refptr(new net::HttpResponseHeaders( |
| 45 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); | 46 net::HttpUtil::AssembleRawHeaders(headers, strlen(headers)))); |
| 46 } | 47 } |
| 47 | 48 |
| 48 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { | 49 class EmptyURLRequestDelegate : public net::URLRequest::Delegate { |
| 49 void OnResponseStarted(net::URLRequest* request, int net_error) override {} | 50 void OnResponseStarted(net::URLRequest* request, int net_error) override {} |
| 50 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} | 51 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {} |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void(const std::vector<std::string>& urls, | 147 void(const std::vector<std::string>& urls, |
| 147 const std::vector<std::string>& hosts)); | 148 const std::vector<std::string>& hosts)); |
| 148 MOCK_METHOD2(DeleteSingleRedirectDataPoint, | 149 MOCK_METHOD2(DeleteSingleRedirectDataPoint, |
| 149 void(const std::string& key, PrefetchKeyType key_type)); | 150 void(const std::string& key, PrefetchKeyType key_type)); |
| 150 MOCK_METHOD0(DeleteAllData, void()); | 151 MOCK_METHOD0(DeleteAllData, void()); |
| 151 | 152 |
| 152 protected: | 153 protected: |
| 153 ~MockResourcePrefetchPredictorTables() { } | 154 ~MockResourcePrefetchPredictorTables() { } |
| 154 }; | 155 }; |
| 155 | 156 |
| 157 class MockResourcePrefetchPredictorDelegate |
| 158 : public ResourcePrefetchPredictor::TestDelegate { |
| 159 public: |
| 160 explicit MockResourcePrefetchPredictorDelegate( |
| 161 ResourcePrefetchPredictor* predictor) |
| 162 : TestDelegate(predictor) {} |
| 163 |
| 164 MOCK_METHOD2( |
| 165 OnNavigationLearned, |
| 166 void(size_t url_visit_count, |
| 167 const ResourcePrefetchPredictor::PageRequestSummary& summary)); |
| 168 }; |
| 169 |
| 156 class ResourcePrefetchPredictorTest : public testing::Test { | 170 class ResourcePrefetchPredictorTest : public testing::Test { |
| 157 public: | 171 public: |
| 158 ResourcePrefetchPredictorTest(); | 172 ResourcePrefetchPredictorTest(); |
| 159 ~ResourcePrefetchPredictorTest() override; | 173 ~ResourcePrefetchPredictorTest() override; |
| 160 void SetUp() override; | 174 void SetUp() override; |
| 161 void TearDown() override; | 175 void TearDown() override; |
| 162 | 176 |
| 163 protected: | 177 protected: |
| 164 void AddUrlToHistory(const std::string& url, int visit_count) { | 178 void AddUrlToHistory(const std::string& url, int visit_count) { |
| 165 HistoryServiceFactory::GetForProfile(profile_.get(), | 179 HistoryServiceFactory::GetForProfile(profile_.get(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 177 | 191 |
| 178 NavigationID CreateNavigationID(int process_id, | 192 NavigationID CreateNavigationID(int process_id, |
| 179 int render_frame_id, | 193 int render_frame_id, |
| 180 const std::string& main_frame_url) { | 194 const std::string& main_frame_url) { |
| 181 NavigationID navigation_id(process_id, render_frame_id, | 195 NavigationID navigation_id(process_id, render_frame_id, |
| 182 GURL(main_frame_url)); | 196 GURL(main_frame_url)); |
| 183 navigation_id.creation_time = base::TimeTicks::Now(); | 197 navigation_id.creation_time = base::TimeTicks::Now(); |
| 184 return navigation_id; | 198 return navigation_id; |
| 185 } | 199 } |
| 186 | 200 |
| 201 PageRequestSummary CreatePageRequestSummary( |
| 202 const std::string& main_frame_url, |
| 203 const std::string& initial_url, |
| 204 const std::vector<URLRequestSummary>& subresource_requests) { |
| 205 GURL main_frame_gurl(main_frame_url); |
| 206 PageRequestSummary summary(main_frame_gurl); |
| 207 summary.initial_url = GURL(initial_url); |
| 208 summary.subresource_requests = subresource_requests; |
| 209 return summary; |
| 210 } |
| 211 |
| 187 URLRequestSummary CreateURLRequestSummary( | 212 URLRequestSummary CreateURLRequestSummary( |
| 188 int process_id, | 213 int process_id, |
| 189 int render_frame_id, | 214 int render_frame_id, |
| 190 const std::string& main_frame_url, | 215 const std::string& main_frame_url, |
| 191 const std::string& resource_url = std::string(), | 216 const std::string& resource_url = std::string(), |
| 192 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, | 217 content::ResourceType resource_type = content::RESOURCE_TYPE_MAIN_FRAME, |
| 193 net::RequestPriority priority = net::MEDIUM, | 218 net::RequestPriority priority = net::MEDIUM, |
| 194 const std::string& mime_type = std::string(), | 219 const std::string& mime_type = std::string(), |
| 195 bool was_cached = false) { | 220 bool was_cached = false) { |
| 196 URLRequestSummary summary; | 221 URLRequestSummary summary; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 497 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
| 473 | 498 |
| 474 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); | 499 EXPECT_EQ(test_url_data_, *predictor_->url_table_cache_); |
| 475 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); | 500 EXPECT_EQ(test_host_data_, *predictor_->host_table_cache_); |
| 476 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); | 501 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); |
| 477 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); | 502 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); |
| 478 } | 503 } |
| 479 | 504 |
| 480 // Single navigation but history count is low, so should not record. | 505 // Single navigation but history count is low, so should not record. |
| 481 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { | 506 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { |
| 482 AddUrlToHistory("http://www.google.com", 1); | 507 const int kVisitCount = 1; |
| 508 AddUrlToHistory("https://www.google.com", kVisitCount); |
| 483 | 509 |
| 484 URLRequestSummary main_frame = | 510 URLRequestSummary main_frame = |
| 485 CreateURLRequestSummary(1, 1, "http://www.google.com"); | 511 CreateURLRequestSummary(1, 1, "http://www.google.com"); |
| 486 predictor_->RecordURLRequest(main_frame); | 512 predictor_->RecordURLRequest(main_frame); |
| 487 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 513 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 488 | 514 |
| 489 URLRequestSummary main_frame_redirect = CreateRedirectRequestSummary( | 515 URLRequestSummary main_frame_redirect = CreateRedirectRequestSummary( |
| 490 1, 1, "http://www.google.com", "https://www.google.com"); | 516 1, 1, "http://www.google.com", "https://www.google.com"); |
| 491 predictor_->RecordURLRedirect(main_frame_redirect); | 517 predictor_->RecordURLRedirect(main_frame_redirect); |
| 492 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 518 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 493 main_frame = CreateURLRequestSummary(1, 1, "https://www.google.com"); | 519 main_frame = CreateURLRequestSummary(1, 1, "https://www.google.com"); |
| 494 | 520 |
| 495 // Now add a few subresources. | 521 // Now add a few subresources. |
| 496 URLRequestSummary resource1 = CreateURLRequestSummary( | 522 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 497 1, 1, "https://www.google.com", "https://google.com/style1.css", | 523 1, 1, "https://www.google.com", "https://google.com/style1.css", |
| 498 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 524 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 499 predictor_->RecordURLResponse(resource1); | 525 predictor_->RecordURLResponse(resource1); |
| 500 URLRequestSummary resource2 = CreateURLRequestSummary( | 526 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 501 1, 1, "https://www.google.com", "https://google.com/script1.js", | 527 1, 1, "https://www.google.com", "https://google.com/script1.js", |
| 502 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 528 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 503 predictor_->RecordURLResponse(resource2); | 529 predictor_->RecordURLResponse(resource2); |
| 504 URLRequestSummary resource3 = CreateURLRequestSummary( | 530 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 505 1, 1, "https://www.google.com", "https://google.com/script2.js", | 531 1, 1, "https://www.google.com", "https://google.com/script2.js", |
| 506 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 532 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 507 predictor_->RecordURLResponse(resource3); | 533 predictor_->RecordURLResponse(resource3); |
| 508 | 534 |
| 535 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 536 predictor_.get()); |
| 537 EXPECT_CALL( |
| 538 mock_delegate, |
| 539 OnNavigationLearned(kVisitCount, |
| 540 CreatePageRequestSummary( |
| 541 "https://www.google.com", "http://www.google.com", |
| 542 {resource1, resource2, resource3}))); |
| 543 |
| 509 PrefetchData host_data = CreatePrefetchData("www.google.com"); | 544 PrefetchData host_data = CreatePrefetchData("www.google.com"); |
| 510 InitializeResourceData(host_data.add_resources(), | 545 InitializeResourceData(host_data.add_resources(), |
| 511 "https://google.com/style1.css", | 546 "https://google.com/style1.css", |
| 512 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | 547 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 513 net::MEDIUM, false, false); | 548 net::MEDIUM, false, false); |
| 514 InitializeResourceData( | 549 InitializeResourceData( |
| 515 host_data.add_resources(), "https://google.com/script1.js", | 550 host_data.add_resources(), "https://google.com/script1.js", |
| 516 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | 551 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 517 InitializeResourceData( | 552 InitializeResourceData( |
| 518 host_data.add_resources(), "https://google.com/script2.js", | 553 host_data.add_resources(), "https://google.com/script2.js", |
| 519 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 554 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 520 EXPECT_CALL(*mock_tables_.get(), | 555 EXPECT_CALL(*mock_tables_.get(), |
| 521 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 556 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 522 empty_redirect_data_)); | 557 empty_redirect_data_)); |
| 523 | 558 |
| 524 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 559 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 525 profile_->BlockUntilHistoryProcessesPendingRequests(); | 560 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 526 } | 561 } |
| 527 | 562 |
| 528 // Single navigation that will be recorded. Will check for duplicate | 563 // Single navigation that will be recorded. Will check for duplicate |
| 529 // resources and also for number of resources saved. | 564 // resources and also for number of resources saved. |
| 530 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 565 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
| 531 AddUrlToHistory("http://www.google.com", 4); | 566 const int kVisitCount = 4; |
| 567 AddUrlToHistory("http://www.google.com", kVisitCount); |
| 532 | 568 |
| 533 URLRequestSummary main_frame = | 569 URLRequestSummary main_frame = |
| 534 CreateURLRequestSummary(1, 1, "http://www.google.com"); | 570 CreateURLRequestSummary(1, 1, "http://www.google.com"); |
| 535 predictor_->RecordURLRequest(main_frame); | 571 predictor_->RecordURLRequest(main_frame); |
| 536 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 572 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 537 | 573 |
| 538 URLRequestSummary resource1 = CreateURLRequestSummary( | 574 std::vector<URLRequestSummary> resources; |
| 575 resources.push_back(CreateURLRequestSummary( |
| 539 1, 1, "http://www.google.com", "http://google.com/style1.css", | 576 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 540 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 577 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); |
| 541 predictor_->RecordURLResponse(resource1); | 578 predictor_->RecordURLResponse(resources.back()); |
| 542 URLRequestSummary resource2 = CreateURLRequestSummary( | 579 resources.push_back(CreateURLRequestSummary( |
| 543 1, 1, "http://www.google.com", "http://google.com/script1.js", | 580 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 544 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 581 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
| 545 predictor_->RecordURLResponse(resource2); | 582 predictor_->RecordURLResponse(resources.back()); |
| 546 URLRequestSummary resource3 = CreateURLRequestSummary( | 583 resources.push_back(CreateURLRequestSummary( |
| 547 1, 1, "http://www.google.com", "http://google.com/script2.js", | 584 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 548 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 585 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
| 549 predictor_->RecordURLResponse(resource3); | 586 predictor_->RecordURLResponse(resources.back()); |
| 550 URLRequestSummary resource4 = CreateURLRequestSummary( | 587 resources.push_back(CreateURLRequestSummary( |
| 551 1, 1, "http://www.google.com", "http://google.com/script1.js", | 588 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 552 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true); | 589 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); |
| 553 predictor_->RecordURLResponse(resource4); | 590 predictor_->RecordURLResponse(resources.back()); |
| 554 URLRequestSummary resource5 = CreateURLRequestSummary( | 591 resources.push_back(CreateURLRequestSummary( |
| 555 1, 1, "http://www.google.com", "http://google.com/image1.png", | 592 1, 1, "http://www.google.com", "http://google.com/image1.png", |
| 556 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 593 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 557 predictor_->RecordURLResponse(resource5); | 594 predictor_->RecordURLResponse(resources.back()); |
| 558 URLRequestSummary resource6 = CreateURLRequestSummary( | 595 resources.push_back(CreateURLRequestSummary( |
| 559 1, 1, "http://www.google.com", "http://google.com/image2.png", | 596 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 560 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 597 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 561 predictor_->RecordURLResponse(resource6); | 598 predictor_->RecordURLResponse(resources.back()); |
| 562 URLRequestSummary resource7 = CreateURLRequestSummary( | 599 resources.push_back(CreateURLRequestSummary( |
| 563 1, 1, "http://www.google.com", "http://google.com/style2.css", | 600 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 564 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 601 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
| 565 predictor_->RecordURLResponse(resource7); | 602 predictor_->RecordURLResponse(resources.back()); |
| 603 |
| 604 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 605 predictor_.get()); |
| 606 EXPECT_CALL(mock_delegate, |
| 607 OnNavigationLearned( |
| 608 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 609 "http://www.google.com", |
| 610 resources))); |
| 566 | 611 |
| 567 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 612 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| 568 InitializeResourceData(url_data.add_resources(), | 613 InitializeResourceData(url_data.add_resources(), |
| 569 "http://google.com/style1.css", | 614 "http://google.com/style1.css", |
| 570 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | 615 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 571 net::MEDIUM, false, false); | 616 net::MEDIUM, false, false); |
| 572 InitializeResourceData( | 617 InitializeResourceData( |
| 573 url_data.add_resources(), "http://google.com/script1.js", | 618 url_data.add_resources(), "http://google.com/script1.js", |
| 574 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | 619 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 575 InitializeResourceData( | 620 InitializeResourceData( |
| 576 url_data.add_resources(), "http://google.com/script2.js", | 621 url_data.add_resources(), "http://google.com/script2.js", |
| 577 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 622 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 578 InitializeResourceData(url_data.add_resources(), | 623 InitializeResourceData(url_data.add_resources(), |
| 579 "http://google.com/style2.css", | 624 "http://google.com/style2.css", |
| 580 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, | 625 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, |
| 581 net::MEDIUM, false, false); | 626 net::MEDIUM, false, false); |
| 582 EXPECT_CALL(*mock_tables_.get(), | 627 EXPECT_CALL(*mock_tables_.get(), |
| 583 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, | 628 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, |
| 584 empty_redirect_data_)); | 629 empty_redirect_data_)); |
| 585 | 630 |
| 586 PrefetchData host_data = CreatePrefetchData("www.google.com"); | 631 PrefetchData host_data = CreatePrefetchData("www.google.com"); |
| 587 host_data.mutable_resources()->CopyFrom(url_data.resources()); | 632 host_data.mutable_resources()->CopyFrom(url_data.resources()); |
| 588 EXPECT_CALL(*mock_tables_.get(), | 633 EXPECT_CALL(*mock_tables_.get(), |
| 589 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 634 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 590 empty_redirect_data_)); | 635 empty_redirect_data_)); |
| 591 | 636 |
| 592 predictor_->OnNavigationComplete(main_frame.navigation_id); | 637 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 593 profile_->BlockUntilHistoryProcessesPendingRequests(); | 638 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 594 } | 639 } |
| 595 | 640 |
| 596 // Tests that navigation is recorded correctly for URL already present in | 641 // Tests that navigation is recorded correctly for URL already present in |
| 597 // the database cache. | 642 // the database cache. |
| 598 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { | 643 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlInDB) { |
| 599 AddUrlToHistory("http://www.google.com", 4); | 644 const int kVisitCount = 4; |
| 645 AddUrlToHistory("http://www.google.com", kVisitCount); |
| 600 | 646 |
| 601 EXPECT_CALL(*mock_tables_.get(), | 647 EXPECT_CALL(*mock_tables_.get(), |
| 602 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 648 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 603 Pointee(ContainerEq(PrefetchDataMap())), | 649 Pointee(ContainerEq(PrefetchDataMap())), |
| 604 Pointee(ContainerEq(RedirectDataMap())), | 650 Pointee(ContainerEq(RedirectDataMap())), |
| 605 Pointee(ContainerEq(RedirectDataMap())))) | 651 Pointee(ContainerEq(RedirectDataMap())))) |
| 606 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 652 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 607 SetArgPointee<1>(test_host_data_))); | 653 SetArgPointee<1>(test_host_data_))); |
| 608 ResetPredictor(); | 654 ResetPredictor(); |
| 609 InitializePredictor(); | 655 InitializePredictor(); |
| 610 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 656 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 611 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 657 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 612 | 658 |
| 613 URLRequestSummary main_frame = CreateURLRequestSummary( | 659 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 614 1, 1, "http://www.google.com", "http://www.google.com", | 660 1, 1, "http://www.google.com", "http://www.google.com", |
| 615 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 661 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 616 predictor_->RecordURLRequest(main_frame); | 662 predictor_->RecordURLRequest(main_frame); |
| 617 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 663 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 618 | 664 |
| 619 URLRequestSummary resource1 = CreateURLRequestSummary( | 665 std::vector<URLRequestSummary> resources; |
| 666 resources.push_back(CreateURLRequestSummary( |
| 620 1, 1, "http://www.google.com", "http://google.com/style1.css", | 667 1, 1, "http://www.google.com", "http://google.com/style1.css", |
| 621 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 668 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); |
| 622 predictor_->RecordURLResponse(resource1); | 669 predictor_->RecordURLResponse(resources.back()); |
| 623 URLRequestSummary resource2 = CreateURLRequestSummary( | 670 resources.push_back(CreateURLRequestSummary( |
| 624 1, 1, "http://www.google.com", "http://google.com/script1.js", | 671 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 625 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 672 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
| 626 predictor_->RecordURLResponse(resource2); | 673 predictor_->RecordURLResponse(resources.back()); |
| 627 URLRequestSummary resource3 = CreateURLRequestSummary( | 674 resources.push_back(CreateURLRequestSummary( |
| 628 1, 1, "http://www.google.com", "http://google.com/script2.js", | 675 1, 1, "http://www.google.com", "http://google.com/script2.js", |
| 629 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 676 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
| 630 predictor_->RecordURLResponse(resource3); | 677 predictor_->RecordURLResponse(resources.back()); |
| 631 URLRequestSummary resource4 = CreateURLRequestSummary( | 678 resources.push_back(CreateURLRequestSummary( |
| 632 1, 1, "http://www.google.com", "http://google.com/script1.js", | 679 1, 1, "http://www.google.com", "http://google.com/script1.js", |
| 633 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true); | 680 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); |
| 634 predictor_->RecordURLResponse(resource4); | 681 predictor_->RecordURLResponse(resources.back()); |
| 635 URLRequestSummary resource5 = CreateURLRequestSummary( | 682 resources.push_back(CreateURLRequestSummary( |
| 636 1, 1, "http://www.google.com", "http://google.com/image1.png", | 683 1, 1, "http://www.google.com", "http://google.com/image1.png", |
| 637 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 684 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 638 predictor_->RecordURLResponse(resource5); | 685 predictor_->RecordURLResponse(resources.back()); |
| 639 URLRequestSummary resource6 = CreateURLRequestSummary( | 686 resources.push_back(CreateURLRequestSummary( |
| 640 1, 1, "http://www.google.com", "http://google.com/image2.png", | 687 1, 1, "http://www.google.com", "http://google.com/image2.png", |
| 641 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 688 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
| 642 predictor_->RecordURLResponse(resource6); | 689 predictor_->RecordURLResponse(resources.back()); |
| 643 URLRequestSummary resource7 = CreateURLRequestSummary( | 690 resources.push_back(CreateURLRequestSummary( |
| 644 1, 1, "http://www.google.com", "http://google.com/style2.css", | 691 1, 1, "http://www.google.com", "http://google.com/style2.css", |
| 645 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true); | 692 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
| 646 predictor_->RecordURLResponse(resource7); | 693 predictor_->RecordURLResponse(resources.back()); |
| 694 |
| 695 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 696 predictor_.get()); |
| 697 EXPECT_CALL(mock_delegate, |
| 698 OnNavigationLearned( |
| 699 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
| 700 "http://www.google.com", |
| 701 resources))); |
| 647 | 702 |
| 648 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); | 703 PrefetchData url_data = CreatePrefetchData("http://www.google.com/"); |
| 649 InitializeResourceData(url_data.add_resources(), | 704 InitializeResourceData(url_data.add_resources(), |
| 650 "http://google.com/style1.css", | 705 "http://google.com/style1.css", |
| 651 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, | 706 content::RESOURCE_TYPE_STYLESHEET, 4, 2, 0, 1.0, |
| 652 net::MEDIUM, false, false); | 707 net::MEDIUM, false, false); |
| 653 InitializeResourceData( | 708 InitializeResourceData( |
| 654 url_data.add_resources(), "http://google.com/script1.js", | 709 url_data.add_resources(), "http://google.com/script1.js", |
| 655 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | 710 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 656 InitializeResourceData( | 711 InitializeResourceData( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 678 host_data.add_resources(), "http://google.com/script2.js", | 733 host_data.add_resources(), "http://google.com/script2.js", |
| 679 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); | 734 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, net::MEDIUM, false, false); |
| 680 InitializeResourceData(host_data.add_resources(), | 735 InitializeResourceData(host_data.add_resources(), |
| 681 "http://google.com/style2.css", | 736 "http://google.com/style2.css", |
| 682 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, | 737 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 7.0, |
| 683 net::MEDIUM, false, false); | 738 net::MEDIUM, false, false); |
| 684 EXPECT_CALL(*mock_tables_.get(), | 739 EXPECT_CALL(*mock_tables_.get(), |
| 685 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 740 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 686 empty_redirect_data_)); | 741 empty_redirect_data_)); |
| 687 | 742 |
| 688 predictor_->OnNavigationComplete(main_frame.navigation_id); | 743 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 689 profile_->BlockUntilHistoryProcessesPendingRequests(); | 744 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 690 } | 745 } |
| 691 | 746 |
| 692 // Tests that a URL is deleted before another is added if the cache is full. | 747 // Tests that a URL is deleted before another is added if the cache is full. |
| 693 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { | 748 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDBAndDBFull) { |
| 694 AddUrlToHistory("http://www.nike.com/", 4); | 749 const int kVisitCount = 4; |
| 750 AddUrlToHistory("http://www.nike.com/", kVisitCount); |
| 695 | 751 |
| 696 EXPECT_CALL(*mock_tables_.get(), | 752 EXPECT_CALL(*mock_tables_.get(), |
| 697 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 753 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 698 Pointee(ContainerEq(PrefetchDataMap())), | 754 Pointee(ContainerEq(PrefetchDataMap())), |
| 699 Pointee(ContainerEq(RedirectDataMap())), | 755 Pointee(ContainerEq(RedirectDataMap())), |
| 700 Pointee(ContainerEq(RedirectDataMap())))) | 756 Pointee(ContainerEq(RedirectDataMap())))) |
| 701 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 757 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
| 702 SetArgPointee<1>(test_host_data_))); | 758 SetArgPointee<1>(test_host_data_))); |
| 703 ResetPredictor(); | 759 ResetPredictor(); |
| 704 InitializePredictor(); | 760 InitializePredictor(); |
| 705 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 761 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
| 706 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 762 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
| 707 | 763 |
| 708 URLRequestSummary main_frame = CreateURLRequestSummary( | 764 URLRequestSummary main_frame = CreateURLRequestSummary( |
| 709 1, 1, "http://www.nike.com", "http://www.nike.com", | 765 1, 1, "http://www.nike.com", "http://www.nike.com", |
| 710 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 766 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
| 711 predictor_->RecordURLRequest(main_frame); | 767 predictor_->RecordURLRequest(main_frame); |
| 712 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 768 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 713 | 769 |
| 714 URLRequestSummary resource1 = CreateURLRequestSummary( | 770 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 715 1, 1, "http://www.nike.com", "http://nike.com/style1.css", | 771 1, 1, "http://www.nike.com", "http://nike.com/style1.css", |
| 716 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 772 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 717 predictor_->RecordURLResponse(resource1); | 773 predictor_->RecordURLResponse(resource1); |
| 718 URLRequestSummary resource2 = CreateURLRequestSummary( | 774 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 719 1, 1, "http://www.nike.com", "http://nike.com/image2.png", | 775 1, 1, "http://www.nike.com", "http://nike.com/image2.png", |
| 720 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 776 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
| 721 predictor_->RecordURLResponse(resource2); | 777 predictor_->RecordURLResponse(resource2); |
| 722 | 778 |
| 779 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 780 predictor_.get()); |
| 781 EXPECT_CALL(mock_delegate, |
| 782 OnNavigationLearned( |
| 783 kVisitCount, CreatePageRequestSummary( |
| 784 "http://www.nike.com", "http://www.nike.com", |
| 785 {resource1, resource2}))); |
| 786 |
| 723 EXPECT_CALL(*mock_tables_.get(), | 787 EXPECT_CALL(*mock_tables_.get(), |
| 724 DeleteSingleResourceDataPoint("http://www.google.com/", | 788 DeleteSingleResourceDataPoint("http://www.google.com/", |
| 725 PREFETCH_KEY_TYPE_URL)); | 789 PREFETCH_KEY_TYPE_URL)); |
| 726 EXPECT_CALL(*mock_tables_.get(), | 790 EXPECT_CALL(*mock_tables_.get(), |
| 727 DeleteSingleResourceDataPoint("www.facebook.com", | 791 DeleteSingleResourceDataPoint("www.facebook.com", |
| 728 PREFETCH_KEY_TYPE_HOST)); | 792 PREFETCH_KEY_TYPE_HOST)); |
| 729 | 793 |
| 730 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); | 794 PrefetchData url_data = CreatePrefetchData("http://www.nike.com/"); |
| 731 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", | 795 InitializeResourceData(url_data.add_resources(), "http://nike.com/style1.css", |
| 732 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | 796 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 733 net::MEDIUM, false, false); | 797 net::MEDIUM, false, false); |
| 734 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", | 798 InitializeResourceData(url_data.add_resources(), "http://nike.com/image2.png", |
| 735 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, | 799 content::RESOURCE_TYPE_IMAGE, 1, 0, 0, 2.0, |
| 736 net::MEDIUM, false, false); | 800 net::MEDIUM, false, false); |
| 737 EXPECT_CALL(*mock_tables_.get(), | 801 EXPECT_CALL(*mock_tables_.get(), |
| 738 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, | 802 UpdateData(url_data, empty_resource_data_, empty_redirect_data_, |
| 739 empty_redirect_data_)); | 803 empty_redirect_data_)); |
| 740 | 804 |
| 741 PrefetchData host_data = CreatePrefetchData("www.nike.com"); | 805 PrefetchData host_data = CreatePrefetchData("www.nike.com"); |
| 742 host_data.mutable_resources()->CopyFrom(url_data.resources()); | 806 host_data.mutable_resources()->CopyFrom(url_data.resources()); |
| 743 EXPECT_CALL(*mock_tables_.get(), | 807 EXPECT_CALL(*mock_tables_.get(), |
| 744 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, | 808 UpdateData(empty_resource_data_, host_data, empty_redirect_data_, |
| 745 empty_redirect_data_)); | 809 empty_redirect_data_)); |
| 746 | 810 |
| 747 predictor_->OnNavigationComplete(main_frame.navigation_id); | 811 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 748 profile_->BlockUntilHistoryProcessesPendingRequests(); | 812 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 749 } | 813 } |
| 750 | 814 |
| 751 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { | 815 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { |
| 752 AddUrlToHistory("https://facebook.com/google", 4); | 816 const int kVisitCount = 4; |
| 817 AddUrlToHistory("https://facebook.com/google", kVisitCount); |
| 753 | 818 |
| 754 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); | 819 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); |
| 755 predictor_->RecordURLRequest(fb1); | 820 predictor_->RecordURLRequest(fb1); |
| 756 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 821 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 757 | 822 |
| 758 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 823 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
| 759 1, 1, "http://fb.com/google", "http://facebook.com/google"); | 824 1, 1, "http://fb.com/google", "http://facebook.com/google"); |
| 760 predictor_->RecordURLRedirect(fb2); | 825 predictor_->RecordURLRedirect(fb2); |
| 761 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 826 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
| 762 1, 1, "http://facebook.com/google", "https://facebook.com/google"); | 827 1, 1, "http://facebook.com/google", "https://facebook.com/google"); |
| 763 predictor_->RecordURLRedirect(fb3); | 828 predictor_->RecordURLRedirect(fb3); |
| 764 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); | 829 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); |
| 765 | 830 |
| 831 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 832 predictor_.get()); |
| 833 EXPECT_CALL( |
| 834 mock_delegate, |
| 835 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
| 836 "https://facebook.com/google", |
| 837 "http://fb.com/google", |
| 838 std::vector<URLRequestSummary>()))); |
| 839 |
| 766 // Since the navigation hasn't resources, corresponding entry | 840 // Since the navigation hasn't resources, corresponding entry |
| 767 // in resource table will be deleted. | 841 // in resource table will be deleted. |
| 768 EXPECT_CALL(*mock_tables_.get(), | 842 EXPECT_CALL(*mock_tables_.get(), |
| 769 DeleteSingleResourceDataPoint("https://facebook.com/google", | 843 DeleteSingleResourceDataPoint("https://facebook.com/google", |
| 770 PREFETCH_KEY_TYPE_URL)); | 844 PREFETCH_KEY_TYPE_URL)); |
| 771 EXPECT_CALL(*mock_tables_.get(), DeleteSingleResourceDataPoint( | 845 EXPECT_CALL(*mock_tables_.get(), DeleteSingleResourceDataPoint( |
| 772 "facebook.com", PREFETCH_KEY_TYPE_HOST)); | 846 "facebook.com", PREFETCH_KEY_TYPE_HOST)); |
| 773 | 847 |
| 774 RedirectData url_redirect_data = CreateRedirectData("http://fb.com/google"); | 848 RedirectData url_redirect_data = CreateRedirectData("http://fb.com/google"); |
| 775 InitializeRedirectStat(url_redirect_data.add_redirect_endpoints(), | 849 InitializeRedirectStat(url_redirect_data.add_redirect_endpoints(), |
| 776 "https://facebook.com/google", 1, 0, 0); | 850 "https://facebook.com/google", 1, 0, 0); |
| 777 EXPECT_CALL(*mock_tables_.get(), | 851 EXPECT_CALL(*mock_tables_.get(), |
| 778 UpdateData(empty_resource_data_, empty_resource_data_, | 852 UpdateData(empty_resource_data_, empty_resource_data_, |
| 779 url_redirect_data, empty_redirect_data_)); | 853 url_redirect_data, empty_redirect_data_)); |
| 780 | 854 |
| 781 RedirectData host_redirect_data = CreateRedirectData("fb.com"); | 855 RedirectData host_redirect_data = CreateRedirectData("fb.com"); |
| 782 InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(), | 856 InitializeRedirectStat(host_redirect_data.add_redirect_endpoints(), |
| 783 "facebook.com", 1, 0, 0); | 857 "facebook.com", 1, 0, 0); |
| 784 EXPECT_CALL(*mock_tables_.get(), | 858 EXPECT_CALL(*mock_tables_.get(), |
| 785 UpdateData(empty_resource_data_, empty_resource_data_, | 859 UpdateData(empty_resource_data_, empty_resource_data_, |
| 786 empty_redirect_data_, host_redirect_data)); | 860 empty_redirect_data_, host_redirect_data)); |
| 787 | 861 |
| 788 predictor_->RecordMainFrameLoadComplete(fb_end); | 862 predictor_->RecordMainFrameLoadComplete(fb_end); |
| 789 profile_->BlockUntilHistoryProcessesPendingRequests(); | 863 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 790 } | 864 } |
| 791 | 865 |
| 792 // Tests that redirect is recorded correctly for URL already present in | 866 // Tests that redirect is recorded correctly for URL already present in |
| 793 // the database cache. | 867 // the database cache. |
| 794 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { | 868 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlInDB) { |
| 795 AddUrlToHistory("https://facebook.com/google", 4); | 869 const int kVisitCount = 7; |
| 870 AddUrlToHistory("https://facebook.com/google", kVisitCount); |
| 796 | 871 |
| 797 EXPECT_CALL(*mock_tables_.get(), | 872 EXPECT_CALL(*mock_tables_.get(), |
| 798 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), | 873 GetAllData(Pointee(ContainerEq(PrefetchDataMap())), |
| 799 Pointee(ContainerEq(PrefetchDataMap())), | 874 Pointee(ContainerEq(PrefetchDataMap())), |
| 800 Pointee(ContainerEq(RedirectDataMap())), | 875 Pointee(ContainerEq(RedirectDataMap())), |
| 801 Pointee(ContainerEq(RedirectDataMap())))) | 876 Pointee(ContainerEq(RedirectDataMap())))) |
| 802 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), | 877 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), |
| 803 SetArgPointee<3>(test_host_redirect_data_))); | 878 SetArgPointee<3>(test_host_redirect_data_))); |
| 804 ResetPredictor(); | 879 ResetPredictor(); |
| 805 InitializePredictor(); | 880 InitializePredictor(); |
| 806 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); | 881 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); |
| 807 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); | 882 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); |
| 808 | 883 |
| 809 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); | 884 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); |
| 810 predictor_->RecordURLRequest(fb1); | 885 predictor_->RecordURLRequest(fb1); |
| 811 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 886 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 812 | 887 |
| 813 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 888 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
| 814 1, 1, "http://fb.com/google", "http://facebook.com/google"); | 889 1, 1, "http://fb.com/google", "http://facebook.com/google"); |
| 815 predictor_->RecordURLRedirect(fb2); | 890 predictor_->RecordURLRedirect(fb2); |
| 816 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 891 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
| 817 1, 1, "http://facebook.com/google", "https://facebook.com/google"); | 892 1, 1, "http://facebook.com/google", "https://facebook.com/google"); |
| 818 predictor_->RecordURLRedirect(fb3); | 893 predictor_->RecordURLRedirect(fb3); |
| 819 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); | 894 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); |
| 820 | 895 |
| 896 StrictMock<MockResourcePrefetchPredictorDelegate> mock_delegate( |
| 897 predictor_.get()); |
| 898 EXPECT_CALL( |
| 899 mock_delegate, |
| 900 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
| 901 "https://facebook.com/google", |
| 902 "http://fb.com/google", |
| 903 std::vector<URLRequestSummary>()))); |
| 904 |
| 821 // Oldest entries in tables will be superseded and deleted. | 905 // Oldest entries in tables will be superseded and deleted. |
| 822 EXPECT_CALL(*mock_tables_.get(), | 906 EXPECT_CALL(*mock_tables_.get(), |
| 823 DeleteSingleRedirectDataPoint("bbc.com", PREFETCH_KEY_TYPE_HOST)); | 907 DeleteSingleRedirectDataPoint("bbc.com", PREFETCH_KEY_TYPE_HOST)); |
| 824 | 908 |
| 825 // Since the navigation hasn't resources, corresponding entry | 909 // Since the navigation hasn't resources, corresponding entry |
| 826 // in resource table will be deleted. | 910 // in resource table will be deleted. |
| 827 EXPECT_CALL(*mock_tables_.get(), | 911 EXPECT_CALL(*mock_tables_.get(), |
| 828 DeleteSingleResourceDataPoint("https://facebook.com/google", | 912 DeleteSingleResourceDataPoint("https://facebook.com/google", |
| 829 PREFETCH_KEY_TYPE_URL)); | 913 PREFETCH_KEY_TYPE_URL)); |
| 830 EXPECT_CALL(*mock_tables_.get(), DeleteSingleResourceDataPoint( | 914 EXPECT_CALL(*mock_tables_.get(), DeleteSingleResourceDataPoint( |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 net::MEDIUM, false, false); | 1576 net::MEDIUM, false, false); |
| 1493 predictor_->url_table_cache_->insert( | 1577 predictor_->url_table_cache_->insert( |
| 1494 std::make_pair(www_google_url.primary_key(), www_google_url)); | 1578 std::make_pair(www_google_url.primary_key(), www_google_url)); |
| 1495 | 1579 |
| 1496 urls.clear(); | 1580 urls.clear(); |
| 1497 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); | 1581 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); |
| 1498 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); | 1582 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); |
| 1499 } | 1583 } |
| 1500 | 1584 |
| 1501 } // namespace predictors | 1585 } // namespace predictors |
| OLD | NEW |