| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 STYLE_UPDATE_BEFORE_FCP = 1 << 2 | 49 STYLE_UPDATE_BEFORE_FCP = 1 << 2 |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host) | 52 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host) |
| 53 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) { | 53 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) { |
| 54 render_widget_host->GetProcess()->AddFilter(this); | 54 render_widget_host->GetProcess()->AddFilter(this); |
| 55 | 55 |
| 56 // Roundtrip to the IO thread, to ensure that the filter is properly | 56 // Roundtrip to the IO thread, to ensure that the filter is properly |
| 57 // installed. | 57 // installed. |
| 58 content::BrowserThread::PostTaskAndReply( | 58 content::BrowserThread::PostTaskAndReply( |
| 59 content::BrowserThread::IO, FROM_HERE, base::Bind(&base::DoNothing), | 59 content::BrowserThread::IO, FROM_HERE, base::BindOnce(&base::DoNothing), |
| 60 base::Bind(&TimingUpdatedObserver::Quit, this)); | 60 base::BindOnce(&TimingUpdatedObserver::Quit, this)); |
| 61 run_loop_.reset(new base::RunLoop()); | 61 run_loop_.reset(new base::RunLoop()); |
| 62 run_loop_->Run(); | 62 run_loop_->Run(); |
| 63 run_loop_.reset(nullptr); | 63 run_loop_.reset(nullptr); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Add the given timing fields to the set of fields to match on. | 66 // Add the given timing fields to the set of fields to match on. |
| 67 void AddMatchingFields(ExpectedTimingFields fields) { | 67 void AddMatchingFields(ExpectedTimingFields fields) { |
| 68 matching_fields_ |= fields; | 68 matching_fields_ |= fields; |
| 69 } | 69 } |
| 70 | 70 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 timing.paint_timing.first_paint) && | 115 timing.paint_timing.first_paint) && |
| 116 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || | 116 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || |
| 117 timing.paint_timing.first_contentful_paint) && | 117 timing.paint_timing.first_contentful_paint) && |
| 118 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) || | 118 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) || |
| 119 timing.style_sheet_timing.update_style_duration_before_fcp)) { | 119 timing.style_sheet_timing.update_style_duration_before_fcp)) { |
| 120 // Ensure that any other handlers of this message, for example the real | 120 // Ensure that any other handlers of this message, for example the real |
| 121 // PageLoadMetric observers, get a chance to handle this message before | 121 // PageLoadMetric observers, get a chance to handle this message before |
| 122 // this waiter unblocks. | 122 // this waiter unblocks. |
| 123 content::BrowserThread::PostTask( | 123 content::BrowserThread::PostTask( |
| 124 content::BrowserThread::IO, FROM_HERE, | 124 content::BrowserThread::IO, FROM_HERE, |
| 125 base::Bind(&TimingUpdatedObserver::BounceTimingUpdate, this, timing, | 125 base::BindOnce(&TimingUpdatedObserver::BounceTimingUpdate, this, |
| 126 metadata)); | 126 timing, metadata)); |
| 127 } | 127 } |
| 128 return true; | 128 return true; |
| 129 } | 129 } |
| 130 | 130 |
| 131 void BounceTimingUpdate(const page_load_metrics::PageLoadTiming& timing, | 131 void BounceTimingUpdate(const page_load_metrics::PageLoadTiming& timing, |
| 132 const page_load_metrics::PageLoadMetadata& metadata) { | 132 const page_load_metrics::PageLoadMetadata& metadata) { |
| 133 content::BrowserThread::PostTask( | 133 content::BrowserThread::PostTask( |
| 134 content::BrowserThread::UI, FROM_HERE, | 134 content::BrowserThread::UI, FROM_HERE, |
| 135 base::Bind(&TimingUpdatedObserver::SetTimingUpdatedAndQuit, this)); | 135 base::BindOnce(&TimingUpdatedObserver::SetTimingUpdatedAndQuit, this)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void Quit() { | 138 void Quit() { |
| 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 140 if (run_loop_) | 140 if (run_loop_) |
| 141 run_loop_->Quit(); | 141 run_loop_->Quit(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void SetTimingUpdatedAndQuit() { | 144 void SetTimingUpdatedAndQuit() { |
| 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, ChromeErrorPage) { | 292 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, ChromeErrorPage) { |
| 293 ASSERT_TRUE(embedded_test_server()->Start()); | 293 ASSERT_TRUE(embedded_test_server()->Start()); |
| 294 | 294 |
| 295 // Configure the network stack to fail all attempted loads with a network | 295 // Configure the network stack to fail all attempted loads with a network |
| 296 // error, which will cause Chrome to display an error page. | 296 // error, which will cause Chrome to display an error page. |
| 297 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = | 297 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = |
| 298 browser()->profile()->GetRequestContext(); | 298 browser()->profile()->GetRequestContext(); |
| 299 content::BrowserThread::PostTask( | 299 content::BrowserThread::PostTask( |
| 300 content::BrowserThread::IO, FROM_HERE, | 300 content::BrowserThread::IO, FROM_HERE, |
| 301 base::Bind(&FailAllNetworkTransactions, | 301 base::BindOnce(&FailAllNetworkTransactions, |
| 302 base::RetainedRef(url_request_context_getter))); | 302 base::RetainedRef(url_request_context_getter))); |
| 303 | 303 |
| 304 ui_test_utils::NavigateToURL(browser(), | 304 ui_test_utils::NavigateToURL(browser(), |
| 305 embedded_test_server()->GetURL("/title1.html")); | 305 embedded_test_server()->GetURL("/title1.html")); |
| 306 NavigateToUntrackedUrl(); | 306 NavigateToUntrackedUrl(); |
| 307 EXPECT_TRUE(NoPageLoadMetricsRecorded()); | 307 EXPECT_TRUE(NoPageLoadMetricsRecorded()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, Ignore204Pages) { | 310 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, Ignore204Pages) { |
| 311 ASSERT_TRUE(embedded_test_server()->Start()); | 311 ASSERT_TRUE(embedded_test_server()->Start()); |
| 312 | 312 |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( | 783 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
| 784 "/page_load_metrics/large.html")); | 784 "/page_load_metrics/large.html")); |
| 785 NavigateToUntrackedUrl(); | 785 NavigateToUntrackedUrl(); |
| 786 | 786 |
| 787 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); | 787 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); |
| 788 | 788 |
| 789 // 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 |
| 790 // of the main HTML response). | 790 // of the main HTML response). |
| 791 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); | 791 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); |
| 792 } | 792 } |
| OLD | NEW |