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::WrapUnique(new AbortsPageLoadMetricsObserver())); | 14 tracker->AddObserver(base::WrapUnique(new AbortsPageLoadMetricsObserver())); |
15 } | 15 } |
16 | 16 |
17 void SimulateTimingWithoutPaint() { | 17 void SimulateTimingWithoutPaint() { |
18 page_load_metrics::PageLoadTiming timing; | 18 page_load_metrics::PageLoadTiming timing; |
19 timing.navigation_start = base::Time::FromDoubleT(1); | 19 timing.navigation_start = base::Time::FromDoubleT(1); |
20 SimulateTimingUpdate(timing); | 20 SimulateTimingUpdate(timing); |
21 } | 21 } |
22 }; | 22 }; |
23 | 23 |
24 TEST_F(AbortsPageLoadMetricsObserverTest, UnknownNavigationBeforeCommit) { | 24 TEST_F(AbortsPageLoadMetricsObserverTest, NewNavigationBeforeCommit) { |
25 StartNavigation(GURL("https://www.google.com")); | 25 StartNavigation(GURL("https://www.google.com")); |
26 // Simulate the user performing another navigation before commit. | 26 // Simulate the user performing another navigation before commit. |
27 NavigateAndCommit(GURL("https://www.example.com")); | 27 NavigateAndCommit(GURL("https://www.example.com")); |
28 histogram_tester().ExpectTotalCount( | 28 histogram_tester().ExpectTotalCount( |
29 internal::kHistogramAbortUnknownNavigationBeforeCommit, 1); | 29 internal::kHistogramAbortNewNavigationBeforeCommit, 1); |
| 30 } |
| 31 |
| 32 TEST_F(AbortsPageLoadMetricsObserverTest, ReloadBeforeCommit) { |
| 33 StartNavigation(GURL("https://www.google.com")); |
| 34 // Simulate the user performing another navigation before commit. |
| 35 NavigateWithPageTransitionAndCommit(GURL("https://www.example.com"), |
| 36 ui::PAGE_TRANSITION_RELOAD); |
| 37 histogram_tester().ExpectTotalCount( |
| 38 internal::kHistogramAbortReloadBeforeCommit, 1); |
| 39 } |
| 40 |
| 41 TEST_F(AbortsPageLoadMetricsObserverTest, ForwardBackBeforeCommit) { |
| 42 StartNavigation(GURL("https://www.google.com")); |
| 43 // Simulate the user performing another navigation before commit. |
| 44 NavigateWithPageTransitionAndCommit(GURL("https://www.example.com"), |
| 45 ui::PAGE_TRANSITION_FORWARD_BACK); |
| 46 histogram_tester().ExpectTotalCount( |
| 47 internal::kHistogramAbortForwardBackBeforeCommit, 1); |
30 } | 48 } |
31 | 49 |
32 TEST_F(AbortsPageLoadMetricsObserverTest, | 50 TEST_F(AbortsPageLoadMetricsObserverTest, |
33 UnknownProvisionalNavigationBeforeCommit) { | 51 NewProvisionalNavigationBeforeCommit) { |
34 StartNavigation(GURL("https://www.google.com")); | 52 StartNavigation(GURL("https://www.google.com")); |
35 StartNavigation(GURL("https://www.example.com")); | 53 StartNavigation(GURL("https://www.example.com")); |
36 histogram_tester().ExpectTotalCount( | 54 histogram_tester().ExpectTotalCount( |
37 internal::kHistogramAbortUnknownNavigationBeforeCommit, 1); | 55 internal::kHistogramAbortNewNavigationBeforeCommit, 1); |
38 } | 56 } |
39 | 57 |
40 TEST_F(AbortsPageLoadMetricsObserverTest, | 58 TEST_F(AbortsPageLoadMetricsObserverTest, |
41 UnknownNavigationBeforeCommitNonTrackedPageLoad) { | 59 NewNavigationBeforeCommitNonTrackedPageLoad) { |
42 StartNavigation(GURL("https://www.google.com")); | 60 StartNavigation(GURL("https://www.google.com")); |
43 // Simulate the user performing another navigation before commit. Navigate to | 61 // Simulate the user performing another navigation before commit. Navigate to |
44 // an untracked URL, to verify that we still log abort metrics even if the new | 62 // an untracked URL, to verify that we still log abort metrics even if the new |
45 // navigation isn't tracked. | 63 // navigation isn't tracked. |
46 NavigateAndCommit(GURL("about:blank")); | 64 NavigateAndCommit(GURL("about:blank")); |
47 histogram_tester().ExpectTotalCount( | 65 histogram_tester().ExpectTotalCount( |
48 internal::kHistogramAbortUnknownNavigationBeforeCommit, 1); | 66 internal::kHistogramAbortNewNavigationBeforeCommit, 1); |
49 } | 67 } |
50 | 68 |
51 TEST_F(AbortsPageLoadMetricsObserverTest, NewNavigationBeforePaint) { | 69 TEST_F(AbortsPageLoadMetricsObserverTest, NewNavigationBeforePaint) { |
52 NavigateAndCommit(GURL("https://www.google.com")); | 70 NavigateAndCommit(GURL("https://www.google.com")); |
53 SimulateTimingWithoutPaint(); | 71 SimulateTimingWithoutPaint(); |
54 // Simulate the user performing another navigation before paint. | 72 // Simulate the user performing another navigation before paint. |
55 NavigateAndCommit(GURL("https://www.example.com")); | 73 NavigateAndCommit(GURL("https://www.example.com")); |
56 histogram_tester().ExpectTotalCount( | 74 histogram_tester().ExpectTotalCount( |
57 internal::kHistogramAbortNewNavigationBeforePaint, 1); | 75 internal::kHistogramAbortNewNavigationBeforePaint, 1); |
58 histogram_tester().ExpectTotalCount( | 76 histogram_tester().ExpectTotalCount( |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 229 |
212 NavigateAndCommit(GURL("https://www.example.com")); | 230 NavigateAndCommit(GURL("https://www.example.com")); |
213 | 231 |
214 base::HistogramTester::CountsMap counts_map = | 232 base::HistogramTester::CountsMap counts_map = |
215 histogram_tester().GetTotalCountsForPrefix( | 233 histogram_tester().GetTotalCountsForPrefix( |
216 internal::kHistogramAbortNewNavigationBeforePaint); | 234 internal::kHistogramAbortNewNavigationBeforePaint); |
217 | 235 |
218 EXPECT_TRUE(counts_map.empty() || | 236 EXPECT_TRUE(counts_map.empty() || |
219 (counts_map.size() == 1 && counts_map.begin()->second == 1)); | 237 (counts_map.size() == 1 && counts_map.begin()->second == 1)); |
220 } | 238 } |
OLD | NEW |