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

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

Issue 1961363003: Log an immediate variant of FirstContentfulPaint. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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 (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 <vector> 7 #include <vector>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 15 matching lines...) Expand all
26 26
27 const char kDefaultTestUrl[] = "https://google.com/"; 27 const char kDefaultTestUrl[] = "https://google.com/";
28 const char kDefaultTestUrlAnchor[] = "https://google.com/#samepage"; 28 const char kDefaultTestUrlAnchor[] = "https://google.com/#samepage";
29 const char kDefaultTestUrl2[] = "https://whatever.com/"; 29 const char kDefaultTestUrl2[] = "https://whatever.com/";
30 30
31 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the 31 // Simple PageLoadMetricsObserver that copies observed PageLoadTimings into the
32 // provided std::vector, so they can be analyzed by unit tests. 32 // provided std::vector, so they can be analyzed by unit tests.
33 class TestPageLoadMetricsObserver : public PageLoadMetricsObserver { 33 class TestPageLoadMetricsObserver : public PageLoadMetricsObserver {
34 public: 34 public:
35 explicit TestPageLoadMetricsObserver( 35 explicit TestPageLoadMetricsObserver(
36 std::vector<PageLoadTiming>* observed_timings, 36 std::vector<PageLoadTiming>* updated_timings,
37 std::vector<PageLoadTiming>* complete_timings,
37 std::vector<GURL>* observed_committed_urls) 38 std::vector<GURL>* observed_committed_urls)
38 : observed_timings_(observed_timings), 39 : updated_timings_(updated_timings),
40 complete_timings_(complete_timings),
39 observed_committed_urls_(observed_committed_urls) {} 41 observed_committed_urls_(observed_committed_urls) {}
40 42
41 void OnStart(content::NavigationHandle* navigation_handle, 43 void OnStart(content::NavigationHandle* navigation_handle,
42 const GURL& currently_committed_url) override { 44 const GURL& currently_committed_url) override {
43 observed_committed_urls_->push_back(currently_committed_url); 45 observed_committed_urls_->push_back(currently_committed_url);
44 } 46 }
45 47
48 void OnTimingUpdate(const PageLoadTiming& timing,
49 const PageLoadExtraInfo& extra_info) override {
50 updated_timings_->push_back(timing);
51 }
52
46 void OnComplete(const PageLoadTiming& timing, 53 void OnComplete(const PageLoadTiming& timing,
47 const PageLoadExtraInfo& extra_info) override { 54 const PageLoadExtraInfo& extra_info) override {
48 observed_timings_->push_back(timing); 55 complete_timings_->push_back(timing);
49 } 56 }
50 57
51 private: 58 private:
52 std::vector<PageLoadTiming>* const observed_timings_; 59 std::vector<PageLoadTiming>* const updated_timings_;
60 std::vector<PageLoadTiming>* const complete_timings_;
53 std::vector<GURL>* const observed_committed_urls_; 61 std::vector<GURL>* const observed_committed_urls_;
54 }; 62 };
55 63
56 class TestPageLoadMetricsEmbedderInterface 64 class TestPageLoadMetricsEmbedderInterface
57 : public PageLoadMetricsEmbedderInterface { 65 : public PageLoadMetricsEmbedderInterface {
58 public: 66 public:
59 TestPageLoadMetricsEmbedderInterface() : is_prerendering_(false) {} 67 TestPageLoadMetricsEmbedderInterface() : is_prerendering_(false) {}
60 68
61 bool IsPrerendering(content::WebContents* web_contents) override { 69 bool IsPrerendering(content::WebContents* web_contents) override {
62 return is_prerendering_; 70 return is_prerendering_;
63 } 71 }
64 void set_is_prerendering(bool is_prerendering) { 72 void set_is_prerendering(bool is_prerendering) {
65 is_prerendering_ = is_prerendering; 73 is_prerendering_ = is_prerendering;
66 } 74 }
67 void RegisterObservers(PageLoadTracker* tracker) override { 75 void RegisterObservers(PageLoadTracker* tracker) override {
68 tracker->AddObserver(make_scoped_ptr(new TestPageLoadMetricsObserver( 76 tracker->AddObserver(make_scoped_ptr(new TestPageLoadMetricsObserver(
69 &observed_timings_, &observed_committed_urls_))); 77 &updated_timings_, &complete_timings_, &observed_committed_urls_)));
70 } 78 }
71 const std::vector<PageLoadTiming>& observed_timings() const { 79 const std::vector<PageLoadTiming>& updated_timings() const {
72 return observed_timings_; 80 return updated_timings_;
81 }
82 const std::vector<PageLoadTiming>& complete_timings() const {
83 return complete_timings_;
73 } 84 }
74 85
75 // currently_committed_urls passed to OnStart(). 86 // currently_committed_urls passed to OnStart().
76 const std::vector<GURL>& observed_committed_urls_from_on_start() const { 87 const std::vector<GURL>& observed_committed_urls_from_on_start() const {
77 return observed_committed_urls_; 88 return observed_committed_urls_;
78 } 89 }
79 90
80 private: 91 private:
81 std::vector<PageLoadTiming> observed_timings_; 92 std::vector<PageLoadTiming> updated_timings_;
93 std::vector<PageLoadTiming> complete_timings_;
82 std::vector<GURL> observed_committed_urls_; 94 std::vector<GURL> observed_committed_urls_;
83 bool is_prerendering_; 95 bool is_prerendering_;
84 }; 96 };
85 97
86 } // namespace 98 } // namespace
87 99
88 class MetricsWebContentsObserverTest 100 class MetricsWebContentsObserverTest
89 : public content::RenderViewHostTestHarness { 101 : public content::RenderViewHostTestHarness {
90 public: 102 public:
91 MetricsWebContentsObserverTest() : num_errors_(0) {} 103 MetricsWebContentsObserverTest() : num_errors_(0) {}
(...skipping 29 matching lines...) Expand all
121 133
122 void CheckTotalErrorEvents() { 134 void CheckTotalErrorEvents() {
123 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_); 135 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, num_errors_);
124 } 136 }
125 137
126 void CheckNoErrorEvents() { 138 void CheckNoErrorEvents() {
127 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0); 139 histogram_tester_.ExpectTotalCount(internal::kErrorEvents, 0);
128 } 140 }
129 141
130 void AssertNoNonEmptyTimingReported() { 142 void AssertNoNonEmptyTimingReported() {
131 ASSERT_FALSE(embedder_interface_->observed_timings().empty()); 143 ASSERT_FALSE(embedder_interface_->complete_timings().empty());
132 for (const auto& timing : embedder_interface_->observed_timings()) { 144 for (const auto& timing : embedder_interface_->complete_timings()) {
133 ASSERT_TRUE(timing.IsEmpty()); 145 ASSERT_TRUE(timing.IsEmpty());
134 } 146 }
135 } 147 }
136 148
137 void AssertNonEmptyTimingsReported(size_t expected_non_empty_timings) { 149 void AssertNonEmptyTimingsReported(size_t expected_non_empty_timings) {
138 ASSERT_GE(embedder_interface_->observed_timings().size(), 150 ASSERT_GE(embedder_interface_->complete_timings().size(),
139 expected_non_empty_timings); 151 expected_non_empty_timings);
140 size_t actual_non_empty_timings = 0; 152 size_t actual_non_empty_timings = 0;
141 for (const auto& timing : embedder_interface_->observed_timings()) { 153 for (const auto& timing : embedder_interface_->complete_timings()) {
142 if (!timing.IsEmpty()) { 154 if (!timing.IsEmpty()) {
143 ++actual_non_empty_timings; 155 ++actual_non_empty_timings;
144 } 156 }
145 } 157 }
146 ASSERT_EQ(expected_non_empty_timings, actual_non_empty_timings); 158 ASSERT_EQ(expected_non_empty_timings, actual_non_empty_timings);
159 ASSERT_GE(embedder_interface_->updated_timings().size(),
160 actual_non_empty_timings);
147 } 161 }
148 162
149 void AssertNoTimingReported() { 163 int CountCompleteTimingReported() {
150 ASSERT_TRUE(embedder_interface_->observed_timings().empty()); 164 return embedder_interface_->complete_timings().size();
165 }
166 int CountUpdatedTimingReported() {
167 return embedder_interface_->updated_timings().size();
151 } 168 }
152 169
153 const std::vector<GURL>& observed_committed_urls_from_on_start() const { 170 const std::vector<GURL>& observed_committed_urls_from_on_start() const {
154 return embedder_interface_->observed_committed_urls_from_on_start(); 171 return embedder_interface_->observed_committed_urls_from_on_start();
155 } 172 }
156 173
157 protected: 174 protected:
158 base::HistogramTester histogram_tester_; 175 base::HistogramTester histogram_tester_;
159 TestPageLoadMetricsEmbedderInterface* embedder_interface_; 176 TestPageLoadMetricsEmbedderInterface* embedder_interface_;
160 scoped_ptr<MetricsWebContentsObserver> observer_; 177 scoped_ptr<MetricsWebContentsObserver> observer_;
(...skipping 10 matching lines...) Expand all
171 timing.response_start = base::TimeDelta::FromMilliseconds(2); 188 timing.response_start = base::TimeDelta::FromMilliseconds(2);
172 189
173 content::WebContentsTester* web_contents_tester = 190 content::WebContentsTester* web_contents_tester =
174 content::WebContentsTester::For(web_contents()); 191 content::WebContentsTester::For(web_contents());
175 192
176 ASSERT_TRUE(observed_committed_urls_from_on_start().empty()); 193 ASSERT_TRUE(observed_committed_urls_from_on_start().empty());
177 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 194 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
178 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size()); 195 ASSERT_EQ(1u, observed_committed_urls_from_on_start().size());
179 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty()); 196 ASSERT_TRUE(observed_committed_urls_from_on_start().at(0).is_empty());
180 197
198 ASSERT_EQ(0, CountUpdatedTimingReported());
181 SimulateTimingUpdate(timing); 199 SimulateTimingUpdate(timing);
182 AssertNoTimingReported(); 200 ASSERT_EQ(1, CountUpdatedTimingReported());
201 ASSERT_EQ(0, CountCompleteTimingReported());
183 202
184 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); 203 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
185 AssertNonEmptyTimingsReported(1); 204 AssertNonEmptyTimingsReported(1);
186 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size()); 205 ASSERT_EQ(2u, observed_committed_urls_from_on_start().size());
187 ASSERT_EQ(kDefaultTestUrl, 206 ASSERT_EQ(kDefaultTestUrl,
188 observed_committed_urls_from_on_start().at(1).spec()); 207 observed_committed_urls_from_on_start().at(1).spec());
208 ASSERT_EQ(1, CountUpdatedTimingReported());
189 209
190 CheckNoErrorEvents(); 210 CheckNoErrorEvents();
191 } 211 }
192 212
193 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) { 213 TEST_F(MetricsWebContentsObserverTest, NotInMainFrame) {
194 PageLoadTiming timing; 214 PageLoadTiming timing;
195 timing.navigation_start = base::Time::FromDoubleT(1); 215 timing.navigation_start = base::Time::FromDoubleT(1);
196 216
197 content::WebContentsTester* web_contents_tester = 217 content::WebContentsTester* web_contents_tester =
198 content::WebContentsTester::For(web_contents()); 218 content::WebContentsTester::For(web_contents());
199 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 219 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
200 220
201 content::RenderFrameHostTester* rfh_tester = 221 content::RenderFrameHostTester* rfh_tester =
202 content::RenderFrameHostTester::For(main_rfh()); 222 content::RenderFrameHostTester::For(main_rfh());
203 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); 223 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe");
204 224
205 content::RenderFrameHostTester* subframe_tester = 225 content::RenderFrameHostTester* subframe_tester =
206 content::RenderFrameHostTester::For(subframe); 226 content::RenderFrameHostTester::For(subframe);
207 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); 227 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2));
208 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); 228 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2));
209 SimulateTimingUpdate(timing, subframe); 229 SimulateTimingUpdate(timing, subframe);
210 subframe_tester->SimulateNavigationStop(); 230 subframe_tester->SimulateNavigationStop();
211 231
212 // Navigate again to see if the timing updated for a subframe message. 232 // Navigate again to see if the timing updated for a subframe message.
213 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 233 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
214 234
235 ASSERT_EQ(0, CountUpdatedTimingReported());
215 AssertNoNonEmptyTimingReported(); 236 AssertNoNonEmptyTimingReported();
216 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); 237 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1);
217 CheckTotalErrorEvents(); 238 CheckTotalErrorEvents();
218 } 239 }
219 240
220 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) { 241 TEST_F(MetricsWebContentsObserverTest, SamePageNoTrigger) {
221 PageLoadTiming timing; 242 PageLoadTiming timing;
222 timing.navigation_start = base::Time::FromDoubleT(1); 243 timing.navigation_start = base::Time::FromDoubleT(1);
223 244
224 content::WebContentsTester* web_contents_tester = 245 content::WebContentsTester* web_contents_tester =
225 content::WebContentsTester::For(web_contents()); 246 content::WebContentsTester::For(web_contents());
226 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 247 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
248 ASSERT_EQ(0, CountUpdatedTimingReported());
227 SimulateTimingUpdate(timing); 249 SimulateTimingUpdate(timing);
250 ASSERT_EQ(1, CountUpdatedTimingReported());
228 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); 251 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor));
229 // A same page navigation shouldn't trigger logging UMA for the original. 252 // A same page navigation shouldn't trigger logging UMA for the original.
253 ASSERT_EQ(1, CountUpdatedTimingReported());
230 AssertNoNonEmptyTimingReported(); 254 AssertNoNonEmptyTimingReported();
231 CheckNoErrorEvents(); 255 CheckNoErrorEvents();
232 } 256 }
233 257
234 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { 258 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) {
235 PageLoadTiming timing; 259 PageLoadTiming timing;
236 timing.navigation_start = base::Time::FromDoubleT(1); 260 timing.navigation_start = base::Time::FromDoubleT(1);
237 261
238 content::WebContentsTester* web_contents_tester = 262 content::WebContentsTester* web_contents_tester =
239 content::WebContentsTester::For(web_contents()); 263 content::WebContentsTester::For(web_contents());
240 embedder_interface_->set_is_prerendering(true); 264 embedder_interface_->set_is_prerendering(true);
241 265
242 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 266 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
243 SimulateTimingUpdate(timing); 267 SimulateTimingUpdate(timing);
244 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); 268 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
245 AssertNoTimingReported(); 269 ASSERT_EQ(0, CountUpdatedTimingReported());
270 ASSERT_EQ(0, CountCompleteTimingReported());
246 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); 271 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1);
247 CheckTotalErrorEvents(); 272 CheckTotalErrorEvents();
248 } 273 }
249 274
250 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { 275 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) {
251 PageLoadTiming timing; 276 PageLoadTiming timing;
252 timing.navigation_start = base::Time::FromDoubleT(10); 277 timing.navigation_start = base::Time::FromDoubleT(10);
253 278
254 content::WebContentsTester* web_contents_tester = 279 content::WebContentsTester* web_contents_tester =
255 content::WebContentsTester::For(web_contents()); 280 content::WebContentsTester::For(web_contents());
256 281
257 GURL about_blank_url = GURL("about:blank"); 282 GURL about_blank_url = GURL("about:blank");
258 web_contents_tester->NavigateAndCommit(about_blank_url); 283 web_contents_tester->NavigateAndCommit(about_blank_url);
259 SimulateTimingUpdate(timing); 284 SimulateTimingUpdate(timing);
285 ASSERT_EQ(0, CountUpdatedTimingReported());
260 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 286 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
287 ASSERT_EQ(0, CountUpdatedTimingReported());
288 ASSERT_EQ(0, CountCompleteTimingReported());
261 289
262 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1); 290 CheckErrorEvent(ERR_IPC_FROM_BAD_URL_SCHEME, 1);
263 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); 291 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1);
264 CheckTotalErrorEvents(); 292 CheckTotalErrorEvents();
265 } 293 }
266 294
267 TEST_F(MetricsWebContentsObserverTest, NotInMainError) { 295 TEST_F(MetricsWebContentsObserverTest, NotInMainError) {
268 PageLoadTiming timing; 296 PageLoadTiming timing;
269 timing.navigation_start = base::Time::FromDoubleT(1); 297 timing.navigation_start = base::Time::FromDoubleT(1);
270 298
271 content::WebContentsTester* web_contents_tester = 299 content::WebContentsTester* web_contents_tester =
272 content::WebContentsTester::For(web_contents()); 300 content::WebContentsTester::For(web_contents());
273 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 301 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
274 302
275 content::RenderFrameHostTester* rfh_tester = 303 content::RenderFrameHostTester* rfh_tester =
276 content::RenderFrameHostTester::For(main_rfh()); 304 content::RenderFrameHostTester::For(main_rfh());
277 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe"); 305 content::RenderFrameHost* subframe = rfh_tester->AppendChild("subframe");
278 306
279 content::RenderFrameHostTester* subframe_tester = 307 content::RenderFrameHostTester* subframe_tester =
280 content::RenderFrameHostTester::For(subframe); 308 content::RenderFrameHostTester::For(subframe);
281 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2)); 309 subframe_tester->SimulateNavigationStart(GURL(kDefaultTestUrl2));
282 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); 310 subframe_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2));
283 SimulateTimingUpdate(timing, subframe); 311 SimulateTimingUpdate(timing, subframe);
284 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1); 312 CheckErrorEvent(ERR_IPC_FROM_WRONG_FRAME, 1);
285 CheckTotalErrorEvents(); 313 CheckTotalErrorEvents();
314 ASSERT_EQ(0, CountUpdatedTimingReported());
315 ASSERT_EQ(0, CountCompleteTimingReported());
286 } 316 }
287 317
288 TEST_F(MetricsWebContentsObserverTest, BadIPC) { 318 TEST_F(MetricsWebContentsObserverTest, BadIPC) {
289 PageLoadTiming timing; 319 PageLoadTiming timing;
290 timing.navigation_start = base::Time::FromDoubleT(10); 320 timing.navigation_start = base::Time::FromDoubleT(10);
291 PageLoadTiming timing2; 321 PageLoadTiming timing2;
292 timing2.navigation_start = base::Time::FromDoubleT(100); 322 timing2.navigation_start = base::Time::FromDoubleT(100);
293 323
294 content::WebContentsTester* web_contents_tester = 324 content::WebContentsTester* web_contents_tester =
295 content::WebContentsTester::For(web_contents()); 325 content::WebContentsTester::For(web_contents());
296 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); 326 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl));
297 327
298 SimulateTimingUpdate(timing); 328 SimulateTimingUpdate(timing);
329 ASSERT_EQ(1, CountUpdatedTimingReported());
299 SimulateTimingUpdate(timing2); 330 SimulateTimingUpdate(timing2);
331 ASSERT_EQ(1, CountUpdatedTimingReported());
300 332
301 CheckErrorEvent(ERR_BAD_TIMING_IPC, 1); 333 CheckErrorEvent(ERR_BAD_TIMING_IPC, 1);
302 CheckTotalErrorEvents(); 334 CheckTotalErrorEvents();
303 } 335 }
304 336
305 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) { 337 TEST_F(MetricsWebContentsObserverTest, ObservePartialNavigation) {
306 // Delete the observer for this test, add it once the navigation has started. 338 // Delete the observer for this test, add it once the navigation has started.
307 observer_.reset(); 339 observer_.reset();
308 PageLoadTiming timing; 340 PageLoadTiming timing;
309 timing.navigation_start = base::Time::FromDoubleT(10); 341 timing.navigation_start = base::Time::FromDoubleT(10);
310 342
311 content::WebContentsTester* web_contents_tester = 343 content::WebContentsTester* web_contents_tester =
312 content::WebContentsTester::For(web_contents()); 344 content::WebContentsTester::For(web_contents());
313 content::RenderFrameHostTester* rfh_tester = 345 content::RenderFrameHostTester* rfh_tester =
314 content::RenderFrameHostTester::For(main_rfh()); 346 content::RenderFrameHostTester::For(main_rfh());
315 347
316 // Start the navigation, then start observing the web contents. This used to 348 // Start the navigation, then start observing the web contents. This used to
317 // crash us. Make sure we bail out and don't log histograms. 349 // crash us. Make sure we bail out and don't log histograms.
318 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); 350 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl));
319 AttachObserver(); 351 AttachObserver();
320 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl)); 352 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl));
321 353
322 SimulateTimingUpdate(timing); 354 SimulateTimingUpdate(timing);
323 355
324 // Navigate again to force histogram logging. 356 // Navigate again to force histogram logging.
325 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); 357 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2));
326 AssertNoTimingReported(); 358 ASSERT_EQ(0, CountCompleteTimingReported());
359 ASSERT_EQ(0, CountUpdatedTimingReported());
327 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1); 360 CheckErrorEvent(ERR_IPC_WITH_NO_RELEVANT_LOAD, 1);
328 CheckTotalErrorEvents(); 361 CheckTotalErrorEvents();
329 } 362 }
330 363
331 TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) { 364 TEST_F(MetricsWebContentsObserverTest, DontLogAbortChains) {
332 NavigateAndCommit(GURL(kDefaultTestUrl)); 365 NavigateAndCommit(GURL(kDefaultTestUrl));
333 NavigateAndCommit(GURL(kDefaultTestUrl2)); 366 NavigateAndCommit(GURL(kDefaultTestUrl2));
334 NavigateAndCommit(GURL(kDefaultTestUrl)); 367 NavigateAndCommit(GURL(kDefaultTestUrl));
335 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0); 368 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNewNavigation, 0);
336 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 2); 369 CheckErrorEvent(ERR_NO_IPCS_RECEIVED, 2);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 rfh_tester->SimulateNavigationStop(); 440 rfh_tester->SimulateNavigationStop();
408 441
409 web_contents()->Stop(); 442 web_contents()->Stop();
410 443
411 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1); 444 histogram_tester_.ExpectTotalCount(internal::kAbortChainSizeNoCommit, 1);
412 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3, 445 histogram_tester_.ExpectBucketCount(internal::kAbortChainSizeNoCommit, 3,
413 1); 446 1);
414 } 447 }
415 448
416 } // namespace page_load_metrics 449 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698