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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 internal::kHistogramAbortUnknownNavigationBeforeCommit, 1); | 29 internal::kHistogramAbortUnknownNavigationBeforeCommit, 1); |
30 } | 30 } |
31 | 31 |
32 TEST_F(AbortsPageLoadMetricsObserverTest, NewNavigationBeforePaint) { | 32 TEST_F(AbortsPageLoadMetricsObserverTest, NewNavigationBeforePaint) { |
33 NavigateAndCommit(GURL("https://www.google.com")); | 33 NavigateAndCommit(GURL("https://www.google.com")); |
34 SimulateTimingWithoutPaint(); | 34 SimulateTimingWithoutPaint(); |
35 // Simulate the user performing another navigation before paint. | 35 // Simulate the user performing another navigation before paint. |
36 NavigateAndCommit(GURL("https://www.example.com")); | 36 NavigateAndCommit(GURL("https://www.example.com")); |
37 histogram_tester().ExpectTotalCount( | 37 histogram_tester().ExpectTotalCount( |
38 internal::kHistogramAbortNewNavigationBeforePaint, 1); | 38 internal::kHistogramAbortNewNavigationBeforePaint, 1); |
| 39 histogram_tester().ExpectTotalCount( |
| 40 internal::kHistogramAbortReloadBeforePaint, 0); |
| 41 histogram_tester().ExpectTotalCount( |
| 42 internal::kHistogramAbortForwardBackBeforePaint, 0); |
| 43 } |
| 44 |
| 45 TEST_F(AbortsPageLoadMetricsObserverTest, ReloadBeforePaint) { |
| 46 NavigateAndCommit(GURL("https://www.example.com")); |
| 47 SimulateTimingWithoutPaint(); |
| 48 // Simulate the user performing a reload navigation before paint. |
| 49 NavigateWithPageTransitionAndCommit(GURL("https://www.google.com"), |
| 50 ui::PAGE_TRANSITION_RELOAD); |
| 51 histogram_tester().ExpectTotalCount( |
| 52 internal::kHistogramAbortReloadBeforePaint, 1); |
| 53 histogram_tester().ExpectTotalCount( |
| 54 internal::kHistogramAbortNewNavigationBeforePaint, 0); |
| 55 histogram_tester().ExpectTotalCount( |
| 56 internal::kHistogramAbortForwardBackBeforePaint, 0); |
| 57 } |
| 58 |
| 59 TEST_F(AbortsPageLoadMetricsObserverTest, ForwardBackBeforePaint) { |
| 60 NavigateAndCommit(GURL("https://www.example.com")); |
| 61 SimulateTimingWithoutPaint(); |
| 62 // Simulate the user performing a forward/back navigation before paint. |
| 63 NavigateWithPageTransitionAndCommit( |
| 64 GURL("https://www.google.com"), |
| 65 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | |
| 66 ui::PAGE_TRANSITION_FORWARD_BACK)); |
| 67 histogram_tester().ExpectTotalCount( |
| 68 internal::kHistogramAbortForwardBackBeforePaint, 1); |
| 69 histogram_tester().ExpectTotalCount( |
| 70 internal::kHistogramAbortNewNavigationBeforePaint, 0); |
| 71 histogram_tester().ExpectTotalCount( |
| 72 internal::kHistogramAbortReloadBeforePaint, 0); |
39 } | 73 } |
40 | 74 |
41 TEST_F(AbortsPageLoadMetricsObserverTest, StopBeforeCommit) { | 75 TEST_F(AbortsPageLoadMetricsObserverTest, StopBeforeCommit) { |
42 StartNavigation(GURL("https://www.google.com")); | 76 StartNavigation(GURL("https://www.google.com")); |
43 // Simulate the user pressing the stop button. | 77 // Simulate the user pressing the stop button. |
44 web_contents()->Stop(); | 78 web_contents()->Stop(); |
45 // Now close the tab. This will trigger logging for the prior navigation which | 79 // Now close the tab. This will trigger logging for the prior navigation which |
46 // was stopped above. | 80 // was stopped above. |
47 DeleteContents(); | 81 DeleteContents(); |
48 histogram_tester().ExpectTotalCount(internal::kHistogramAbortStopBeforeCommit, | 82 histogram_tester().ExpectTotalCount(internal::kHistogramAbortStopBeforeCommit, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 NavigateAndCommit(GURL("https://www.example.com")); | 152 NavigateAndCommit(GURL("https://www.example.com")); |
119 SimulateTimingWithoutPaint(); | 153 SimulateTimingWithoutPaint(); |
120 // Simulate closing the tab. | 154 // Simulate closing the tab. |
121 DeleteContents(); | 155 DeleteContents(); |
122 histogram_tester().ExpectTotalCount(internal::kHistogramAbortStopBeforeCommit, | 156 histogram_tester().ExpectTotalCount(internal::kHistogramAbortStopBeforeCommit, |
123 1); | 157 1); |
124 histogram_tester().ExpectTotalCount(internal::kHistogramAbortCloseBeforePaint, | 158 histogram_tester().ExpectTotalCount(internal::kHistogramAbortCloseBeforePaint, |
125 1); | 159 1); |
126 } | 160 } |
127 | 161 |
128 // TODO(bmcquade): add tests for reload, back/forward, and other aborts. | |
129 | |
130 TEST_F(AbortsPageLoadMetricsObserverTest, NoAbortNewNavigationFromAboutURL) { | 162 TEST_F(AbortsPageLoadMetricsObserverTest, NoAbortNewNavigationFromAboutURL) { |
131 NavigateAndCommit(GURL("about:blank")); | 163 NavigateAndCommit(GURL("about:blank")); |
132 NavigateAndCommit(GURL("https://www.example.com")); | 164 NavigateAndCommit(GURL("https://www.example.com")); |
133 histogram_tester().ExpectTotalCount( | 165 histogram_tester().ExpectTotalCount( |
134 internal::kHistogramAbortNewNavigationBeforePaint, 0); | 166 internal::kHistogramAbortNewNavigationBeforePaint, 0); |
135 } | 167 } |
136 | 168 |
137 TEST_F(AbortsPageLoadMetricsObserverTest, | 169 TEST_F(AbortsPageLoadMetricsObserverTest, |
138 NoAbortNewNavigationFromURLWithoutTiming) { | 170 NoAbortNewNavigationFromURLWithoutTiming) { |
139 NavigateAndCommit(GURL("https://www.google.com")); | 171 NavigateAndCommit(GURL("https://www.google.com")); |
(...skipping 20 matching lines...) Expand all Loading... |
160 | 192 |
161 NavigateAndCommit(GURL("https://www.example.com")); | 193 NavigateAndCommit(GURL("https://www.example.com")); |
162 | 194 |
163 base::HistogramTester::CountsMap counts_map = | 195 base::HistogramTester::CountsMap counts_map = |
164 histogram_tester().GetTotalCountsForPrefix( | 196 histogram_tester().GetTotalCountsForPrefix( |
165 internal::kHistogramAbortNewNavigationBeforePaint); | 197 internal::kHistogramAbortNewNavigationBeforePaint); |
166 | 198 |
167 EXPECT_TRUE(counts_map.empty() || | 199 EXPECT_TRUE(counts_map.empty() || |
168 (counts_map.size() == 1 && counts_map.begin()->second == 1)); | 200 (counts_map.size() == 1 && counts_map.begin()->second == 1)); |
169 } | 201 } |
OLD | NEW |