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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 base::string16(), | 182 base::string16(), |
183 visit_count, | 183 visit_count, |
184 0, | 184 0, |
185 base::Time::Now(), | 185 base::Time::Now(), |
186 false, | 186 false, |
187 history::SOURCE_BROWSED); | 187 history::SOURCE_BROWSED); |
188 profile_->BlockUntilHistoryProcessesPendingRequests(); | 188 profile_->BlockUntilHistoryProcessesPendingRequests(); |
189 } | 189 } |
190 | 190 |
191 URLRequestSummary CreateRedirectRequestSummary( | 191 URLRequestSummary CreateRedirectRequestSummary( |
192 int process_id, | 192 int tab_id, |
Benoit L
2016/12/20 09:53:39
As above, please fix the type and the variable nam
ahemery
2016/12/20 13:00:00
Done
| |
193 int render_frame_id, | |
194 const std::string& main_frame_url, | 193 const std::string& main_frame_url, |
195 const std::string& redirect_url) { | 194 const std::string& redirect_url) { |
196 URLRequestSummary summary = | 195 URLRequestSummary summary = CreateURLRequestSummary(tab_id, main_frame_url); |
197 CreateURLRequestSummary(process_id, render_frame_id, main_frame_url); | |
198 summary.redirect_url = GURL(redirect_url); | 196 summary.redirect_url = GURL(redirect_url); |
199 return summary; | 197 return summary; |
200 } | 198 } |
201 | 199 |
202 std::unique_ptr<net::URLRequest> CreateURLRequest( | 200 std::unique_ptr<net::URLRequest> CreateURLRequest( |
203 const GURL& url, | 201 const GURL& url, |
204 net::RequestPriority priority, | 202 net::RequestPriority priority, |
205 content::ResourceType resource_type, | 203 content::ResourceType resource_type, |
206 int render_process_id, | |
207 int render_frame_id, | |
208 bool is_main_frame) { | 204 bool is_main_frame) { |
209 std::unique_ptr<net::URLRequest> request = | 205 std::unique_ptr<net::URLRequest> request = |
210 url_request_context_.CreateRequest(url, priority, | 206 url_request_context_.CreateRequest(url, priority, |
211 &url_request_delegate_); | 207 &url_request_delegate_); |
212 request->set_first_party_for_cookies(url); | 208 request->set_first_party_for_cookies(url); |
213 content::ResourceRequestInfo::AllocateForTesting( | 209 content::ResourceRequestInfo::AllocateForTesting( |
214 request.get(), resource_type, nullptr, render_process_id, -1, | 210 request.get(), resource_type, nullptr, -1, -1, -1, is_main_frame, false, |
215 render_frame_id, is_main_frame, false, false, true, false); | 211 false, true, false); |
216 request->Start(); | 212 request->Start(); |
217 return request; | 213 return request; |
218 } | 214 } |
219 | 215 |
220 void InitializePredictor() { | 216 void InitializePredictor() { |
221 predictor_->StartInitialization(); | 217 predictor_->StartInitialization(); |
222 base::RunLoop loop; | 218 base::RunLoop loop; |
223 loop.RunUntilIdle(); // Runs the DB lookup. | 219 loop.RunUntilIdle(); // Runs the DB lookup. |
224 profile_->BlockUntilHistoryProcessesPendingRequests(); | 220 profile_->BlockUntilHistoryProcessesPendingRequests(); |
225 } | 221 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); | 464 EXPECT_EQ(test_url_redirect_data_, *predictor_->url_redirect_table_cache_); |
469 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); | 465 EXPECT_EQ(test_host_redirect_data_, *predictor_->host_redirect_table_cache_); |
470 } | 466 } |
471 | 467 |
472 // Single navigation but history count is low, so should not record. | 468 // Single navigation but history count is low, so should not record. |
473 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { | 469 TEST_F(ResourcePrefetchPredictorTest, NavigationNotRecorded) { |
474 const int kVisitCount = 1; | 470 const int kVisitCount = 1; |
475 AddUrlToHistory("https://www.google.com", kVisitCount); | 471 AddUrlToHistory("https://www.google.com", kVisitCount); |
476 | 472 |
477 URLRequestSummary main_frame = | 473 URLRequestSummary main_frame = |
478 CreateURLRequestSummary(1, 1, "http://www.google.com"); | 474 CreateURLRequestSummary(1, "http://www.google.com"); |
479 predictor_->RecordURLRequest(main_frame); | 475 predictor_->RecordURLRequest(main_frame); |
480 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 476 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
481 | 477 |
482 URLRequestSummary main_frame_redirect = CreateRedirectRequestSummary( | 478 URLRequestSummary main_frame_redirect = CreateRedirectRequestSummary( |
483 1, 1, "http://www.google.com", "https://www.google.com"); | 479 1, "http://www.google.com", "https://www.google.com"); |
484 predictor_->RecordURLRedirect(main_frame_redirect); | 480 predictor_->RecordURLRedirect(main_frame_redirect); |
485 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 481 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
486 main_frame = CreateURLRequestSummary(1, 1, "https://www.google.com"); | 482 main_frame = CreateURLRequestSummary(1, "https://www.google.com"); |
487 | 483 |
488 // Now add a few subresources. | 484 // Now add a few subresources. |
489 URLRequestSummary resource1 = CreateURLRequestSummary( | 485 URLRequestSummary resource1 = CreateURLRequestSummary( |
490 1, 1, "https://www.google.com", "https://google.com/style1.css", | 486 1, "https://www.google.com", "https://google.com/style1.css", |
491 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 487 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
492 predictor_->RecordURLResponse(resource1); | 488 predictor_->RecordURLResponse(resource1); |
493 URLRequestSummary resource2 = CreateURLRequestSummary( | 489 URLRequestSummary resource2 = CreateURLRequestSummary( |
494 1, 1, "https://www.google.com", "https://google.com/script1.js", | 490 1, "https://www.google.com", "https://google.com/script1.js", |
495 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 491 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
496 predictor_->RecordURLResponse(resource2); | 492 predictor_->RecordURLResponse(resource2); |
497 URLRequestSummary resource3 = CreateURLRequestSummary( | 493 URLRequestSummary resource3 = CreateURLRequestSummary( |
498 1, 1, "https://www.google.com", "https://google.com/script2.js", | 494 1, "https://www.google.com", "https://google.com/script2.js", |
499 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 495 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
500 predictor_->RecordURLResponse(resource3); | 496 predictor_->RecordURLResponse(resource3); |
501 | 497 |
502 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 498 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
503 predictor_.get()); | 499 predictor_.get()); |
504 EXPECT_CALL( | 500 EXPECT_CALL( |
505 mock_observer, | 501 mock_observer, |
506 OnNavigationLearned(kVisitCount, | 502 OnNavigationLearned(kVisitCount, |
507 CreatePageRequestSummary( | 503 CreatePageRequestSummary( |
508 "https://www.google.com", "http://www.google.com", | 504 "https://www.google.com", "http://www.google.com", |
(...skipping 18 matching lines...) Expand all Loading... | |
527 profile_->BlockUntilHistoryProcessesPendingRequests(); | 523 profile_->BlockUntilHistoryProcessesPendingRequests(); |
528 } | 524 } |
529 | 525 |
530 // Single navigation that will be recorded. Will check for duplicate | 526 // Single navigation that will be recorded. Will check for duplicate |
531 // resources and also for number of resources saved. | 527 // resources and also for number of resources saved. |
532 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { | 528 TEST_F(ResourcePrefetchPredictorTest, NavigationUrlNotInDB) { |
533 const int kVisitCount = 4; | 529 const int kVisitCount = 4; |
534 AddUrlToHistory("http://www.google.com", kVisitCount); | 530 AddUrlToHistory("http://www.google.com", kVisitCount); |
535 | 531 |
536 URLRequestSummary main_frame = | 532 URLRequestSummary main_frame = |
537 CreateURLRequestSummary(1, 1, "http://www.google.com"); | 533 CreateURLRequestSummary(1, "http://www.google.com"); |
538 predictor_->RecordURLRequest(main_frame); | 534 predictor_->RecordURLRequest(main_frame); |
539 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 535 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
540 | 536 |
541 std::vector<URLRequestSummary> resources; | 537 std::vector<URLRequestSummary> resources; |
542 resources.push_back(CreateURLRequestSummary( | 538 resources.push_back(CreateURLRequestSummary( |
543 1, 1, "http://www.google.com", "http://google.com/style1.css", | 539 1, "http://www.google.com", "http://google.com/style1.css", |
544 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); | 540 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); |
545 predictor_->RecordURLResponse(resources.back()); | 541 predictor_->RecordURLResponse(resources.back()); |
546 resources.push_back(CreateURLRequestSummary( | 542 resources.push_back(CreateURLRequestSummary( |
547 1, 1, "http://www.google.com", "http://google.com/script1.js", | 543 1, "http://www.google.com", "http://google.com/script1.js", |
548 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); | 544 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
549 predictor_->RecordURLResponse(resources.back()); | 545 predictor_->RecordURLResponse(resources.back()); |
550 resources.push_back(CreateURLRequestSummary( | 546 resources.push_back(CreateURLRequestSummary( |
551 1, 1, "http://www.google.com", "http://google.com/script2.js", | 547 1, "http://www.google.com", "http://google.com/script2.js", |
552 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); | 548 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
553 predictor_->RecordURLResponse(resources.back()); | 549 predictor_->RecordURLResponse(resources.back()); |
554 resources.push_back(CreateURLRequestSummary( | 550 resources.push_back(CreateURLRequestSummary( |
555 1, 1, "http://www.google.com", "http://google.com/script1.js", | 551 1, "http://www.google.com", "http://google.com/script1.js", |
556 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); | 552 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); |
557 predictor_->RecordURLResponse(resources.back()); | 553 predictor_->RecordURLResponse(resources.back()); |
558 resources.push_back(CreateURLRequestSummary( | 554 resources.push_back(CreateURLRequestSummary( |
559 1, 1, "http://www.google.com", "http://google.com/image1.png", | 555 1, "http://www.google.com", "http://google.com/image1.png", |
560 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 556 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
561 predictor_->RecordURLResponse(resources.back()); | 557 predictor_->RecordURLResponse(resources.back()); |
562 resources.push_back(CreateURLRequestSummary( | 558 resources.push_back(CreateURLRequestSummary( |
563 1, 1, "http://www.google.com", "http://google.com/image2.png", | 559 1, "http://www.google.com", "http://google.com/image2.png", |
564 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 560 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
565 predictor_->RecordURLResponse(resources.back()); | 561 predictor_->RecordURLResponse(resources.back()); |
566 resources.push_back(CreateURLRequestSummary( | 562 resources.push_back(CreateURLRequestSummary( |
567 1, 1, "http://www.google.com", "http://google.com/style2.css", | 563 1, "http://www.google.com", "http://google.com/style2.css", |
568 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); | 564 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
569 predictor_->RecordURLResponse(resources.back()); | 565 predictor_->RecordURLResponse(resources.back()); |
570 | 566 |
571 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 567 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
572 predictor_.get()); | 568 predictor_.get()); |
573 EXPECT_CALL(mock_observer, | 569 EXPECT_CALL(mock_observer, |
574 OnNavigationLearned( | 570 OnNavigationLearned( |
575 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 571 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
576 "http://www.google.com", | 572 "http://www.google.com", |
577 resources))); | 573 resources))); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 Pointee(ContainerEq(RedirectDataMap())), | 613 Pointee(ContainerEq(RedirectDataMap())), |
618 Pointee(ContainerEq(RedirectDataMap())))) | 614 Pointee(ContainerEq(RedirectDataMap())))) |
619 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 615 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
620 SetArgPointee<1>(test_host_data_))); | 616 SetArgPointee<1>(test_host_data_))); |
621 ResetPredictor(); | 617 ResetPredictor(); |
622 InitializePredictor(); | 618 InitializePredictor(); |
623 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 619 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
624 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 620 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
625 | 621 |
626 URLRequestSummary main_frame = CreateURLRequestSummary( | 622 URLRequestSummary main_frame = CreateURLRequestSummary( |
627 1, 1, "http://www.google.com", "http://www.google.com", | 623 1, "http://www.google.com", "http://www.google.com", |
628 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 624 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
629 predictor_->RecordURLRequest(main_frame); | 625 predictor_->RecordURLRequest(main_frame); |
630 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 626 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
631 | 627 |
632 std::vector<URLRequestSummary> resources; | 628 std::vector<URLRequestSummary> resources; |
633 resources.push_back(CreateURLRequestSummary( | 629 resources.push_back(CreateURLRequestSummary( |
634 1, 1, "http://www.google.com", "http://google.com/style1.css", | 630 1, "http://www.google.com", "http://google.com/style1.css", |
635 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); | 631 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false)); |
636 predictor_->RecordURLResponse(resources.back()); | 632 predictor_->RecordURLResponse(resources.back()); |
637 resources.push_back(CreateURLRequestSummary( | 633 resources.push_back(CreateURLRequestSummary( |
638 1, 1, "http://www.google.com", "http://google.com/script1.js", | 634 1, "http://www.google.com", "http://google.com/script1.js", |
639 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); | 635 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
640 predictor_->RecordURLResponse(resources.back()); | 636 predictor_->RecordURLResponse(resources.back()); |
641 resources.push_back(CreateURLRequestSummary( | 637 resources.push_back(CreateURLRequestSummary( |
642 1, 1, "http://www.google.com", "http://google.com/script2.js", | 638 1, "http://www.google.com", "http://google.com/script2.js", |
643 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); | 639 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false)); |
644 predictor_->RecordURLResponse(resources.back()); | 640 predictor_->RecordURLResponse(resources.back()); |
645 resources.push_back(CreateURLRequestSummary( | 641 resources.push_back(CreateURLRequestSummary( |
646 1, 1, "http://www.google.com", "http://google.com/script1.js", | 642 1, "http://www.google.com", "http://google.com/script1.js", |
647 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); | 643 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", true)); |
648 predictor_->RecordURLResponse(resources.back()); | 644 predictor_->RecordURLResponse(resources.back()); |
649 resources.push_back(CreateURLRequestSummary( | 645 resources.push_back(CreateURLRequestSummary( |
650 1, 1, "http://www.google.com", "http://google.com/image1.png", | 646 1, "http://www.google.com", "http://google.com/image1.png", |
651 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 647 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
652 predictor_->RecordURLResponse(resources.back()); | 648 predictor_->RecordURLResponse(resources.back()); |
653 resources.push_back(CreateURLRequestSummary( | 649 resources.push_back(CreateURLRequestSummary( |
654 1, 1, "http://www.google.com", "http://google.com/image2.png", | 650 1, "http://www.google.com", "http://google.com/image2.png", |
655 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); | 651 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false)); |
656 predictor_->RecordURLResponse(resources.back()); | 652 predictor_->RecordURLResponse(resources.back()); |
657 resources.push_back(CreateURLRequestSummary( | 653 resources.push_back(CreateURLRequestSummary( |
658 1, 1, "http://www.google.com", "http://google.com/style2.css", | 654 1, "http://www.google.com", "http://google.com/style2.css", |
659 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); | 655 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", true)); |
660 predictor_->RecordURLResponse(resources.back()); | 656 predictor_->RecordURLResponse(resources.back()); |
661 | 657 |
662 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 658 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
663 predictor_.get()); | 659 predictor_.get()); |
664 EXPECT_CALL(mock_observer, | 660 EXPECT_CALL(mock_observer, |
665 OnNavigationLearned( | 661 OnNavigationLearned( |
666 kVisitCount, CreatePageRequestSummary("http://www.google.com", | 662 kVisitCount, CreatePageRequestSummary("http://www.google.com", |
667 "http://www.google.com", | 663 "http://www.google.com", |
668 resources))); | 664 resources))); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 Pointee(ContainerEq(RedirectDataMap())), | 718 Pointee(ContainerEq(RedirectDataMap())), |
723 Pointee(ContainerEq(RedirectDataMap())))) | 719 Pointee(ContainerEq(RedirectDataMap())))) |
724 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), | 720 .WillOnce(DoAll(SetArgPointee<0>(test_url_data_), |
725 SetArgPointee<1>(test_host_data_))); | 721 SetArgPointee<1>(test_host_data_))); |
726 ResetPredictor(); | 722 ResetPredictor(); |
727 InitializePredictor(); | 723 InitializePredictor(); |
728 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); | 724 EXPECT_EQ(3U, predictor_->url_table_cache_->size()); |
729 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); | 725 EXPECT_EQ(2U, predictor_->host_table_cache_->size()); |
730 | 726 |
731 URLRequestSummary main_frame = CreateURLRequestSummary( | 727 URLRequestSummary main_frame = CreateURLRequestSummary( |
732 1, 1, "http://www.nike.com", "http://www.nike.com", | 728 1, "http://www.nike.com", "http://www.nike.com", |
733 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 729 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
734 predictor_->RecordURLRequest(main_frame); | 730 predictor_->RecordURLRequest(main_frame); |
735 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 731 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
736 | 732 |
737 URLRequestSummary resource1 = CreateURLRequestSummary( | 733 URLRequestSummary resource1 = CreateURLRequestSummary( |
738 1, 1, "http://www.nike.com", "http://nike.com/style1.css", | 734 1, "http://www.nike.com", "http://nike.com/style1.css", |
739 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 735 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
740 predictor_->RecordURLResponse(resource1); | 736 predictor_->RecordURLResponse(resource1); |
741 URLRequestSummary resource2 = CreateURLRequestSummary( | 737 URLRequestSummary resource2 = CreateURLRequestSummary( |
742 1, 1, "http://www.nike.com", "http://nike.com/image2.png", | 738 1, "http://www.nike.com", "http://nike.com/image2.png", |
743 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); | 739 content::RESOURCE_TYPE_IMAGE, net::MEDIUM, "image/png", false); |
744 predictor_->RecordURLResponse(resource2); | 740 predictor_->RecordURLResponse(resource2); |
745 | 741 |
746 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 742 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
747 predictor_.get()); | 743 predictor_.get()); |
748 EXPECT_CALL(mock_observer, | 744 EXPECT_CALL(mock_observer, |
749 OnNavigationLearned( | 745 OnNavigationLearned( |
750 kVisitCount, CreatePageRequestSummary( | 746 kVisitCount, CreatePageRequestSummary( |
751 "http://www.nike.com", "http://www.nike.com", | 747 "http://www.nike.com", "http://www.nike.com", |
752 {resource1, resource2}))); | 748 {resource1, resource2}))); |
(...skipping 23 matching lines...) Expand all Loading... | |
776 empty_redirect_data_)); | 772 empty_redirect_data_)); |
777 | 773 |
778 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | 774 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
779 profile_->BlockUntilHistoryProcessesPendingRequests(); | 775 profile_->BlockUntilHistoryProcessesPendingRequests(); |
780 } | 776 } |
781 | 777 |
782 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { | 778 TEST_F(ResourcePrefetchPredictorTest, RedirectUrlNotInDB) { |
783 const int kVisitCount = 4; | 779 const int kVisitCount = 4; |
784 AddUrlToHistory("https://facebook.com/google", kVisitCount); | 780 AddUrlToHistory("https://facebook.com/google", kVisitCount); |
785 | 781 |
786 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); | 782 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); |
787 predictor_->RecordURLRequest(fb1); | 783 predictor_->RecordURLRequest(fb1); |
788 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 784 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
789 | 785 |
790 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 786 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
791 1, 1, "http://fb.com/google", "http://facebook.com/google"); | 787 1, "http://fb.com/google", "http://facebook.com/google"); |
792 predictor_->RecordURLRedirect(fb2); | 788 predictor_->RecordURLRedirect(fb2); |
793 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 789 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
794 1, 1, "http://facebook.com/google", "https://facebook.com/google"); | 790 1, "http://facebook.com/google", "https://facebook.com/google"); |
795 predictor_->RecordURLRedirect(fb3); | 791 predictor_->RecordURLRedirect(fb3); |
796 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); | 792 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); |
797 | 793 |
798 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 794 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
799 predictor_.get()); | 795 predictor_.get()); |
800 EXPECT_CALL( | 796 EXPECT_CALL( |
801 mock_observer, | 797 mock_observer, |
802 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( | 798 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
803 "https://facebook.com/google", | 799 "https://facebook.com/google", |
804 "http://fb.com/google", | 800 "http://fb.com/google", |
805 std::vector<URLRequestSummary>()))); | 801 std::vector<URLRequestSummary>()))); |
806 | 802 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 Pointee(ContainerEq(PrefetchDataMap())), | 837 Pointee(ContainerEq(PrefetchDataMap())), |
842 Pointee(ContainerEq(RedirectDataMap())), | 838 Pointee(ContainerEq(RedirectDataMap())), |
843 Pointee(ContainerEq(RedirectDataMap())))) | 839 Pointee(ContainerEq(RedirectDataMap())))) |
844 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), | 840 .WillOnce(DoAll(SetArgPointee<2>(test_url_redirect_data_), |
845 SetArgPointee<3>(test_host_redirect_data_))); | 841 SetArgPointee<3>(test_host_redirect_data_))); |
846 ResetPredictor(); | 842 ResetPredictor(); |
847 InitializePredictor(); | 843 InitializePredictor(); |
848 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); | 844 EXPECT_EQ(3U, predictor_->url_redirect_table_cache_->size()); |
849 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); | 845 EXPECT_EQ(2U, predictor_->host_redirect_table_cache_->size()); |
850 | 846 |
851 URLRequestSummary fb1 = CreateURLRequestSummary(1, 1, "http://fb.com/google"); | 847 URLRequestSummary fb1 = CreateURLRequestSummary(1, "http://fb.com/google"); |
852 predictor_->RecordURLRequest(fb1); | 848 predictor_->RecordURLRequest(fb1); |
853 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 849 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
854 | 850 |
855 URLRequestSummary fb2 = CreateRedirectRequestSummary( | 851 URLRequestSummary fb2 = CreateRedirectRequestSummary( |
856 1, 1, "http://fb.com/google", "http://facebook.com/google"); | 852 1, "http://fb.com/google", "http://facebook.com/google"); |
857 predictor_->RecordURLRedirect(fb2); | 853 predictor_->RecordURLRedirect(fb2); |
858 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 854 URLRequestSummary fb3 = CreateRedirectRequestSummary( |
859 1, 1, "http://facebook.com/google", "https://facebook.com/google"); | 855 1, "http://facebook.com/google", "https://facebook.com/google"); |
860 predictor_->RecordURLRedirect(fb3); | 856 predictor_->RecordURLRedirect(fb3); |
861 NavigationID fb_end = CreateNavigationID(1, 1, "https://facebook.com/google"); | 857 NavigationID fb_end = CreateNavigationID(1, "https://facebook.com/google"); |
862 | 858 |
863 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | 859 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( |
864 predictor_.get()); | 860 predictor_.get()); |
865 EXPECT_CALL( | 861 EXPECT_CALL( |
866 mock_observer, | 862 mock_observer, |
867 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( | 863 OnNavigationLearned(kVisitCount, CreatePageRequestSummary( |
868 "https://facebook.com/google", | 864 "https://facebook.com/google", |
869 "http://fb.com/google", | 865 "http://fb.com/google", |
870 std::vector<URLRequestSummary>()))); | 866 std::vector<URLRequestSummary>()))); |
871 | 867 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 | 971 |
976 predictor_->DeleteAllUrls(); | 972 predictor_->DeleteAllUrls(); |
977 EXPECT_TRUE(predictor_->url_table_cache_->empty()); | 973 EXPECT_TRUE(predictor_->url_table_cache_->empty()); |
978 EXPECT_TRUE(predictor_->host_table_cache_->empty()); | 974 EXPECT_TRUE(predictor_->host_table_cache_->empty()); |
979 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty()); | 975 EXPECT_TRUE(predictor_->url_redirect_table_cache_->empty()); |
980 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty()); | 976 EXPECT_TRUE(predictor_->host_redirect_table_cache_->empty()); |
981 } | 977 } |
982 | 978 |
983 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) { | 979 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRequest) { |
984 URLRequestSummary summary1 = CreateURLRequestSummary( | 980 URLRequestSummary summary1 = CreateURLRequestSummary( |
985 1, 1, "http://www.google.com", "http://www.google.com", | 981 1, "http://www.google.com", "http://www.google.com", |
986 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 982 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
987 URLRequestSummary summary2 = CreateURLRequestSummary( | 983 URLRequestSummary summary2 = CreateURLRequestSummary( |
988 1, 2, "http://www.google.com", "http://www.google.com", | 984 2, "http://www.google.com", "http://www.google.com", |
989 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 985 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
990 URLRequestSummary summary3 = CreateURLRequestSummary( | 986 URLRequestSummary summary3 = CreateURLRequestSummary( |
991 2, 1, "http://www.yahoo.com", "http://www.yahoo.com", | 987 3, "http://www.yahoo.com", "http://www.yahoo.com", |
992 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 988 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
993 | 989 |
994 predictor_->OnMainFrameRequest(summary1); | 990 predictor_->OnMainFrameRequest(summary1); |
995 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 991 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
996 predictor_->OnMainFrameRequest(summary2); | 992 predictor_->OnMainFrameRequest(summary2); |
997 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); | 993 EXPECT_EQ(2U, predictor_->inflight_navigations_.size()); |
998 predictor_->OnMainFrameRequest(summary3); | 994 predictor_->OnMainFrameRequest(summary3); |
999 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 995 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
1000 | 996 |
1001 // Insert another with same navigation id. It should replace. | 997 // Insert another with same navigation id. It should replace. |
1002 URLRequestSummary summary4 = CreateURLRequestSummary( | 998 URLRequestSummary summary4 = CreateURLRequestSummary( |
1003 1, 1, "http://www.nike.com", "http://www.nike.com", | 999 1, "http://www.nike.com", "http://www.nike.com", |
1004 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 1000 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
1005 URLRequestSummary summary5 = CreateURLRequestSummary( | 1001 URLRequestSummary summary5 = CreateURLRequestSummary( |
1006 1, 2, "http://www.google.com", "http://www.google.com", | 1002 2, "http://www.google.com", "http://www.google.com", |
1007 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 1003 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
1008 | 1004 |
1009 predictor_->OnMainFrameRequest(summary4); | 1005 predictor_->OnMainFrameRequest(summary4); |
1010 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 1006 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
1011 | 1007 |
1012 // Change this creation time so that it will go away on the next insert. | 1008 // Change this creation time so that it will go away on the next insert. |
1013 summary5.navigation_id.creation_time = base::TimeTicks::Now() - | 1009 summary5.navigation_id.creation_time = base::TimeTicks::Now() - |
1014 base::TimeDelta::FromDays(1); | 1010 base::TimeDelta::FromDays(1); |
1015 predictor_->OnMainFrameRequest(summary5); | 1011 predictor_->OnMainFrameRequest(summary5); |
1016 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 1012 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
1017 | 1013 |
1018 URLRequestSummary summary6 = CreateURLRequestSummary( | 1014 URLRequestSummary summary6 = CreateURLRequestSummary( |
1019 3, 1, "http://www.shoes.com", "http://www.shoes.com", | 1015 4, "http://www.shoes.com", "http://www.shoes.com", |
1020 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 1016 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
1021 predictor_->OnMainFrameRequest(summary6); | 1017 predictor_->OnMainFrameRequest(summary6); |
1022 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); | 1018 EXPECT_EQ(3U, predictor_->inflight_navigations_.size()); |
1023 | 1019 |
1024 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary3.navigation_id) != | 1020 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary3.navigation_id) != |
1025 predictor_->inflight_navigations_.end()); | 1021 predictor_->inflight_navigations_.end()); |
1026 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary4.navigation_id) != | 1022 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary4.navigation_id) != |
1027 predictor_->inflight_navigations_.end()); | 1023 predictor_->inflight_navigations_.end()); |
1028 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary6.navigation_id) != | 1024 EXPECT_TRUE(predictor_->inflight_navigations_.find(summary6.navigation_id) != |
1029 predictor_->inflight_navigations_.end()); | 1025 predictor_->inflight_navigations_.end()); |
1030 } | 1026 } |
1031 | 1027 |
1032 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRedirect) { | 1028 TEST_F(ResourcePrefetchPredictorTest, OnMainFrameRedirect) { |
1033 URLRequestSummary yahoo = CreateURLRequestSummary(1, 1, "http://yahoo.com"); | 1029 URLRequestSummary yahoo = CreateURLRequestSummary(1, "http://yahoo.com"); |
1034 | 1030 |
1035 URLRequestSummary bbc1 = CreateURLRequestSummary(2, 2, "http://bbc.com"); | 1031 URLRequestSummary bbc1 = CreateURLRequestSummary(2, "http://bbc.com"); |
1036 URLRequestSummary bbc2 = CreateRedirectRequestSummary(2, 2, "http://bbc.com", | 1032 URLRequestSummary bbc2 = |
1037 "https://www.bbc.com"); | 1033 CreateRedirectRequestSummary(2, "http://bbc.com", "https://www.bbc.com"); |
1038 NavigationID bbc_end = CreateNavigationID(2, 2, "https://www.bbc.com"); | 1034 NavigationID bbc_end = CreateNavigationID(2, "https://www.bbc.com"); |
1039 | 1035 |
1040 URLRequestSummary youtube1 = | 1036 URLRequestSummary youtube1 = CreateURLRequestSummary(3, "http://youtube.com"); |
1041 CreateURLRequestSummary(1, 2, "http://youtube.com"); | |
1042 URLRequestSummary youtube2 = CreateRedirectRequestSummary( | 1037 URLRequestSummary youtube2 = CreateRedirectRequestSummary( |
1043 1, 2, "http://youtube.com", "https://youtube.com"); | 1038 3, "http://youtube.com", "https://youtube.com"); |
1044 NavigationID youtube_end = CreateNavigationID(1, 2, "https://youtube.com"); | 1039 NavigationID youtube_end = CreateNavigationID(3, "https://youtube.com"); |
1045 | 1040 |
1046 URLRequestSummary nyt1 = CreateURLRequestSummary(2, 1, "http://nyt.com"); | 1041 URLRequestSummary nyt1 = CreateURLRequestSummary(4, "http://nyt.com"); |
1047 URLRequestSummary nyt2 = CreateRedirectRequestSummary(2, 1, "http://nyt.com", | 1042 URLRequestSummary nyt2 = |
1048 "http://nytimes.com"); | 1043 CreateRedirectRequestSummary(4, "http://nyt.com", "http://nytimes.com"); |
1049 URLRequestSummary nyt3 = CreateRedirectRequestSummary( | 1044 URLRequestSummary nyt3 = CreateRedirectRequestSummary(4, "http://nytimes.com", |
1050 2, 1, "http://nytimes.com", "http://m.nytimes.com"); | 1045 "http://m.nytimes.com"); |
1051 NavigationID nyt_end = CreateNavigationID(2, 1, "http://m.nytimes.com"); | 1046 NavigationID nyt_end = CreateNavigationID(4, "http://m.nytimes.com"); |
1052 | 1047 |
1053 URLRequestSummary fb1 = CreateURLRequestSummary(1, 3, "http://fb.com"); | 1048 URLRequestSummary fb1 = CreateURLRequestSummary(5, "http://fb.com"); |
1054 URLRequestSummary fb2 = CreateRedirectRequestSummary(1, 3, "http://fb.com", | 1049 URLRequestSummary fb2 = |
1055 "http://facebook.com"); | 1050 CreateRedirectRequestSummary(5, "http://fb.com", "http://facebook.com"); |
1056 URLRequestSummary fb3 = CreateRedirectRequestSummary( | 1051 URLRequestSummary fb3 = CreateRedirectRequestSummary(5, "http://facebook.com", |
1057 1, 3, "http://facebook.com", "https://facebook.com"); | 1052 "https://facebook.com"); |
1058 URLRequestSummary fb4 = CreateRedirectRequestSummary( | 1053 URLRequestSummary fb4 = CreateRedirectRequestSummary( |
1059 1, 3, "https://facebook.com", | 1054 5, "https://facebook.com", |
1060 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr"); | 1055 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr"); |
1061 NavigationID fb_end = CreateNavigationID( | 1056 NavigationID fb_end = CreateNavigationID( |
1062 1, 3, | 1057 5, |
1063 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr"); | 1058 "https://m.facebook.com/?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr"); |
1064 | 1059 |
1065 // Redirect with empty redirect_url will be deleted. | 1060 // Redirect with empty redirect_url will be deleted. |
1066 predictor_->OnMainFrameRequest(yahoo); | 1061 predictor_->OnMainFrameRequest(yahoo); |
1067 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 1062 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
1068 predictor_->OnMainFrameRedirect(yahoo); | 1063 predictor_->OnMainFrameRedirect(yahoo); |
1069 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 1064 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
1070 | 1065 |
1071 // Redirect without previous request works fine. | 1066 // Redirect without previous request works fine. |
1072 // predictor_->OnMainFrameRequest(bbc1) missing. | 1067 // predictor_->OnMainFrameRequest(bbc1) missing. |
(...skipping 27 matching lines...) Expand all Loading... | |
1100 predictor_->OnMainFrameRedirect(fb3); | 1095 predictor_->OnMainFrameRedirect(fb3); |
1101 predictor_->OnMainFrameRedirect(fb4); | 1096 predictor_->OnMainFrameRedirect(fb4); |
1102 EXPECT_EQ(4U, predictor_->inflight_navigations_.size()); | 1097 EXPECT_EQ(4U, predictor_->inflight_navigations_.size()); |
1103 EXPECT_EQ(fb1.navigation_id.main_frame_url, | 1098 EXPECT_EQ(fb1.navigation_id.main_frame_url, |
1104 predictor_->inflight_navigations_[fb_end]->initial_url); | 1099 predictor_->inflight_navigations_[fb_end]->initial_url); |
1105 } | 1100 } |
1106 | 1101 |
1107 TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) { | 1102 TEST_F(ResourcePrefetchPredictorTest, OnSubresourceResponse) { |
1108 // If there is no inflight navigation, nothing happens. | 1103 // If there is no inflight navigation, nothing happens. |
1109 URLRequestSummary resource1 = CreateURLRequestSummary( | 1104 URLRequestSummary resource1 = CreateURLRequestSummary( |
1110 1, 1, "http://www.google.com", "http://google.com/style1.css", | 1105 1, "http://www.google.com", "http://google.com/style1.css", |
1111 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | 1106 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
1112 predictor_->OnSubresourceResponse(resource1); | 1107 predictor_->OnSubresourceResponse(resource1); |
1113 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); | 1108 EXPECT_TRUE(predictor_->inflight_navigations_.empty()); |
1114 | 1109 |
1115 // Add an inflight navigation. | 1110 // Add an inflight navigation. |
1116 URLRequestSummary main_frame1 = CreateURLRequestSummary( | 1111 URLRequestSummary main_frame1 = CreateURLRequestSummary( |
1117 1, 1, "http://www.google.com", "http://www.google.com", | 1112 1, "http://www.google.com", "http://www.google.com", |
1118 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | 1113 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); |
1119 predictor_->OnMainFrameRequest(main_frame1); | 1114 predictor_->OnMainFrameRequest(main_frame1); |
1120 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 1115 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
1121 | 1116 |
1122 // Now add a few subresources. | 1117 // Now add a few subresources. |
1123 URLRequestSummary resource2 = CreateURLRequestSummary( | 1118 URLRequestSummary resource2 = CreateURLRequestSummary( |
1124 1, 1, "http://www.google.com", "http://google.com/script1.js", | 1119 1, "http://www.google.com", "http://google.com/script1.js", |
1125 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 1120 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
1126 URLRequestSummary resource3 = CreateURLRequestSummary( | 1121 URLRequestSummary resource3 = CreateURLRequestSummary( |
1127 1, 1, "http://www.google.com", "http://google.com/script2.js", | 1122 1, "http://www.google.com", "http://google.com/script2.js", |
1128 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | 1123 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
1129 predictor_->OnSubresourceResponse(resource1); | 1124 predictor_->OnSubresourceResponse(resource1); |
1130 predictor_->OnSubresourceResponse(resource2); | 1125 predictor_->OnSubresourceResponse(resource2); |
1131 predictor_->OnSubresourceResponse(resource3); | 1126 predictor_->OnSubresourceResponse(resource3); |
1132 | 1127 |
1133 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | 1128 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
1134 EXPECT_EQ(3U, predictor_->inflight_navigations_[main_frame1.navigation_id] | 1129 EXPECT_EQ(3U, predictor_->inflight_navigations_[main_frame1.navigation_id] |
1135 ->subresource_requests.size()); | 1130 ->subresource_requests.size()); |
1136 EXPECT_TRUE(URLRequestSummaryAreEqual( | 1131 EXPECT_TRUE(URLRequestSummaryAreEqual( |
1137 resource1, predictor_->inflight_navigations_[main_frame1.navigation_id] | 1132 resource1, predictor_->inflight_navigations_[main_frame1.navigation_id] |
(...skipping 29 matching lines...) Expand all Loading... | |
1167 content::RESOURCE_TYPE_XHR, "")); | 1162 content::RESOURCE_TYPE_XHR, "")); |
1168 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 1163 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
1169 content::RESOURCE_TYPE_XHR, "bogus/mime-type")); | 1164 content::RESOURCE_TYPE_XHR, "bogus/mime-type")); |
1170 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 1165 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
1171 content::RESOURCE_TYPE_XHR, "application/javascript")); | 1166 content::RESOURCE_TYPE_XHR, "application/javascript")); |
1172 } | 1167 } |
1173 | 1168 |
1174 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) { | 1169 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestMainFrame) { |
1175 std::unique_ptr<net::URLRequest> http_request = | 1170 std::unique_ptr<net::URLRequest> http_request = |
1176 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | 1171 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, |
1177 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1172 content::RESOURCE_TYPE_IMAGE, true); |
1178 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1173 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1179 http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | 1174 http_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
1180 | 1175 |
1181 std::unique_ptr<net::URLRequest> https_request = | 1176 std::unique_ptr<net::URLRequest> https_request = |
1182 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | 1177 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, |
1183 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1178 content::RESOURCE_TYPE_IMAGE, true); |
1184 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1179 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1185 https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | 1180 https_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
1186 | 1181 |
1187 std::unique_ptr<net::URLRequest> file_request = | 1182 std::unique_ptr<net::URLRequest> file_request = |
1188 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | 1183 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, |
1189 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1184 content::RESOURCE_TYPE_IMAGE, true); |
1190 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1185 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1191 file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); | 1186 file_request.get(), content::RESOURCE_TYPE_MAIN_FRAME)); |
1192 } | 1187 } |
1193 | 1188 |
1194 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) { | 1189 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordRequestSubResource) { |
1195 std::unique_ptr<net::URLRequest> http_request = | 1190 std::unique_ptr<net::URLRequest> http_request = |
1196 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1191 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1197 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | 1192 content::RESOURCE_TYPE_IMAGE, false); |
1198 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1193 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1199 http_request.get(), content::RESOURCE_TYPE_IMAGE)); | 1194 http_request.get(), content::RESOURCE_TYPE_IMAGE)); |
1200 | 1195 |
1201 std::unique_ptr<net::URLRequest> https_request = | 1196 std::unique_ptr<net::URLRequest> https_request = |
1202 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | 1197 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, |
1203 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | 1198 content::RESOURCE_TYPE_IMAGE, false); |
1204 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1199 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1205 https_request.get(), content::RESOURCE_TYPE_IMAGE)); | 1200 https_request.get(), content::RESOURCE_TYPE_IMAGE)); |
1206 | 1201 |
1207 std::unique_ptr<net::URLRequest> file_request = | 1202 std::unique_ptr<net::URLRequest> file_request = |
1208 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | 1203 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, |
1209 content::RESOURCE_TYPE_IMAGE, 1, 1, false); | 1204 content::RESOURCE_TYPE_IMAGE, false); |
1210 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( | 1205 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordRequest( |
1211 file_request.get(), content::RESOURCE_TYPE_IMAGE)); | 1206 file_request.get(), content::RESOURCE_TYPE_IMAGE)); |
1212 } | 1207 } |
1213 | 1208 |
1214 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) { | 1209 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseMainFrame) { |
1215 net::HttpResponseInfo response_info; | 1210 net::HttpResponseInfo response_info; |
1216 response_info.headers = MakeResponseHeaders(""); | 1211 response_info.headers = MakeResponseHeaders(""); |
1217 url_request_job_factory_.set_response_info(response_info); | 1212 url_request_job_factory_.set_response_info(response_info); |
1218 | 1213 |
1219 std::unique_ptr<net::URLRequest> http_request = | 1214 std::unique_ptr<net::URLRequest> http_request = |
1220 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, | 1215 CreateURLRequest(GURL("http://www.google.com"), net::MEDIUM, |
1221 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | 1216 content::RESOURCE_TYPE_MAIN_FRAME, true); |
1222 EXPECT_TRUE( | 1217 EXPECT_TRUE( |
1223 ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get())); | 1218 ResourcePrefetchPredictor::ShouldRecordResponse(http_request.get())); |
1224 | 1219 |
1225 std::unique_ptr<net::URLRequest> https_request = | 1220 std::unique_ptr<net::URLRequest> https_request = |
1226 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, | 1221 CreateURLRequest(GURL("https://www.google.com"), net::MEDIUM, |
1227 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | 1222 content::RESOURCE_TYPE_MAIN_FRAME, true); |
1228 EXPECT_TRUE( | 1223 EXPECT_TRUE( |
1229 ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get())); | 1224 ResourcePrefetchPredictor::ShouldRecordResponse(https_request.get())); |
1230 | 1225 |
1231 std::unique_ptr<net::URLRequest> file_request = | 1226 std::unique_ptr<net::URLRequest> file_request = |
1232 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, | 1227 CreateURLRequest(GURL("file://www.google.com"), net::MEDIUM, |
1233 content::RESOURCE_TYPE_MAIN_FRAME, 1, 1, true); | 1228 content::RESOURCE_TYPE_MAIN_FRAME, true); |
1234 EXPECT_FALSE( | 1229 EXPECT_FALSE( |
1235 ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get())); | 1230 ResourcePrefetchPredictor::ShouldRecordResponse(file_request.get())); |
1236 } | 1231 } |
1237 | 1232 |
1238 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) { | 1233 TEST_F(ResourcePrefetchPredictorTest, ShouldRecordResponseSubresource) { |
1239 net::HttpResponseInfo response_info; | 1234 net::HttpResponseInfo response_info; |
1240 response_info.headers = | 1235 response_info.headers = |
1241 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); | 1236 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); |
1242 response_info.was_cached = true; | 1237 response_info.was_cached = true; |
1243 url_request_job_factory_.set_response_info(response_info); | 1238 url_request_job_factory_.set_response_info(response_info); |
1244 | 1239 |
1245 // Protocol. | 1240 // Protocol. |
1246 std::unique_ptr<net::URLRequest> http_image_request = | 1241 std::unique_ptr<net::URLRequest> http_image_request = |
1247 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1242 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1248 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1243 content::RESOURCE_TYPE_IMAGE, true); |
1249 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1244 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1250 http_image_request.get())); | 1245 http_image_request.get())); |
1251 | 1246 |
1252 std::unique_ptr<net::URLRequest> https_image_request = | 1247 std::unique_ptr<net::URLRequest> https_image_request = |
1253 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, | 1248 CreateURLRequest(GURL("https://www.google.com/cat.png"), net::MEDIUM, |
1254 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1249 content::RESOURCE_TYPE_IMAGE, true); |
1255 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1250 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1256 https_image_request.get())); | 1251 https_image_request.get())); |
1257 | 1252 |
1258 std::unique_ptr<net::URLRequest> file_image_request = | 1253 std::unique_ptr<net::URLRequest> file_image_request = |
1259 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, | 1254 CreateURLRequest(GURL("file://www.google.com/cat.png"), net::MEDIUM, |
1260 content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1255 content::RESOURCE_TYPE_IMAGE, true); |
1261 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1256 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1262 file_image_request.get())); | 1257 file_image_request.get())); |
1263 | 1258 |
1264 // ResourceType. | 1259 // ResourceType. |
1265 std::unique_ptr<net::URLRequest> sub_frame_request = | 1260 std::unique_ptr<net::URLRequest> sub_frame_request = |
1266 CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM, | 1261 CreateURLRequest(GURL("http://www.google.com/frame.html"), net::MEDIUM, |
1267 content::RESOURCE_TYPE_SUB_FRAME, 1, 1, true); | 1262 content::RESOURCE_TYPE_SUB_FRAME, true); |
1268 EXPECT_FALSE( | 1263 EXPECT_FALSE( |
1269 ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get())); | 1264 ResourcePrefetchPredictor::ShouldRecordResponse(sub_frame_request.get())); |
1270 | 1265 |
1271 std::unique_ptr<net::URLRequest> font_request = CreateURLRequest( | 1266 std::unique_ptr<net::URLRequest> font_request = |
1272 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | 1267 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), |
1273 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, true); | 1268 net::MEDIUM, content::RESOURCE_TYPE_FONT_RESOURCE, true); |
1274 EXPECT_TRUE( | 1269 EXPECT_TRUE( |
1275 ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get())); | 1270 ResourcePrefetchPredictor::ShouldRecordResponse(font_request.get())); |
1276 | 1271 |
1277 // From MIME Type. | 1272 // From MIME Type. |
1278 url_request_job_factory_.set_mime_type("image/png"); | 1273 url_request_job_factory_.set_mime_type("image/png"); |
1279 std::unique_ptr<net::URLRequest> prefetch_image_request = | 1274 std::unique_ptr<net::URLRequest> prefetch_image_request = |
1280 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1275 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1281 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1276 content::RESOURCE_TYPE_PREFETCH, true); |
1282 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1277 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1283 prefetch_image_request.get())); | 1278 prefetch_image_request.get())); |
1284 | 1279 |
1285 url_request_job_factory_.set_mime_type("image/my-wonderful-format"); | 1280 url_request_job_factory_.set_mime_type("image/my-wonderful-format"); |
1286 std::unique_ptr<net::URLRequest> prefetch_unknown_image_request = | 1281 std::unique_ptr<net::URLRequest> prefetch_unknown_image_request = |
1287 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1282 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1288 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1283 content::RESOURCE_TYPE_PREFETCH, true); |
1289 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1284 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1290 prefetch_unknown_image_request.get())); | 1285 prefetch_unknown_image_request.get())); |
1291 | 1286 |
1292 url_request_job_factory_.set_mime_type("font/woff"); | 1287 url_request_job_factory_.set_mime_type("font/woff"); |
1293 std::unique_ptr<net::URLRequest> prefetch_font_request = CreateURLRequest( | 1288 std::unique_ptr<net::URLRequest> prefetch_font_request = |
1294 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | 1289 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), |
1295 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1290 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true); |
1296 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1291 EXPECT_TRUE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1297 prefetch_font_request.get())); | 1292 prefetch_font_request.get())); |
1298 | 1293 |
1299 url_request_job_factory_.set_mime_type("font/woff-woff"); | 1294 url_request_job_factory_.set_mime_type("font/woff-woff"); |
1300 std::unique_ptr<net::URLRequest> prefetch_unknown_font_request = | 1295 std::unique_ptr<net::URLRequest> prefetch_unknown_font_request = |
1301 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), | 1296 CreateURLRequest(GURL("http://www.google.com/comic-sans-ms.woff"), |
1302 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, 1, 1, | 1297 net::MEDIUM, content::RESOURCE_TYPE_PREFETCH, true); |
1303 true); | |
1304 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1298 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1305 prefetch_unknown_font_request.get())); | 1299 prefetch_unknown_font_request.get())); |
1306 | 1300 |
1307 // Not main frame. | 1301 // Not main frame. |
1308 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( | 1302 std::unique_ptr<net::URLRequest> font_request_sub_frame = CreateURLRequest( |
1309 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, | 1303 GURL("http://www.google.com/comic-sans-ms.woff"), net::MEDIUM, |
1310 content::RESOURCE_TYPE_FONT_RESOURCE, 1, 1, false); | 1304 content::RESOURCE_TYPE_FONT_RESOURCE, false); |
1311 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( | 1305 EXPECT_FALSE(ResourcePrefetchPredictor::ShouldRecordResponse( |
1312 font_request_sub_frame.get())); | 1306 font_request_sub_frame.get())); |
1313 } | 1307 } |
1314 | 1308 |
1315 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponse) { | 1309 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponse) { |
1316 net::HttpResponseInfo response_info; | 1310 net::HttpResponseInfo response_info; |
1317 response_info.headers = | 1311 response_info.headers = |
1318 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); | 1312 MakeResponseHeaders("HTTP/1.1 200 OK\n\nSome: Headers\n"); |
1319 response_info.was_cached = true; | 1313 response_info.was_cached = true; |
1320 url_request_job_factory_.set_response_info(response_info); | 1314 url_request_job_factory_.set_response_info(response_info); |
1321 | 1315 |
1322 GURL url("http://www.google.com/cat.png"); | 1316 GURL url("http://www.google.com/cat.png"); |
1323 std::unique_ptr<net::URLRequest> request = CreateURLRequest( | 1317 std::unique_ptr<net::URLRequest> request = |
1324 url, net::MEDIUM, content::RESOURCE_TYPE_IMAGE, 1, 1, true); | 1318 CreateURLRequest(url, net::MEDIUM, content::RESOURCE_TYPE_IMAGE, true); |
1325 URLRequestSummary summary; | 1319 URLRequestSummary summary; |
1326 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); | 1320 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); |
1327 EXPECT_EQ(url, summary.resource_url); | 1321 EXPECT_EQ(url, summary.resource_url); |
1328 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); | 1322 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); |
1329 EXPECT_TRUE(summary.was_cached); | 1323 EXPECT_TRUE(summary.was_cached); |
1330 EXPECT_FALSE(summary.has_validators); | 1324 EXPECT_FALSE(summary.has_validators); |
1331 EXPECT_FALSE(summary.always_revalidate); | 1325 EXPECT_FALSE(summary.always_revalidate); |
1332 | 1326 |
1333 // Navigation_id elements should be unset by default. | 1327 // Navigation_id elements should be unset by default. |
1334 EXPECT_EQ(-1, summary.navigation_id.render_process_id); | 1328 EXPECT_EQ(-1, summary.navigation_id.session_id); |
1335 EXPECT_EQ(-1, summary.navigation_id.render_frame_id); | |
1336 EXPECT_EQ(GURL(), summary.navigation_id.main_frame_url); | 1329 EXPECT_EQ(GURL(), summary.navigation_id.main_frame_url); |
1337 } | 1330 } |
1338 | 1331 |
1339 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseContentType) { | 1332 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseContentType) { |
1340 net::HttpResponseInfo response_info; | 1333 net::HttpResponseInfo response_info; |
1341 response_info.headers = MakeResponseHeaders( | 1334 response_info.headers = MakeResponseHeaders( |
1342 "HTTP/1.1 200 OK\n\n" | 1335 "HTTP/1.1 200 OK\n\n" |
1343 "Some: Headers\n" | 1336 "Some: Headers\n" |
1344 "Content-Type: image/whatever\n"); | 1337 "Content-Type: image/whatever\n"); |
1345 url_request_job_factory_.set_response_info(response_info); | 1338 url_request_job_factory_.set_response_info(response_info); |
1346 url_request_job_factory_.set_mime_type("image/png"); | 1339 url_request_job_factory_.set_mime_type("image/png"); |
1347 | 1340 |
1348 std::unique_ptr<net::URLRequest> request = | 1341 std::unique_ptr<net::URLRequest> request = |
1349 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1342 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1350 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1343 content::RESOURCE_TYPE_PREFETCH, true); |
1351 URLRequestSummary summary; | 1344 URLRequestSummary summary; |
1352 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); | 1345 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request, &summary)); |
1353 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); | 1346 EXPECT_EQ(content::RESOURCE_TYPE_IMAGE, summary.resource_type); |
1354 } | 1347 } |
1355 | 1348 |
1356 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseCachePolicy) { | 1349 TEST_F(ResourcePrefetchPredictorTest, SummarizeResponseCachePolicy) { |
1357 net::HttpResponseInfo response_info; | 1350 net::HttpResponseInfo response_info; |
1358 response_info.headers = MakeResponseHeaders( | 1351 response_info.headers = MakeResponseHeaders( |
1359 "HTTP/1.1 200 OK\n" | 1352 "HTTP/1.1 200 OK\n" |
1360 "Some: Headers\n"); | 1353 "Some: Headers\n"); |
1361 url_request_job_factory_.set_response_info(response_info); | 1354 url_request_job_factory_.set_response_info(response_info); |
1362 | 1355 |
1363 std::unique_ptr<net::URLRequest> request_no_validators = | 1356 std::unique_ptr<net::URLRequest> request_no_validators = |
1364 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1357 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1365 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1358 content::RESOURCE_TYPE_PREFETCH, true); |
1366 | 1359 |
1367 URLRequestSummary summary; | 1360 URLRequestSummary summary; |
1368 EXPECT_TRUE( | 1361 EXPECT_TRUE( |
1369 URLRequestSummary::SummarizeResponse(*request_no_validators, &summary)); | 1362 URLRequestSummary::SummarizeResponse(*request_no_validators, &summary)); |
1370 EXPECT_FALSE(summary.has_validators); | 1363 EXPECT_FALSE(summary.has_validators); |
1371 | 1364 |
1372 response_info.headers = MakeResponseHeaders( | 1365 response_info.headers = MakeResponseHeaders( |
1373 "HTTP/1.1 200 OK\n" | 1366 "HTTP/1.1 200 OK\n" |
1374 "ETag: \"Cr66\"\n" | 1367 "ETag: \"Cr66\"\n" |
1375 "Cache-Control: no-cache\n"); | 1368 "Cache-Control: no-cache\n"); |
1376 url_request_job_factory_.set_response_info(response_info); | 1369 url_request_job_factory_.set_response_info(response_info); |
1377 std::unique_ptr<net::URLRequest> request_etag = | 1370 std::unique_ptr<net::URLRequest> request_etag = |
1378 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1371 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1379 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1372 content::RESOURCE_TYPE_PREFETCH, true); |
1380 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); | 1373 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); |
1381 EXPECT_TRUE(summary.has_validators); | 1374 EXPECT_TRUE(summary.has_validators); |
1382 EXPECT_TRUE(summary.always_revalidate); | 1375 EXPECT_TRUE(summary.always_revalidate); |
1383 } | 1376 } |
1384 | 1377 |
1385 TEST_F(ResourcePrefetchPredictorTest, PopulatePrefetcherRequest) { | 1378 TEST_F(ResourcePrefetchPredictorTest, PopulatePrefetcherRequest) { |
1386 // The data that will be used in populating. | 1379 // The data that will be used in populating. |
1387 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); | 1380 PrefetchData google = CreatePrefetchData("http://www.google.com/", 1); |
1388 InitializeResourceData(google.add_resources(), "http://google.com/image1.png", | 1381 InitializeResourceData(google.add_resources(), "http://google.com/image1.png", |
1389 content::RESOURCE_TYPE_IMAGE, 10, 0, 0, 2.2, | 1382 content::RESOURCE_TYPE_IMAGE, 10, 0, 0, 2.2, |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1551 net::MEDIUM, false, false); | 1544 net::MEDIUM, false, false); |
1552 predictor_->url_table_cache_->insert( | 1545 predictor_->url_table_cache_->insert( |
1553 std::make_pair(www_google_url.primary_key(), www_google_url)); | 1546 std::make_pair(www_google_url.primary_key(), www_google_url)); |
1554 | 1547 |
1555 urls.clear(); | 1548 urls.clear(); |
1556 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); | 1549 EXPECT_TRUE(predictor_->GetPrefetchData(main_frame_url, &urls)); |
1557 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); | 1550 EXPECT_THAT(urls, UnorderedElementsAre(GURL(font_url))); |
1558 } | 1551 } |
1559 | 1552 |
1560 } // namespace predictors | 1553 } // namespace predictors |
OLD | NEW |