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

Side by Side Diff: chrome/browser/page_load_metrics/page_load_metrics_browsertest.cc

Issue 2729893002: Page load metrics: improve flaky CSSTiming (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 27 matching lines...) Expand all
38 38
39 namespace { 39 namespace {
40 40
41 // Waits until a PageLoadMetricsMsg_TimingUpdated message IPC is received 41 // Waits until a PageLoadMetricsMsg_TimingUpdated message IPC is received
42 // matching a PageLoadTiming. See WaitForMatchingIPC for details. 42 // matching a PageLoadTiming. See WaitForMatchingIPC for details.
43 class TimingUpdatedObserver : public content::BrowserMessageFilter { 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 }; 50 };
50 51
51 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host) 52 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host)
52 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) { 53 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) {
53 render_widget_host->GetProcess()->AddFilter(this); 54 render_widget_host->GetProcess()->AddFilter(this);
54 55
55 // 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
56 // installed. 57 // installed.
57 content::BrowserThread::PostTaskAndReply( 58 content::BrowserThread::PostTaskAndReply(
58 content::BrowserThread::IO, FROM_HERE, base::Bind(&base::DoNothing), 59 content::BrowserThread::IO, FROM_HERE, base::Bind(&base::DoNothing),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 WebLoadingBehaviorDocumentWriteBlockReload) { 106 WebLoadingBehaviorDocumentWriteBlockReload) {
106 --match_document_write_block_reload_; 107 --match_document_write_block_reload_;
107 } 108 }
108 109
109 if (match_document_write_block_reload_ > 0) { 110 if (match_document_write_block_reload_ > 0) {
110 return true; 111 return true;
111 } 112 }
112 113
113 if ((!(matching_fields_ & FIRST_PAINT) || timing.first_paint) && 114 if ((!(matching_fields_ & FIRST_PAINT) || timing.first_paint) &&
114 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || 115 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) ||
115 timing.first_contentful_paint)) { 116 timing.first_contentful_paint) &&
117 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) ||
118 timing.style_sheet_timing.update_style_duration_before_fcp)) {
116 // Ensure that any other handlers of this message, for example the real 119 // Ensure that any other handlers of this message, for example the real
117 // PageLoadMetric observers, get a chance to handle this message before 120 // PageLoadMetric observers, get a chance to handle this message before
118 // this waiter unblocks. 121 // this waiter unblocks.
119 content::BrowserThread::PostTask( 122 content::BrowserThread::PostTask(
120 content::BrowserThread::IO, FROM_HERE, 123 content::BrowserThread::IO, FROM_HERE,
121 base::Bind(&TimingUpdatedObserver::BounceTimingUpdate, this, timing, 124 base::Bind(&TimingUpdatedObserver::BounceTimingUpdate, this, timing,
122 metadata)); 125 metadata));
123 } 126 }
124 return true; 127 return true;
125 } 128 }
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 715
713 histogram_tester_.ExpectTotalCount( 716 histogram_tester_.ExpectTotalCount(
714 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1); 717 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1);
715 histogram_tester_.ExpectTotalCount( 718 histogram_tester_.ExpectTotalCount(
716 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0); 719 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0);
717 } 720 }
718 721
719 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) { 722 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) {
720 ASSERT_TRUE(embedded_test_server()->Start()); 723 ASSERT_TRUE(embedded_test_server()->Start());
721 724
725 scoped_refptr<TimingUpdatedObserver> fcp_observer =
726 CreateTimingUpdatedObserver();
727 fcp_observer->AddMatchingFields(
728 TimingUpdatedObserver::STYLE_UPDATE_BEFORE_FCP);
729
722 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here 730 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here
723 // must take >> 5us, otherwise we'll log 0 for the value and it will remain 731 // must take >> 5us, otherwise we'll log 0 for the value and it will remain
724 // unset here. 732 // unset here.
725 ui_test_utils::NavigateToURL( 733 ui_test_utils::NavigateToURL(
726 browser(), 734 browser(),
727 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html")); 735 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html"));
728 NavigateToUntrackedUrl(); 736 NavigateToUntrackedUrl();
737 fcp_observer->WaitForMatchingIPC();
729 738
730 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint, 739 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint,
731 1); 740 1);
732 histogram_tester_.ExpectTotalCount( 741 histogram_tester_.ExpectTotalCount(
733 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1); 742 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1);
734 histogram_tester_.ExpectTotalCount( 743 histogram_tester_.ExpectTotalCount(
735 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1); 744 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1);
736 histogram_tester_.ExpectTotalCount( 745 histogram_tester_.ExpectTotalCount(
737 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1); 746 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1);
738 } 747 }
739 748
740 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PayloadSize) { 749 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PayloadSize) {
741 ASSERT_TRUE(embedded_test_server()->Start()); 750 ASSERT_TRUE(embedded_test_server()->Start());
742 751
743 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( 752 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
744 "/page_load_metrics/large.html")); 753 "/page_load_metrics/large.html"));
745 NavigateToUntrackedUrl(); 754 NavigateToUntrackedUrl();
746 755
747 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 756 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
748 757
749 // Verify that there is a single sample recorded in the 10kB bucket (the size 758 // Verify that there is a single sample recorded in the 10kB bucket (the size
750 // of the main HTML response). 759 // of the main HTML response).
751 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); 760 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1);
752 } 761 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698