Chromium Code Reviews| 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 2074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2085 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); | 2085 content::RESOURCE_TYPE_SCRIPT, 10, 0, 1, 2.1, net::MEDIUM, false, false); |
| 2086 predictor_->host_table_cache_->insert( | 2086 predictor_->host_table_cache_->insert( |
| 2087 std::make_pair(google.primary_key(), google)); | 2087 std::make_pair(google.primary_key(), google)); |
| 2088 | 2088 |
| 2089 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); | 2089 predictor_->StartPrefetching(GURL(main_frame_url), PrefetchOrigin::EXTERNAL); |
| 2090 predictor_->StopPrefetching(GURL(main_frame_url)); | 2090 predictor_->StopPrefetching(GURL(main_frame_url)); |
| 2091 histogram_tester_->ExpectTotalCount( | 2091 histogram_tester_->ExpectTotalCount( |
| 2092 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); | 2092 internal::kResourcePrefetchPredictorPrefetchingDurationHistogram, 1); |
| 2093 } | 2093 } |
| 2094 | 2094 |
| 2095 TEST_F(ResourcePrefetchPredictorTest, TestRecordFirstContentfulPaint) { | |
| 2096 using testing::_; | |
| 2097 EXPECT_CALL(*mock_tables_.get(), UpdateRedirectData(_, _)); | |
| 2098 EXPECT_CALL(*mock_tables_.get(), UpdateOriginData(_)); | |
| 2099 | |
| 2100 const int kVisitCount = 1; | |
| 2101 AddUrlToHistory("http://www.google.com", kVisitCount); | |
| 2102 | |
| 2103 auto start = base::TimeTicks::Now(); | |
| 2104 auto second = base::TimeDelta::FromSeconds(1); | |
| 2105 | |
| 2106 auto res1_time = start + 1 * second; | |
|
alexilin
2017/04/27 13:16:39
nit:
You could use base::TimeTicks::FromInternalVa
trevordixon
2017/04/28 09:44:06
Done.
| |
| 2107 auto res2_time = start + 2 * second; | |
| 2108 auto fcp_time = start + 3 * second; | |
| 2109 auto res3_time = start + 4 * second; | |
| 2110 | |
| 2111 URLRequestSummary main_frame = | |
| 2112 CreateURLRequestSummary(1, "http://www.google.com"); | |
| 2113 predictor_->RecordURLRequest(main_frame); | |
| 2114 EXPECT_EQ(1U, predictor_->inflight_navigations_.size()); | |
| 2115 | |
| 2116 URLRequestSummary resource1 = CreateURLRequestSummary( | |
| 2117 1, "http://www.google.com", "http://google.com/style1.css", | |
| 2118 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false); | |
| 2119 resource1.response_time = res1_time; | |
| 2120 predictor_->RecordURLResponse(resource1); | |
| 2121 URLRequestSummary resource2 = CreateURLRequestSummary( | |
| 2122 1, "http://www.google.com", "http://google.com/script1.js", | |
| 2123 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | |
| 2124 resource2.response_time = res2_time; | |
| 2125 predictor_->RecordURLResponse(resource2); | |
| 2126 URLRequestSummary resource3 = CreateURLRequestSummary( | |
| 2127 1, "http://www.google.com", "http://google.com/script2.js", | |
| 2128 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false); | |
| 2129 resource3.response_time = res3_time; | |
| 2130 resource3.before_first_contentful_paint = false; | |
| 2131 predictor_->RecordURLResponse(resource3); | |
| 2132 | |
| 2133 predictor_->RecordFirstContentfulPaint(main_frame.navigation_id, fcp_time); | |
| 2134 | |
| 2135 StrictMock<MockResourcePrefetchPredictorObserver> mock_observer( | |
| 2136 predictor_.get()); | |
| 2137 EXPECT_CALL( | |
| 2138 mock_observer, | |
| 2139 OnNavigationLearned(kVisitCount, | |
| 2140 CreatePageRequestSummary( | |
| 2141 "http://www.google.com", "http://www.google.com", | |
| 2142 {resource1, resource2, resource3}))); | |
| 2143 | |
| 2144 // Reset before_first_contentful_paint so we can see if the predictor can | |
| 2145 // figure it out. | |
| 2146 resource3.before_first_contentful_paint = true; | |
|
alexilin
2017/04/27 13:16:39
Predictor doesn't keep references to URLRequestSum
trevordixon
2017/04/28 09:44:06
OK, removed.
| |
| 2147 | |
| 2148 PrefetchData host_data = CreatePrefetchData("www.google.com"); | |
| 2149 InitializeResourceData(host_data.add_resources(), | |
| 2150 "http://google.com/style1.css", | |
| 2151 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0, | |
| 2152 net::MEDIUM, false, false); | |
| 2153 InitializeResourceData( | |
| 2154 host_data.add_resources(), "http://google.com/script1.js", | |
| 2155 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false); | |
| 2156 ResourceData* resource3_rd = host_data.add_resources(); | |
| 2157 InitializeResourceData(resource3_rd, "http://google.com/script2.js", | |
| 2158 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0, | |
| 2159 net::MEDIUM, false, false); | |
| 2160 resource3_rd->set_before_first_contentful_paint(false); | |
| 2161 EXPECT_CALL(*mock_tables_.get(), | |
| 2162 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST)); | |
| 2163 | |
| 2164 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id); | |
| 2165 profile_->BlockUntilHistoryProcessesPendingRequests(); | |
| 2166 } | |
| 2167 | |
| 2095 } // namespace predictors | 2168 } // namespace predictors |
| OLD | NEW |