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