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

Side by Side Diff: chrome/browser/page_load_metrics/observers/page_load_metrics_observer_test_harness.cc

Issue 2901383002: Buffer cross frame paint timing updates. (Closed)
Patch Set: address comment Created 3 years, 6 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 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/page_load_metrics_observer_ test_harness.h" 5 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_ test_harness.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 20 matching lines...) Expand all
31 : test_(test) {} 31 : test_(test) {}
32 32
33 bool IsNewTabPageUrl(const GURL& url) override { return false; } 33 bool IsNewTabPageUrl(const GURL& url) override { return false; }
34 34
35 // Forward the registration logic to the test class so that derived classes 35 // Forward the registration logic to the test class so that derived classes
36 // can override the logic there without depending on the embedder interface. 36 // can override the logic there without depending on the embedder interface.
37 void RegisterObservers(PageLoadTracker* tracker) override { 37 void RegisterObservers(PageLoadTracker* tracker) override {
38 test_->RegisterObservers(tracker); 38 test_->RegisterObservers(tracker);
39 } 39 }
40 40
41 std::unique_ptr<base::Timer> CreateTimer() override {
42 auto timer = base::MakeUnique<test::WeakMockTimer>();
43 test_->SetMockTimer(timer->AsWeakPtr());
44 return std::move(timer);
45 }
46
41 private: 47 private:
42 PageLoadMetricsObserverTestHarness* test_; 48 PageLoadMetricsObserverTestHarness* test_;
43 49
44 DISALLOW_COPY_AND_ASSIGN(TestPageLoadMetricsEmbedderInterface); 50 DISALLOW_COPY_AND_ASSIGN(TestPageLoadMetricsEmbedderInterface);
45 }; 51 };
46 52
47 } // namespace 53 } // namespace
48 54
49 PageLoadMetricsObserverTestHarness::PageLoadMetricsObserverTestHarness() 55 PageLoadMetricsObserverTestHarness::PageLoadMetricsObserverTestHarness()
50 : ChromeRenderViewHostTestHarness() {} 56 : ChromeRenderViewHostTestHarness() {}
51 57
52 PageLoadMetricsObserverTestHarness::~PageLoadMetricsObserverTestHarness() {} 58 PageLoadMetricsObserverTestHarness::~PageLoadMetricsObserverTestHarness() {}
53 59
54 // static
55 void PageLoadMetricsObserverTestHarness::PopulateRequiredTimingFields(
56 mojom::PageLoadTiming* inout_timing) {
57 if (inout_timing->paint_timing->first_meaningful_paint &&
58 !inout_timing->paint_timing->first_contentful_paint) {
59 inout_timing->paint_timing->first_contentful_paint =
60 inout_timing->paint_timing->first_meaningful_paint;
61 }
62 if ((inout_timing->paint_timing->first_text_paint ||
63 inout_timing->paint_timing->first_image_paint ||
64 inout_timing->paint_timing->first_contentful_paint) &&
65 !inout_timing->paint_timing->first_paint) {
66 inout_timing->paint_timing->first_paint =
67 OptionalMin(OptionalMin(inout_timing->paint_timing->first_text_paint,
68 inout_timing->paint_timing->first_image_paint),
69 inout_timing->paint_timing->first_contentful_paint);
70 }
71 if (inout_timing->paint_timing->first_paint &&
72 !inout_timing->document_timing->first_layout) {
73 inout_timing->document_timing->first_layout =
74 inout_timing->paint_timing->first_paint;
75 }
76 if (inout_timing->document_timing->load_event_start &&
77 !inout_timing->document_timing->dom_content_loaded_event_start) {
78 inout_timing->document_timing->dom_content_loaded_event_start =
79 inout_timing->document_timing->load_event_start;
80 }
81 if (inout_timing->document_timing->first_layout &&
82 !inout_timing->parse_timing->parse_start) {
83 inout_timing->parse_timing->parse_start =
84 inout_timing->document_timing->first_layout;
85 }
86 if (inout_timing->document_timing->dom_content_loaded_event_start &&
87 !inout_timing->parse_timing->parse_stop) {
88 inout_timing->parse_timing->parse_stop =
89 inout_timing->document_timing->dom_content_loaded_event_start;
90 }
91 if (inout_timing->parse_timing->parse_stop &&
92 !inout_timing->parse_timing->parse_start) {
93 inout_timing->parse_timing->parse_start =
94 inout_timing->parse_timing->parse_stop;
95 }
96 if (inout_timing->parse_timing->parse_start &&
97 !inout_timing->response_start) {
98 inout_timing->response_start = inout_timing->parse_timing->parse_start;
99 }
100 if (inout_timing->parse_timing->parse_start) {
101 if (!inout_timing->parse_timing->parse_blocked_on_script_load_duration)
102 inout_timing->parse_timing->parse_blocked_on_script_load_duration =
103 base::TimeDelta();
104 if (!inout_timing->parse_timing
105 ->parse_blocked_on_script_execution_duration) {
106 inout_timing->parse_timing->parse_blocked_on_script_execution_duration =
107 base::TimeDelta();
108 }
109 if (!inout_timing->parse_timing
110 ->parse_blocked_on_script_load_from_document_write_duration) {
111 inout_timing->parse_timing
112 ->parse_blocked_on_script_load_from_document_write_duration =
113 base::TimeDelta();
114 }
115 if (!inout_timing->parse_timing
116 ->parse_blocked_on_script_execution_from_document_write_duration) {
117 inout_timing->parse_timing
118 ->parse_blocked_on_script_execution_from_document_write_duration =
119 base::TimeDelta();
120 }
121 }
122 }
123
124 void PageLoadMetricsObserverTestHarness::SetUp() { 60 void PageLoadMetricsObserverTestHarness::SetUp() {
125 ChromeRenderViewHostTestHarness::SetUp(); 61 ChromeRenderViewHostTestHarness::SetUp();
126 SetContents(CreateTestWebContents()); 62 SetContents(CreateTestWebContents());
127 NavigateAndCommit(GURL("http://www.google.com")); 63 NavigateAndCommit(GURL("http://www.google.com"));
128 observer_ = MetricsWebContentsObserver::CreateForWebContents( 64 observer_ = MetricsWebContentsObserver::CreateForWebContents(
129 web_contents(), base::nullopt, 65 web_contents(), base::nullopt,
130 base::MakeUnique<TestPageLoadMetricsEmbedderInterface>(this)); 66 base::MakeUnique<TestPageLoadMetricsEmbedderInterface>(this));
131 web_contents()->WasShown(); 67 web_contents()->WasShown();
132 } 68 }
133 69
134 void PageLoadMetricsObserverTestHarness::StartNavigation(const GURL& gurl) { 70 void PageLoadMetricsObserverTestHarness::StartNavigation(const GURL& gurl) {
135 content::WebContentsTester* web_contents_tester = 71 content::WebContentsTester* web_contents_tester =
136 content::WebContentsTester::For(web_contents()); 72 content::WebContentsTester::For(web_contents());
137 web_contents_tester->StartNavigation(gurl); 73 web_contents_tester->StartNavigation(gurl);
138 } 74 }
139 75
140 void PageLoadMetricsObserverTestHarness::SimulateTimingUpdate( 76 void PageLoadMetricsObserverTestHarness::SimulateTimingUpdate(
141 const mojom::PageLoadTiming& timing) { 77 const mojom::PageLoadTiming& timing) {
142 SimulateTimingAndMetadataUpdate(timing, mojom::PageLoadMetadata()); 78 SimulateTimingAndMetadataUpdate(timing, mojom::PageLoadMetadata());
143 } 79 }
144 80
145 void PageLoadMetricsObserverTestHarness::SimulateTimingAndMetadataUpdate( 81 void PageLoadMetricsObserverTestHarness::SimulateTimingAndMetadataUpdate(
146 const mojom::PageLoadTiming& timing, 82 const mojom::PageLoadTiming& timing,
147 const mojom::PageLoadMetadata& metadata) { 83 const mojom::PageLoadMetadata& metadata) {
148 observer_->OnTimingUpdated(web_contents()->GetMainFrame(), timing, metadata); 84 observer_->OnTimingUpdated(web_contents()->GetMainFrame(), timing, metadata);
85 // If sending the timing update caused the PageLoadMetricsUpdateDispatcher to
86 // schedule a buffering timer, then fire it now so metrics are dispatched to
87 // observers.
88 base::MockTimer* mock_timer = GetMockTimer();
89 if (mock_timer && mock_timer->IsRunning())
90 mock_timer->Fire();
149 } 91 }
150 92
151 void PageLoadMetricsObserverTestHarness::SimulateStartedResource( 93 void PageLoadMetricsObserverTestHarness::SimulateStartedResource(
152 const ExtraRequestStartInfo& info) { 94 const ExtraRequestStartInfo& info) {
153 observer_->OnRequestStarted(content::GlobalRequestID(), info.resource_type, 95 observer_->OnRequestStarted(content::GlobalRequestID(), info.resource_type,
154 base::TimeTicks::Now()); 96 base::TimeTicks::Now());
155 } 97 }
156 98
157 void PageLoadMetricsObserverTestHarness::SimulateLoadedResource( 99 void PageLoadMetricsObserverTestHarness::SimulateLoadedResource(
158 const ExtraRequestCompleteInfo& info) { 100 const ExtraRequestCompleteInfo& info) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 141 }
200 142
201 void PageLoadMetricsObserverTestHarness::NavigateWithPageTransitionAndCommit( 143 void PageLoadMetricsObserverTestHarness::NavigateWithPageTransitionAndCommit(
202 const GURL& url, 144 const GURL& url,
203 ui::PageTransition transition) { 145 ui::PageTransition transition) {
204 controller().LoadURL(url, content::Referrer(), transition, std::string()); 146 controller().LoadURL(url, content::Referrer(), transition, std::string());
205 content::WebContentsTester::For(web_contents())->CommitPendingNavigation(); 147 content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
206 } 148 }
207 149
208 } // namespace page_load_metrics 150 } // namespace page_load_metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698