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 | 9 |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 resource1, | 833 resource1, |
834 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0))); | 834 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(0))); |
835 EXPECT_TRUE(URLRequestSummaryAreEqual( | 835 EXPECT_TRUE(URLRequestSummaryAreEqual( |
836 resource2, | 836 resource2, |
837 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1))); | 837 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(1))); |
838 EXPECT_TRUE(URLRequestSummaryAreEqual( | 838 EXPECT_TRUE(URLRequestSummaryAreEqual( |
839 resource3, | 839 resource3, |
840 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2))); | 840 predictor_->inflight_navigations_[main_frame1.navigation_id]->at(2))); |
841 } | 841 } |
842 | 842 |
843 TEST_F(ResourcePrefetchPredictorTest, GetCorrectPLT) { | |
844 // Single navigation but history count is low, so should not record. | |
845 AddUrlToHistory("http://www.google.com", 1); | |
846 | |
847 URLRequestSummary main_frame = CreateURLRequestSummary( | |
848 1, 1, "http://www.google.com", "http://www.google.com", | |
849 content::RESOURCE_TYPE_MAIN_FRAME, net::MEDIUM, std::string(), false); | |
850 predictor_->RecordURLRequest(main_frame); | |
851 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | |
852 | |
853 // Reset the creation time in |main_frame.navigation_id|. The correct creation | |
854 // time is stored in |inflight_navigations_| and should be used later. | |
855 main_frame.navigation_id.creation_time = base::TimeTicks(); | |
856 EXPECT_TRUE(main_frame.navigation_id.creation_time.is_null()); | |
857 | |
858 // Now add a subresource. | |
859 URLRequestSummary resource1 = CreateURLRequestSummary( | |
860 1, 1, "http://www.google.com", "http://google.com/style1.css", | |
861 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | |
862 predictor_->RecordURLResponse(resource1); | |
863 | |
864 PrefetchData host_data(PREFETCH_KEY_TYPE_HOST, "www.google.com"); | |
865 host_data.resources.push_back(ResourceRow( | |
866 "http://google.com/style1.css", content::RESOURCE_TYPE_STYLESHEET, 1, 0, | |
867 0, 1.0, net::MEDIUM, false, false)); | |
868 EXPECT_CALL(*mock_tables_.get(), UpdateData(empty_url_data_, host_data)); | |
869 | |
870 // The page load time will be collected by RPP_HISTOGRAM_MEDIUM_TIMES, which | |
871 // has a upper bound of 3 minutes. | |
872 base::TimeDelta plt = | |
873 predictor_->OnNavigationComplete(main_frame.navigation_id); | |
874 EXPECT_LT(plt, base::TimeDelta::FromSeconds(180)); | |
875 | |
876 profile_->BlockUntilHistoryProcessesPendingRequests(); | |
877 } | |
878 | |
879 TEST_F(ResourcePrefetchPredictorTest, HandledResourceTypes) { | 843 TEST_F(ResourcePrefetchPredictorTest, HandledResourceTypes) { |
880 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 844 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
881 content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type")); | 845 content::RESOURCE_TYPE_STYLESHEET, "bogus/mime-type")); |
882 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 846 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
883 content::RESOURCE_TYPE_STYLESHEET, "")); | 847 content::RESOURCE_TYPE_STYLESHEET, "")); |
884 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 848 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
885 content::RESOURCE_TYPE_WORKER, "text/css")); | 849 content::RESOURCE_TYPE_WORKER, "text/css")); |
886 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( | 850 EXPECT_FALSE(ResourcePrefetchPredictor::IsHandledResourceType( |
887 content::RESOURCE_TYPE_WORKER, "")); | 851 content::RESOURCE_TYPE_WORKER, "")); |
888 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( | 852 EXPECT_TRUE(ResourcePrefetchPredictor::IsHandledResourceType( |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 url_request_job_factory_.set_response_info(response_info); | 1064 url_request_job_factory_.set_response_info(response_info); |
1101 std::unique_ptr<net::URLRequest> request_etag = | 1065 std::unique_ptr<net::URLRequest> request_etag = |
1102 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, | 1066 CreateURLRequest(GURL("http://www.google.com/cat.png"), net::MEDIUM, |
1103 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); | 1067 content::RESOURCE_TYPE_PREFETCH, 1, 1, true); |
1104 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); | 1068 EXPECT_TRUE(URLRequestSummary::SummarizeResponse(*request_etag, &summary)); |
1105 EXPECT_TRUE(summary.has_validators); | 1069 EXPECT_TRUE(summary.has_validators); |
1106 EXPECT_TRUE(summary.always_revalidate); | 1070 EXPECT_TRUE(summary.always_revalidate); |
1107 } | 1071 } |
1108 | 1072 |
1109 } // namespace predictors | 1073 } // namespace predictors |
OLD | NEW |