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 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2110 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); | 2110 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); |
2111 predictor_->host_table_cache_->insert( | 2111 predictor_->host_table_cache_->insert( |
2112 std::make_pair(google.primary_key(), google)); | 2112 std::make_pair(google.primary_key(), google)); |
2113 | 2113 |
2114 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 2114 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); |
2115 predictor_->StopPrefetching(GURL(main_frame_url)); | 2115 predictor_->StopPrefetching(GURL(main_frame_url)); |
2116 histogram_tester_->ExpectTotalCount( | 2116 histogram_tester_->ExpectTotalCount( |
2117 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); | 2117 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); |
2118 } | 2118 } |
2119 | 2119 |
| 2120 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { |
| 2121 using testing::_; |
| 2122 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); |
| 2123 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); |
| 2124 |
| 2125 auto res1_time = base::TimeTicks::FromInternalValue(1); |
| 2126 auto res2_time = base::TimeTicks::FromInternalValue(2); |
| 2127 auto fcp_time = base::TimeTicks::FromInternalValue(3); |
| 2128 auto res3_time = base::TimeTicks::FromInternalValue(4); |
| 2129 |
| 2130 URLRequestSummary main_frame = |
| 2131 CreateURLRequestSummary(1, "http://www.google.com"); |
| 2132 predictor_->RecordURLRequest(main_frame); |
| 2133 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); |
| 2134 |
| 2135 URLRequestSummary resource1 = CreateURLRequestSummary( |
| 2136 1, "http://www.google.com", "http://google.com/style1.css", |
| 2137 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); |
| 2138 resource1.response_time = res1_time; |
| 2139 predictor_->RecordURLResponse(resource1); |
| 2140 URLRequestSummary resource2 = CreateURLRequestSummary( |
| 2141 1, "http://www.google.com", "http://google.com/script1.js", |
| 2142 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 2143 resource2.response_time = res2_time; |
| 2144 predictor_->RecordURLResponse(resource2); |
| 2145 URLRequestSummary resource3 = CreateURLRequestSummary( |
| 2146 1, "http://www.google.com", "http://google.com/script2.js", |
| 2147 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); |
| 2148 resource3.response_time = res3_time; |
| 2149 predictor_->RecordURLResponse(resource3); |
| 2150 |
| 2151 predictor_->RecordFirstContentfulPaint(main_frame.navigation_id, fcp_time); |
| 2152 |
| 2153 PrefetchData host_data = CreatePrefetchData("www.google.com"); |
| 2154 InitializeResourceData(host_data.add_resources(), |
| 2155 "http://google.com/style1.css", |
| 2156 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, |
| 2157 net::MEDIUM, false, false); |
| 2158 InitializeResourceData( |
| 2159 host_data.add_resources(), "http://google.com/script1.js", |
| 2160 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); |
| 2161 ResourceData* resource3_rd = host_data.add_resources(); |
| 2162 InitializeResourceData(resource3_rd, "http://google.com/script2.js", |
| 2163 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, |
| 2164 net::MEDIUM, false, false); |
| 2165 resource3_rd->set_before_first_contentful_paint(false); |
| 2166 EXPECT_CALL(*mock_tables_.get(), |
| 2167 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST)); |
| 2168 |
| 2169 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); |
| 2170 profile_->BlockUntilHistoryProcessesPendingRequests(); |
| 2171 } |
| 2172 |
2120 } // namespace predictors | 2173 } // namespace predictors |
OLD | NEW |