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

Side by Side Diff: components/page_load_metrics/browser/metrics_web_contents_observer_unittest.cc

Issue 2139143002: Standardize which page loads are tracked (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add tests Created 4 years, 5 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 138 }
139 139
140 void CheckTotalErrorEvents() { 140 void CheckTotalErrorEvents() {
141 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); 141 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_);
142 } 142 }
143 143
144 void CheckNoErrorEvents() { 144 void CheckNoErrorEvents() {
145 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); 145 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0);
146 } 146 }
147 147
148 void AssertNoNonEmptyTimingReported() { 148 int CountEmptyCompleteTimingReported() {
149 ASSERT_FALSE(embedder_interface_->complete_timings().empty()); 149 int empty = 0;
150 for (const auto& timing : embedder_interface_->complete_timings()) { 150 for (const auto& timing : embedder_interface_->complete_timings()) {
151 ASSERT_TRUE(timing.IsEmpty()); 151 if (timing.IsEmpty())
152 ++empty;
152 } 153 }
153 } 154 return empty;
154
155 void AssertNonEmptyTimingsReported(size_t expected_non_empty_timings) {
156 ASSERT_GE(embedder_interface_->complete_timings().size(),
157 expected_non_empty_timings);
158 size_t actual_non_empty_timings = 0;
159 for (const auto& timing : embedder_interface_->complete_timings()) {
160 if (!timing.IsEmpty()) {
161 ++actual_non_empty_timings;
162 }
163 }
164 ASSERT_EQ(expected_non_empty_timings, actual_non_empty_timings);
165 ASSERT_GE(embedder_interface_->updated_timings().size(),
166 actual_non_empty_timings);
167 } 155 }
168 156
169 int CountCompleteTimingReported() { 157 int CountCompleteTimingReported() {
170 return embedder_interface_->complete_timings().size(); 158 return embedder_interface_->complete_timings().size();
171 } 159 }
172 int CountUpdatedTimingReported() { 160 int CountUpdatedTimingReported() {
173 return embedder_interface_->updated_timings().size(); 161 return embedder_interface_->updated_timings().size();
174 } 162 }
175 163
176 const std::vector<GURL>& observed_committed_urls_from_on_start() const { 164 const std::vector<GURL>& observed_committed_urls_from_on_start() const {
(...skipping 23 matching lines...) Expand all
200 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 188 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
201 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); 189 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size());
202 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); 190 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty());
203 191
204 ASSERT_EQ(0, CountUpdatedTimingReported()); 192 ASSERT_EQ(0, CountUpdatedTimingReported());
205 SimulateTimingUpdate(timing); 193 SimulateTimingUpdate(timing);
206 ASSERT_EQ(1, CountUpdatedTimingReported()); 194 ASSERT_EQ(1, CountUpdatedTimingReported());
207 ASSERT_EQ(0, CountCompleteTimingReported()); 195 ASSERT_EQ(0, CountCompleteTimingReported());
208 196
209 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); 197 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
210 AssertNonEmptyTimingsReported(1); 198 ASSERT_EQ(1, CountCompleteTimingReported());
199 ASSERT_EQ(0, CountEmptyCompleteTimingReported());
211 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); 200 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size());
212 ASSERT_EQ(kDefaultTestUrl, 201 ASSERT_EQ(kDefaultTestUrl,
213 observed_committed_urls_from_on_start().at(1).spec()); 202 observed_committed_urls_from_on_start().at(1).spec());
214 ASSERT_EQ(1, CountUpdatedTimingReported()); 203 ASSERT_EQ(1, CountUpdatedTimingReported());
215 204
216 CheckNoErrorEvents(); 205 CheckNoErrorEvents();
217 } 206 }
218 207
219 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { 208 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) {
220 PageLoadTiming timing; 209 PageLoadTiming timing;
221 timing.navigation_start = base::Time::FromDoubleT(1); 210 timing.navigation_start = base::Time::FromDoubleT(1);
222 211
223 content::WebContentsTester* web_contents_tester = 212 content::WebContentsTester* web_contents_tester =
224 content::WebContentsTester::For(web_contents()); 213 content::WebContentsTester::For(web_contents());
225 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 214 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
226 215
227 content::RenderFrameHostTester* rfh_tester = 216 content::RenderFrameHostTester* rfh_tester =
228 content::RenderFrameHostTester::For(main_rfh()); 217 content::RenderFrameHostTester::For(main_rfh());
229 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); 218 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe");
230 219
231 content::RenderFrameHostTester* subframe_tester = 220 content::RenderFrameHostTester* subframe_tester =
232 content::RenderFrameHostTester::For(subframe); 221 content::RenderFrameHostTester::For(subframe);
233 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); 222 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2));
234 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); 223 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2));
235 SimulateTimingUpdate(timing, subframe); 224 SimulateTimingUpdate(timing, subframe);
236 subframe_tester->SimulateNavigationStop(); 225 subframe_tester->SimulateNavigationStop();
237 226
238 // Navigate again to see if the timing updated for a subframe message. 227 // Navigate again to see if the timing updated for a subframe message.
239 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 228 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
240 229
241 ASSERT_EQ(0, CountUpdatedTimingReported()); 230 ASSERT_EQ(0, CountUpdatedTimingReported());
242 AssertNoNonEmptyTimingReported(); 231 ASSERT_EQ(1, CountCompleteTimingReported());
232 ASSERT_EQ(1, CountEmptyCompleteTimingReported());
243 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); 233 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1);
234 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 1);
244 CheckTotalErrorEvents(); 235 CheckTotalErrorEvents();
245 } 236 }
246 237
247 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) { 238 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) {
248 PageLoadTiming timing; 239 PageLoadTiming timing;
249 timing.navigation_start = base::Time::FromDoubleT(1); 240 timing.navigation_start = base::Time::FromDoubleT(1);
250 241
251 content::WebContentsTester* web_contents_tester = 242 content::WebContentsTester* web_contents_tester =
252 content::WebContentsTester::For(web_contents()); 243 content::WebContentsTester::For(web_contents());
253 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 244 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
254 ASSERT_EQ(0, CountUpdatedTimingReported()); 245 ASSERT_EQ(0, CountUpdatedTimingReported());
255 SimulateTimingUpdate(timing); 246 SimulateTimingUpdate(timing);
256 ASSERT_EQ(1, CountUpdatedTimingReported()); 247 ASSERT_EQ(1, CountUpdatedTimingReported());
257 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); 248 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor));
249 // Send the same timing update. The original tracker for kDefaultTestUrl
250 // should dedup the update, and the tracker for kDefaultTestUrlAnchor should
251 // have been destroyed as a result of its being a same page navigation, so
252 // CountUpdatedTimingReported() should continue to return 1.
253 SimulateTimingUpdate(timing);
254
255 ASSERT_EQ(1, CountUpdatedTimingReported());
256 ASSERT_EQ(0, CountCompleteTimingReported());
257
258 // Navigate again to force histogram logging.
259 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
260
258 // A same page navigation shouldn't trigger logging UMA for the original. 261 // A same page navigation shouldn't trigger logging UMA for the original.
259 ASSERT_EQ(1, CountUpdatedTimingReported()); 262 ASSERT_EQ(1, CountUpdatedTimingReported());
260 AssertNoNonEmptyTimingReported(); 263 ASSERT_EQ(1, CountCompleteTimingReported());
264 ASSERT_EQ(0, CountEmptyCompleteTimingReported());
261 CheckNoErrorEvents(); 265 CheckNoErrorEvents();
262 } 266 }
263 267
264 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { 268 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) {
265 PageLoadTiming timing; 269 PageLoadTiming timing;
266 timing.navigation_start = base::Time::FromDoubleT(1); 270 timing.navigation_start = base::Time::FromDoubleT(1);
267 271
268 content::WebContentsTester* web_contents_tester = 272 content::WebContentsTester* web_contents_tester =
269 content::WebContentsTester::For(web_contents()); 273 content::WebContentsTester::For(web_contents());
270 embedder_interface_->set_is_prerendering(true); 274 embedder_interface_->set_is_prerendering(true);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 rfh_tester->SimulateNavigationStop(); 467 rfh_tester->SimulateNavigationStop();
464 468
465 web_contents()->Stop(); 469 web_contents()->Stop();
466 470
467 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); 471 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1);
468 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, 472 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3,
469 1); 473 1);
470 } 474 }
471 475
472 } // namespace page_load_metrics 476 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698