OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob
server.h" | 5 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob
server.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" | 8 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
9 | 9 |
10 class AbortsPageLoadMetricsObserverTest | 10 class AbortsPageLoadMetricsObserverTest |
11 : public page_load_metrics::PageLoadMetricsObserverTestHarness { | 11 : public page_load_metrics::PageLoadMetricsObserverTestHarness { |
12 protected: | 12 protected: |
13 void RegisterObservers(page_load_metrics::PageLoadTracker* tracker) override { | 13 void RegisterObservers(page_load_metrics::PageLoadTracker* tracker) override { |
14 tracker->AddObserver(base::MakeUnique<AbortsPageLoadMetricsObserver>()); | 14 tracker->AddObserver(base::MakeUnique<AbortsPageLoadMetricsObserver>()); |
15 } | 15 } |
16 | 16 |
17 void SimulateTimingWithoutPaint() { | 17 void SimulateTimingWithoutPaint() { |
18 page_load_metrics::PageLoadTiming timing; | 18 page_load_metrics::mojom::PageLoadTiming timing; |
| 19 page_load_metrics::InitPageLoadTimingForTest(&timing); |
19 timing.navigation_start = base::Time::FromDoubleT(1); | 20 timing.navigation_start = base::Time::FromDoubleT(1); |
20 SimulateTimingUpdate(timing); | 21 SimulateTimingUpdate(timing); |
21 } | 22 } |
22 | 23 |
23 int CountTotalAbortMetricsRecorded() { | 24 int CountTotalAbortMetricsRecorded() { |
24 base::HistogramTester::CountsMap counts_map = | 25 base::HistogramTester::CountsMap counts_map = |
25 histogram_tester().GetTotalCountsForPrefix( | 26 histogram_tester().GetTotalCountsForPrefix( |
26 "PageLoad.Experimental.AbortTiming."); | 27 "PageLoad.Experimental.AbortTiming."); |
27 int count = 0; | 28 int count = 0; |
28 for (const auto& entry : counts_map) | 29 for (const auto& entry : counts_map) |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 // Simulate the user performing another navigation before paint. | 238 // Simulate the user performing another navigation before paint. |
238 NavigateAndCommit(GURL("https://www.example.com")); | 239 NavigateAndCommit(GURL("https://www.example.com")); |
239 // Since the navigation to google.com had no timing information associated | 240 // Since the navigation to google.com had no timing information associated |
240 // with it, no abort is logged. | 241 // with it, no abort is logged. |
241 histogram_tester().ExpectTotalCount( | 242 histogram_tester().ExpectTotalCount( |
242 internal::kHistogramAbortNewNavigationBeforePaint, 0); | 243 internal::kHistogramAbortNewNavigationBeforePaint, 0); |
243 EXPECT_EQ(0, CountTotalAbortMetricsRecorded()); | 244 EXPECT_EQ(0, CountTotalAbortMetricsRecorded()); |
244 } | 245 } |
245 | 246 |
246 TEST_F(AbortsPageLoadMetricsObserverTest, NoAbortNewNavigationAfterPaint) { | 247 TEST_F(AbortsPageLoadMetricsObserverTest, NoAbortNewNavigationAfterPaint) { |
247 page_load_metrics::PageLoadTiming timing; | 248 page_load_metrics::mojom::PageLoadTiming timing; |
| 249 page_load_metrics::InitPageLoadTimingForTest(&timing); |
248 timing.navigation_start = base::Time::FromDoubleT(1); | 250 timing.navigation_start = base::Time::FromDoubleT(1); |
249 timing.paint_timing.first_paint = base::TimeDelta::FromMicroseconds(1); | 251 timing.paint_timing->first_paint = base::TimeDelta::FromMicroseconds(1); |
250 PopulateRequiredTimingFields(&timing); | 252 PopulateRequiredTimingFields(&timing); |
251 NavigateAndCommit(GURL("https://www.google.com")); | 253 NavigateAndCommit(GURL("https://www.google.com")); |
252 SimulateTimingUpdate(timing); | 254 SimulateTimingUpdate(timing); |
253 | 255 |
254 // The test cannot assume that abort time will be > first_paint | 256 // The test cannot assume that abort time will be > first_paint |
255 // (1 micro-sec). If the system clock is low resolution, PageLoadTracker's | 257 // (1 micro-sec). If the system clock is low resolution, PageLoadTracker's |
256 // abort time may be <= first_paint. In that case the histogram will be | 258 // abort time may be <= first_paint. In that case the histogram will be |
257 // logged. Thus both 0 and 1 counts of histograms are considered good. | 259 // logged. Thus both 0 and 1 counts of histograms are considered good. |
258 | 260 |
259 NavigateAndCommit(GURL("https://www.example.com")); | 261 NavigateAndCommit(GURL("https://www.example.com")); |
260 | 262 |
261 base::HistogramTester::CountsMap counts_map = | 263 base::HistogramTester::CountsMap counts_map = |
262 histogram_tester().GetTotalCountsForPrefix( | 264 histogram_tester().GetTotalCountsForPrefix( |
263 internal::kHistogramAbortNewNavigationBeforePaint); | 265 internal::kHistogramAbortNewNavigationBeforePaint); |
264 | 266 |
265 EXPECT_TRUE(counts_map.empty() || | 267 EXPECT_TRUE(counts_map.empty() || |
266 (counts_map.size() == 1 && counts_map.begin()->second == 1)); | 268 (counts_map.size() == 1 && counts_map.begin()->second == 1)); |
267 } | 269 } |
OLD | NEW |