Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_unittest.cc

Issue 2755093002: predictors: Mark before_first_contentful_paint for resources fetched before fcp. (Closed)
Patch Set: Just check db. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 auto res1_time = base::TimeTicks::FromInternalValue(1);
2101 auto res2_time = base::TimeTicks::FromInternalValue(2);
2102 auto fcp_time = base::TimeTicks::FromInternalValue(3);
2103 auto res3_time = base::TimeTicks::FromInternalValue(4);
2104
2105 URLRequestSummary main_frame =
2106 CreateURLRequestSummary(1, "http://www.google.com");
2107 predictor_->RecordURLRequest(main_frame);
2108 EXPECT_EQ(1U, predictor_->inflight_navigations_.size());
2109
2110 URLRequestSummary resource1 = CreateURLRequestSummary(
2111 1, "http://www.google.com", "http://google.com/style1.css",
2112 content::RESOURCE_TYPE_STYLESHEET, net::MEDIUM, "text/css", false);
2113 resource1.response_time = res1_time;
2114 predictor_->RecordURLResponse(resource1);
2115 URLRequestSummary resource2 = CreateURLRequestSummary(
2116 1, "http://www.google.com", "http://google.com/script1.js",
2117 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
2118 resource2.response_time = res2_time;
2119 predictor_->RecordURLResponse(resource2);
2120 URLRequestSummary resource3 = CreateURLRequestSummary(
2121 1, "http://www.google.com", "http://google.com/script2.js",
2122 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM, "text/javascript", false);
2123 resource3.response_time = res3_time;
2124 predictor_->RecordURLResponse(resource3);
2125
2126 predictor_->RecordFirstContentfulPaint(main_frame.navigation_id, fcp_time);
2127
2128 PrefetchData host_data = CreatePrefetchData("www.google.com");
2129 InitializeResourceData(host_data.add_resources(),
2130 "http://google.com/style1.css",
2131 content::RESOURCE_TYPE_STYLESHEET, 1, 0, 0, 1.0,
2132 net::MEDIUM, false, false);
2133 InitializeResourceData(
2134 host_data.add_resources(), "http://google.com/script1.js",
2135 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 2.0, net::MEDIUM, false, false);
2136 ResourceData* resource3_rd = host_data.add_resources();
2137 InitializeResourceData(resource3_rd, "http://google.com/script2.js",
2138 content::RESOURCE_TYPE_SCRIPT, 1, 0, 0, 3.0,
2139 net::MEDIUM, false, false);
2140 resource3_rd->set_before_first_contentful_paint(false);
2141 EXPECT_CALL(*mock_tables_.get(),
2142 UpdateResourceData(host_data, PREFETCH_KEY_TYPE_HOST));
2143
2144 predictor_->RecordMainFrameLoadComplete(main_frame.navigation_id);
2145 profile_->BlockUntilHistoryProcessesPendingRequests();
2146 }
2147
2095 } // namespace predictors 2148 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698