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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 9 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
10 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob
server.h" | 10 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob
server.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "content/public/test/download_test_observer.h" | 31 #include "content/public/test/download_test_observer.h" |
32 #include "net/http/failing_http_transaction_factory.h" | 32 #include "net/http/failing_http_transaction_factory.h" |
33 #include "net/http/http_cache.h" | 33 #include "net/http/http_cache.h" |
34 #include "net/test/embedded_test_server/embedded_test_server.h" | 34 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 #include "net/test/url_request/url_request_failed_job.h" | 35 #include "net/test/url_request/url_request_failed_job.h" |
36 #include "net/url_request/url_request_context.h" | 36 #include "net/url_request/url_request_context.h" |
37 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 // Waits until specified timing and metadata expectations are satisfied. | 41 // Waits until a PageLoadMetricsMsg_TimingUpdated message IPC is received |
42 class PageLoadMetricsWaiter | 42 // matching a PageLoadTiming. See WaitForMatchingIPC for details. |
43 : public page_load_metrics::MetricsWebContentsObserver::TestingObserver { | 43 class TimingUpdatedObserver : public content::BrowserMessageFilter { |
44 public: | 44 public: |
45 // A bitvector to express which timing fields to match on. | 45 // A bitvector to express which timing fields to match on. |
46 enum ExpectedTimingFields { | 46 enum ExpectedTimingFields { |
47 FIRST_PAINT = 1 << 0, | 47 FIRST_PAINT = 1 << 0, |
48 FIRST_CONTENTFUL_PAINT = 1 << 1, | 48 FIRST_CONTENTFUL_PAINT = 1 << 1, |
49 STYLE_UPDATE_BEFORE_FCP = 1 << 2 | 49 STYLE_UPDATE_BEFORE_FCP = 1 << 2 |
50 }; | 50 }; |
51 | 51 |
52 explicit PageLoadMetricsWaiter(content::WebContents* web_contents) | 52 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host) |
53 : TestingObserver(web_contents) {} | 53 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) { |
| 54 render_widget_host->GetProcess()->AddFilter(this); |
54 | 55 |
55 ~PageLoadMetricsWaiter() override { DCHECK_EQ(nullptr, run_loop_.get()); } | 56 // Roundtrip to the IO thread, to ensure that the filter is properly |
| 57 // installed. |
| 58 content::BrowserThread::PostTaskAndReply( |
| 59 content::BrowserThread::IO, FROM_HERE, base::BindOnce(&base::DoNothing), |
| 60 base::BindOnce(&TimingUpdatedObserver::Quit, this)); |
| 61 run_loop_.reset(new base::RunLoop()); |
| 62 run_loop_->Run(); |
| 63 run_loop_.reset(nullptr); |
| 64 } |
56 | 65 |
57 // Add the given expectation to match on. | 66 // Add the given timing fields to the set of fields to match on. |
58 void AddExpectation(ExpectedTimingFields fields) { | 67 void AddMatchingFields(ExpectedTimingFields fields) { |
59 matching_fields_ |= fields; | 68 matching_fields_ |= fields; |
60 } | 69 } |
61 | 70 |
62 // Instructs observer to also watch for |count| | 71 // Instructs observer to also watch for |count| |
63 // WebLoadingBehaviorDocumentWriteBlockReload events. | 72 // WebLoadingBehaviorDocumentWriteBlockReload events. |
64 void ExpectDocumentWriteBlockReload(int count) { | 73 void MatchDocumentWriteBlockReload(int count) { |
65 match_document_write_block_reload_ = count; | 74 match_document_write_block_reload_ = count; |
66 } | 75 } |
67 | 76 |
68 // Waits for a TimingUpdated IPC that matches the fields set by | 77 // Waits for a TimingUpdated IPC that matches the fields set by |
69 // |AddExpectation|. All matching fields must be set in a TimingUpdated | 78 // |AddMatchingFields|. All matching fields must be set in a TimingUpdated |
70 // IPC for it to end this wait. | 79 // IPC for it to end this wait. |
71 void Wait() { | 80 void WaitForMatchingIPC() { |
72 if (expectations_satisfied_) | 81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 82 if (matched_timing_update_) |
73 return; | 83 return; |
74 | 84 |
75 run_loop_.reset(new base::RunLoop()); | 85 run_loop_.reset(new base::RunLoop()); |
76 run_loop_->Run(); | 86 run_loop_->Run(); |
77 run_loop_.reset(nullptr); | 87 run_loop_.reset(nullptr); |
78 | |
79 EXPECT_TRUE(expectations_satisfied_); | |
80 } | 88 } |
81 | 89 |
82 private: | 90 private: |
83 void OnTimingUpdated( | 91 bool OnMessageReceived(const IPC::Message& message) override { |
84 const page_load_metrics::PageLoadTiming& timing, | 92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
85 const page_load_metrics::PageLoadMetadata& metadata) override { | 93 |
| 94 IPC_BEGIN_MESSAGE_MAP(TimingUpdatedObserver, message) |
| 95 IPC_MESSAGE_HANDLER(PageLoadMetricsMsg_TimingUpdated, OnTimingUpdated) |
| 96 IPC_END_MESSAGE_MAP() |
| 97 |
| 98 return false; |
| 99 } |
| 100 |
| 101 bool OnTimingUpdated(const page_load_metrics::PageLoadTiming& timing, |
| 102 const page_load_metrics::PageLoadMetadata& metadata) { |
86 if (match_document_write_block_reload_ > 0 && | 103 if (match_document_write_block_reload_ > 0 && |
87 metadata.behavior_flags & | 104 metadata.behavior_flags & |
88 blink::WebLoadingBehaviorFlag:: | 105 blink::WebLoadingBehaviorFlag:: |
89 kWebLoadingBehaviorDocumentWriteBlockReload) { | 106 kWebLoadingBehaviorDocumentWriteBlockReload) { |
90 --match_document_write_block_reload_; | 107 --match_document_write_block_reload_; |
91 } | 108 } |
92 | 109 |
93 if (match_document_write_block_reload_ > 0) { | 110 if (match_document_write_block_reload_ > 0) { |
94 return; | 111 return true; |
95 } | 112 } |
96 | 113 |
97 if ((!(matching_fields_ & FIRST_PAINT) || | 114 if ((!(matching_fields_ & FIRST_PAINT) || |
98 timing.paint_timing.first_paint) && | 115 timing.paint_timing.first_paint) && |
99 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || | 116 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || |
100 timing.paint_timing.first_contentful_paint) && | 117 timing.paint_timing.first_contentful_paint) && |
101 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) || | 118 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) || |
102 timing.style_sheet_timing.update_style_duration_before_fcp)) { | 119 timing.style_sheet_timing.update_style_duration_before_fcp)) { |
103 expectations_satisfied_ = true; | 120 // Ensure that any other handlers of this message, for example the real |
104 if (run_loop_) | 121 // PageLoadMetric observers, get a chance to handle this message before |
105 run_loop_->Quit(); | 122 // this waiter unblocks. |
| 123 content::BrowserThread::PostTask( |
| 124 content::BrowserThread::IO, FROM_HERE, |
| 125 base::BindOnce(&TimingUpdatedObserver::BounceTimingUpdate, this, |
| 126 timing, metadata)); |
106 } | 127 } |
| 128 return true; |
107 } | 129 } |
108 | 130 |
| 131 void BounceTimingUpdate(const page_load_metrics::PageLoadTiming& timing, |
| 132 const page_load_metrics::PageLoadMetadata& metadata) { |
| 133 content::BrowserThread::PostTask( |
| 134 content::BrowserThread::UI, FROM_HERE, |
| 135 base::BindOnce(&TimingUpdatedObserver::SetTimingUpdatedAndQuit, this)); |
| 136 } |
| 137 |
| 138 void Quit() { |
| 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 140 if (run_loop_) |
| 141 run_loop_->Quit(); |
| 142 } |
| 143 |
| 144 void SetTimingUpdatedAndQuit() { |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 146 matched_timing_update_ = true; |
| 147 Quit(); |
| 148 } |
| 149 |
| 150 ~TimingUpdatedObserver() override {} |
| 151 |
109 std::unique_ptr<base::RunLoop> run_loop_; | 152 std::unique_ptr<base::RunLoop> run_loop_; |
110 int matching_fields_ = 0; // A bitvector composed from ExpectedTimingFields. | 153 int matching_fields_ = 0; // A bitvector composed from ExpectedTimingFields. |
111 bool expectations_satisfied_ = false; | 154 bool matched_timing_update_ = false; |
112 int match_document_write_block_reload_ = 0; | 155 int match_document_write_block_reload_ = 0; |
113 }; | 156 }; |
114 | 157 |
115 } // namespace | 158 } // namespace |
116 | 159 |
117 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { | 160 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { |
118 public: | 161 public: |
119 PageLoadMetricsBrowserTest() {} | 162 PageLoadMetricsBrowserTest() {} |
120 ~PageLoadMetricsBrowserTest() override {} | 163 ~PageLoadMetricsBrowserTest() override {} |
121 | 164 |
122 protected: | 165 protected: |
123 void NavigateToUntrackedUrl() { | 166 void NavigateToUntrackedUrl() { |
124 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 167 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
125 } | 168 } |
126 | 169 |
127 bool NoPageLoadMetricsRecorded() { | 170 bool NoPageLoadMetricsRecorded() { |
128 // Determine whether any 'public' page load metrics are recorded. We exclude | 171 // Determine whether any 'public' page load metrics are recorded. We exclude |
129 // 'internal' metrics as these may be recorded for debugging purposes. | 172 // 'internal' metrics as these may be recorded for debugging purposes. |
130 size_t total_pageload_histograms = | 173 size_t total_pageload_histograms = |
131 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); | 174 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); |
132 size_t total_internal_histograms = | 175 size_t total_internal_histograms = |
133 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); | 176 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); |
134 DCHECK_GE(total_pageload_histograms, total_internal_histograms); | 177 DCHECK_GE(total_pageload_histograms, total_internal_histograms); |
135 return total_pageload_histograms - total_internal_histograms == 0; | 178 return total_pageload_histograms - total_internal_histograms == 0; |
136 } | 179 } |
137 | 180 |
138 std::unique_ptr<PageLoadMetricsWaiter> CreatePageLoadMetricsWaiter() { | 181 scoped_refptr<TimingUpdatedObserver> CreateTimingUpdatedObserver() { |
139 content::WebContents* web_contents = | 182 content::WebContents* web_contents = |
140 browser()->tab_strip_model()->GetActiveWebContents(); | 183 browser()->tab_strip_model()->GetActiveWebContents(); |
141 return base::MakeUnique<PageLoadMetricsWaiter>(web_contents); | 184 scoped_refptr<TimingUpdatedObserver> observer(new TimingUpdatedObserver( |
| 185 web_contents->GetRenderViewHost()->GetWidget())); |
| 186 return observer; |
142 } | 187 } |
143 | 188 |
144 base::HistogramTester histogram_tester_; | 189 base::HistogramTester histogram_tester_; |
145 | 190 |
146 private: | 191 private: |
147 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsBrowserTest); | 192 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsBrowserTest); |
148 }; | 193 }; |
149 | 194 |
150 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { | 195 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { |
151 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 196 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 browser(), embedded_test_server()->GetURL("/download-test3.gif")); | 332 browser(), embedded_test_server()->GetURL("/download-test3.gif")); |
288 downloads_observer.WaitForFinished(); | 333 downloads_observer.WaitForFinished(); |
289 | 334 |
290 NavigateToUntrackedUrl(); | 335 NavigateToUntrackedUrl(); |
291 EXPECT_TRUE(NoPageLoadMetricsRecorded()); | 336 EXPECT_TRUE(NoPageLoadMetricsRecorded()); |
292 } | 337 } |
293 | 338 |
294 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PreloadDocumentWrite) { | 339 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PreloadDocumentWrite) { |
295 ASSERT_TRUE(embedded_test_server()->Start()); | 340 ASSERT_TRUE(embedded_test_server()->Start()); |
296 | 341 |
297 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 342 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
298 CreatePageLoadMetricsWaiter(); | 343 CreateTimingUpdatedObserver(); |
299 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 344 fcp_observer->AddMatchingFields( |
| 345 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
300 | 346 |
301 ui_test_utils::NavigateToURL( | 347 ui_test_utils::NavigateToURL( |
302 browser(), embedded_test_server()->GetURL( | 348 browser(), embedded_test_server()->GetURL( |
303 "/page_load_metrics/document_write_external_script.html")); | 349 "/page_load_metrics/document_write_external_script.html")); |
304 fcp_waiter->Wait(); | 350 fcp_observer->WaitForMatchingIPC(); |
305 | 351 |
306 histogram_tester_.ExpectTotalCount( | 352 histogram_tester_.ExpectTotalCount( |
307 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1); | 353 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1); |
308 } | 354 } |
309 | 355 |
310 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPreloadDocumentWrite) { | 356 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPreloadDocumentWrite) { |
311 ASSERT_TRUE(embedded_test_server()->Start()); | 357 ASSERT_TRUE(embedded_test_server()->Start()); |
312 | 358 |
313 ui_test_utils::NavigateToURL( | 359 ui_test_utils::NavigateToURL( |
314 browser(), embedded_test_server()->GetURL( | 360 browser(), embedded_test_server()->GetURL( |
315 "/page_load_metrics/document_write_no_script.html")); | 361 "/page_load_metrics/document_write_no_script.html")); |
316 NavigateToUntrackedUrl(); | 362 NavigateToUntrackedUrl(); |
317 | 363 |
318 histogram_tester_.ExpectTotalCount( | 364 histogram_tester_.ExpectTotalCount( |
319 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); | 365 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); |
320 } | 366 } |
321 | 367 |
322 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWrite) { | 368 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWrite) { |
323 ASSERT_TRUE(embedded_test_server()->Start()); | 369 ASSERT_TRUE(embedded_test_server()->Start()); |
324 | 370 |
325 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 371 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
326 CreatePageLoadMetricsWaiter(); | 372 CreateTimingUpdatedObserver(); |
327 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 373 fcp_observer->AddMatchingFields( |
| 374 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
328 | 375 |
329 ui_test_utils::NavigateToURL(browser(), | 376 ui_test_utils::NavigateToURL(browser(), |
330 embedded_test_server()->GetURL("/title1.html")); | 377 embedded_test_server()->GetURL("/title1.html")); |
331 fcp_waiter->Wait(); | 378 fcp_observer->WaitForMatchingIPC(); |
332 | 379 |
333 histogram_tester_.ExpectTotalCount( | 380 histogram_tester_.ExpectTotalCount( |
334 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); | 381 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); |
335 histogram_tester_.ExpectTotalCount( | 382 histogram_tester_.ExpectTotalCount( |
336 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); | 383 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); |
337 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); | 384 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); |
338 } | 385 } |
339 | 386 |
340 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteBlock) { | 387 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteBlock) { |
341 ASSERT_TRUE(embedded_test_server()->Start()); | 388 ASSERT_TRUE(embedded_test_server()->Start()); |
342 | 389 |
343 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 390 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
344 CreatePageLoadMetricsWaiter(); | 391 CreateTimingUpdatedObserver(); |
345 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 392 fcp_observer->AddMatchingFields( |
| 393 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
346 | 394 |
347 ui_test_utils::NavigateToURL( | 395 ui_test_utils::NavigateToURL( |
348 browser(), embedded_test_server()->GetURL( | 396 browser(), embedded_test_server()->GetURL( |
349 "/page_load_metrics/document_write_script_block.html")); | 397 "/page_load_metrics/document_write_script_block.html")); |
350 fcp_waiter->Wait(); | 398 fcp_observer->WaitForMatchingIPC(); |
351 | 399 |
352 histogram_tester_.ExpectTotalCount( | 400 histogram_tester_.ExpectTotalCount( |
353 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); | 401 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); |
354 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); | 402 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); |
355 } | 403 } |
356 | 404 |
357 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteReload) { | 405 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteReload) { |
358 ASSERT_TRUE(embedded_test_server()->Start()); | 406 ASSERT_TRUE(embedded_test_server()->Start()); |
359 | 407 |
360 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 408 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
361 CreatePageLoadMetricsWaiter(); | 409 CreateTimingUpdatedObserver(); |
362 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 410 fcp_observer->AddMatchingFields( |
363 std::unique_ptr<PageLoadMetricsWaiter> reload_waiter = | 411 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
364 CreatePageLoadMetricsWaiter(); | 412 scoped_refptr<TimingUpdatedObserver> reload_observer = |
365 reload_waiter->ExpectDocumentWriteBlockReload(2); | 413 CreateTimingUpdatedObserver(); |
| 414 reload_observer->MatchDocumentWriteBlockReload(2); |
366 | 415 |
367 ui_test_utils::NavigateToURL( | 416 ui_test_utils::NavigateToURL( |
368 browser(), embedded_test_server()->GetURL( | 417 browser(), embedded_test_server()->GetURL( |
369 "/page_load_metrics/document_write_script_block.html")); | 418 "/page_load_metrics/document_write_script_block.html")); |
370 | 419 |
371 // Reload should not log the histogram as the script is not blocked. | 420 // Reload should not log the histogram as the script is not blocked. |
372 ui_test_utils::NavigateToURL( | 421 ui_test_utils::NavigateToURL( |
373 browser(), embedded_test_server()->GetURL( | 422 browser(), embedded_test_server()->GetURL( |
374 "/page_load_metrics/document_write_script_block.html")); | 423 "/page_load_metrics/document_write_script_block.html")); |
375 | 424 |
376 ui_test_utils::NavigateToURL( | 425 ui_test_utils::NavigateToURL( |
377 browser(), embedded_test_server()->GetURL( | 426 browser(), embedded_test_server()->GetURL( |
378 "/page_load_metrics/document_write_script_block.html")); | 427 "/page_load_metrics/document_write_script_block.html")); |
379 | 428 |
380 histogram_tester_.ExpectTotalCount( | 429 histogram_tester_.ExpectTotalCount( |
381 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); | 430 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); |
382 | 431 |
383 fcp_waiter->Wait(); | 432 fcp_observer->WaitForMatchingIPC(); |
384 reload_waiter->Wait(); | 433 reload_observer->WaitForMatchingIPC(); |
385 | 434 |
386 histogram_tester_.ExpectTotalCount( | 435 histogram_tester_.ExpectTotalCount( |
387 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); | 436 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); |
388 | 437 |
389 histogram_tester_.ExpectTotalCount( | 438 histogram_tester_.ExpectTotalCount( |
390 internal::kHistogramDocWriteBlockReloadCount, 2); | 439 internal::kHistogramDocWriteBlockReloadCount, 2); |
391 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); | 440 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); |
392 } | 441 } |
393 | 442 |
394 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteAsync) { | 443 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteAsync) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 | 481 |
433 // TODO(crbug.com/712935): Flaky on Linux dbg. | 482 // TODO(crbug.com/712935): Flaky on Linux dbg. |
434 #if defined(OS_LINUX) && !defined(NDEBUG) | 483 #if defined(OS_LINUX) && !defined(NDEBUG) |
435 #define MAYBE_BadXhtml DISABLED_BadXhtml | 484 #define MAYBE_BadXhtml DISABLED_BadXhtml |
436 #else | 485 #else |
437 #define MAYBE_BadXhtml BadXhtml | 486 #define MAYBE_BadXhtml BadXhtml |
438 #endif | 487 #endif |
439 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_BadXhtml) { | 488 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_BadXhtml) { |
440 ASSERT_TRUE(embedded_test_server()->Start()); | 489 ASSERT_TRUE(embedded_test_server()->Start()); |
441 | 490 |
442 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter = | 491 scoped_refptr<TimingUpdatedObserver> timing_observer = |
443 CreatePageLoadMetricsWaiter(); | 492 CreateTimingUpdatedObserver(); |
444 timing_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_PAINT); | 493 timing_observer->AddMatchingFields(TimingUpdatedObserver::FIRST_PAINT); |
445 | 494 |
446 // When an XHTML page contains invalid XML, it causes a paint of the error | 495 // When an XHTML page contains invalid XML, it causes a paint of the error |
447 // message without a layout. Page load metrics currently treats this as an | 496 // message without a layout. Page load metrics currently treats this as an |
448 // error. Eventually, we'll fix this by special casing the handling of | 497 // error. Eventually, we'll fix this by special casing the handling of |
449 // documents with non-well-formed XML on the blink side. See crbug.com/627607 | 498 // documents with non-well-formed XML on the blink side. See crbug.com/627607 |
450 // for more. | 499 // for more. |
451 ui_test_utils::NavigateToURL( | 500 ui_test_utils::NavigateToURL( |
452 browser(), | 501 browser(), |
453 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml")); | 502 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml")); |
454 | 503 |
455 timing_waiter->Wait(); | 504 timing_observer->WaitForMatchingIPC(); |
456 | 505 |
457 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0); | 506 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0); |
458 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); | 507 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); |
459 histogram_tester_.ExpectTotalCount(page_load_metrics::internal::kErrorEvents, | 508 histogram_tester_.ExpectTotalCount(page_load_metrics::internal::kErrorEvents, |
460 1); | 509 1); |
461 histogram_tester_.ExpectBucketCount( | 510 histogram_tester_.ExpectBucketCount( |
462 page_load_metrics::internal::kErrorEvents, | 511 page_load_metrics::internal::kErrorEvents, |
463 page_load_metrics::ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); | 512 page_load_metrics::ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); |
464 | 513 |
465 histogram_tester_.ExpectTotalCount( | 514 histogram_tester_.ExpectTotalCount( |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 histogram_tester_.ExpectTotalCount( | 681 histogram_tester_.ExpectTotalCount( |
633 internal::kHistogramFirstMeaningfulPaint, 1); | 682 internal::kHistogramFirstMeaningfulPaint, 1); |
634 histogram_tester_.ExpectTotalCount( | 683 histogram_tester_.ExpectTotalCount( |
635 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); | 684 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); |
636 } | 685 } |
637 | 686 |
638 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, | 687 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, |
639 FirstMeaningfulPaintNotRecorded) { | 688 FirstMeaningfulPaintNotRecorded) { |
640 ASSERT_TRUE(embedded_test_server()->Start()); | 689 ASSERT_TRUE(embedded_test_server()->Start()); |
641 | 690 |
642 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 691 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
643 CreatePageLoadMetricsWaiter(); | 692 CreateTimingUpdatedObserver(); |
644 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 693 fcp_observer->AddMatchingFields( |
| 694 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
645 | 695 |
646 ui_test_utils::NavigateToURL( | 696 ui_test_utils::NavigateToURL( |
647 browser(), embedded_test_server()->GetURL( | 697 browser(), embedded_test_server()->GetURL( |
648 "/page_load_metrics/page_with_active_connections.html")); | 698 "/page_load_metrics/page_with_active_connections.html")); |
649 fcp_waiter->Wait(); | 699 fcp_observer->WaitForMatchingIPC(); |
650 | 700 |
651 // Navigate away before a FMP is reported. | 701 // Navigate away before a FMP is reported. |
652 NavigateToUntrackedUrl(); | 702 NavigateToUntrackedUrl(); |
653 | 703 |
654 histogram_tester_.ExpectUniqueSample( | 704 histogram_tester_.ExpectUniqueSample( |
655 internal::kHistogramFirstMeaningfulPaintStatus, | 705 internal::kHistogramFirstMeaningfulPaintStatus, |
656 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1); | 706 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1); |
657 histogram_tester_.ExpectTotalCount( | 707 histogram_tester_.ExpectTotalCount( |
658 internal::kHistogramFirstMeaningfulPaint, 0); | 708 internal::kHistogramFirstMeaningfulPaint, 0); |
659 histogram_tester_.ExpectTotalCount( | 709 histogram_tester_.ExpectTotalCount( |
660 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); | 710 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); |
661 } | 711 } |
662 | 712 |
663 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, | 713 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, |
664 NoStatePrefetchObserverCacheable) { | 714 NoStatePrefetchObserverCacheable) { |
665 ASSERT_TRUE(embedded_test_server()->Start()); | 715 ASSERT_TRUE(embedded_test_server()->Start()); |
666 | 716 |
667 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 717 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
668 CreatePageLoadMetricsWaiter(); | 718 CreateTimingUpdatedObserver(); |
669 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 719 fcp_observer->AddMatchingFields( |
| 720 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
670 | 721 |
671 ui_test_utils::NavigateToURL(browser(), | 722 ui_test_utils::NavigateToURL(browser(), |
672 embedded_test_server()->GetURL("/title1.html")); | 723 embedded_test_server()->GetURL("/title1.html")); |
673 | 724 |
674 fcp_waiter->Wait(); | 725 fcp_observer->WaitForMatchingIPC(); |
675 | 726 |
676 histogram_tester_.ExpectTotalCount( | 727 histogram_tester_.ExpectTotalCount( |
677 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0); | 728 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0); |
678 histogram_tester_.ExpectTotalCount( | 729 histogram_tester_.ExpectTotalCount( |
679 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1); | 730 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1); |
680 } | 731 } |
681 | 732 |
682 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, | 733 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, |
683 NoStatePrefetchObserverNoStore) { | 734 NoStatePrefetchObserverNoStore) { |
684 ASSERT_TRUE(embedded_test_server()->Start()); | 735 ASSERT_TRUE(embedded_test_server()->Start()); |
685 | 736 |
686 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 737 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
687 CreatePageLoadMetricsWaiter(); | 738 CreateTimingUpdatedObserver(); |
688 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); | 739 fcp_observer->AddMatchingFields( |
| 740 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); |
689 | 741 |
690 ui_test_utils::NavigateToURL(browser(), | 742 ui_test_utils::NavigateToURL(browser(), |
691 embedded_test_server()->GetURL("/nostore.html")); | 743 embedded_test_server()->GetURL("/nostore.html")); |
692 | 744 |
693 fcp_waiter->Wait(); | 745 fcp_observer->WaitForMatchingIPC(); |
694 | 746 |
695 histogram_tester_.ExpectTotalCount( | 747 histogram_tester_.ExpectTotalCount( |
696 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1); | 748 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1); |
697 histogram_tester_.ExpectTotalCount( | 749 histogram_tester_.ExpectTotalCount( |
698 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0); | 750 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0); |
699 } | 751 } |
700 | 752 |
701 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) { | 753 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) { |
702 ASSERT_TRUE(embedded_test_server()->Start()); | 754 ASSERT_TRUE(embedded_test_server()->Start()); |
703 | 755 |
704 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = | 756 scoped_refptr<TimingUpdatedObserver> fcp_observer = |
705 CreatePageLoadMetricsWaiter(); | 757 CreateTimingUpdatedObserver(); |
706 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::STYLE_UPDATE_BEFORE_FCP); | 758 fcp_observer->AddMatchingFields( |
| 759 TimingUpdatedObserver::STYLE_UPDATE_BEFORE_FCP); |
707 | 760 |
708 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here | 761 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here |
709 // must take >> 5us, otherwise we'll log 0 for the value and it will remain | 762 // must take >> 5us, otherwise we'll log 0 for the value and it will remain |
710 // unset here. | 763 // unset here. |
711 ui_test_utils::NavigateToURL( | 764 ui_test_utils::NavigateToURL( |
712 browser(), | 765 browser(), |
713 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html")); | 766 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html")); |
714 NavigateToUntrackedUrl(); | 767 NavigateToUntrackedUrl(); |
715 fcp_waiter->Wait(); | 768 fcp_observer->WaitForMatchingIPC(); |
716 | 769 |
717 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint, | 770 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint, |
718 1); | 771 1); |
719 histogram_tester_.ExpectTotalCount( | 772 histogram_tester_.ExpectTotalCount( |
720 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1); | 773 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1); |
721 histogram_tester_.ExpectTotalCount( | 774 histogram_tester_.ExpectTotalCount( |
722 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1); | 775 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1); |
723 histogram_tester_.ExpectTotalCount( | 776 histogram_tester_.ExpectTotalCount( |
724 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1); | 777 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1); |
725 } | 778 } |
726 | 779 |
727 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PayloadSize) { | 780 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PayloadSize) { |
728 ASSERT_TRUE(embedded_test_server()->Start()); | 781 ASSERT_TRUE(embedded_test_server()->Start()); |
729 | 782 |
730 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( | 783 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
731 "/page_load_metrics/large.html")); | 784 "/page_load_metrics/large.html")); |
732 NavigateToUntrackedUrl(); | 785 NavigateToUntrackedUrl(); |
733 | 786 |
734 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); | 787 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); |
735 | 788 |
736 // Verify that there is a single sample recorded in the 10kB bucket (the size | 789 // Verify that there is a single sample recorded in the 10kB bucket (the size |
737 // of the main HTML response). | 790 // of the main HTML response). |
738 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); | 791 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); |
739 } | 792 } |
OLD | NEW |