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

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

Issue 2859393002: Report page load timing information for child frames. (Closed)
Patch Set: cleanup Created 3 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 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/command_line.h"
6 #include "base/feature_list.h"
5 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
6 #include "base/macros.h" 8 #include "base/macros.h"
7 #include "base/test/histogram_tester.h" 9 #include "base/test/histogram_tester.h"
8 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
9 #include "base/time/time.h" 11 #include "base/time/time.h"
10 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 12 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h"
11 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob server.h" 13 #include "chrome/browser/page_load_metrics/observers/aborts_page_load_metrics_ob server.h"
12 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h" 14 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse rver.h"
13 #include "chrome/browser/page_load_metrics/observers/document_write_page_load_me trics_observer.h" 15 #include "chrome/browser/page_load_metrics/observers/document_write_page_load_me trics_observer.h"
14 #include "chrome/browser/page_load_metrics/observers/no_state_prefetch_page_load _metrics_observer.h" 16 #include "chrome/browser/page_load_metrics/observers/no_state_prefetch_page_load _metrics_observer.h"
15 #include "chrome/browser/page_load_metrics/page_load_tracker.h" 17 #include "chrome/browser/page_load_metrics/page_load_tracker.h"
16 #include "chrome/browser/prerender/prerender_histograms.h" 18 #include "chrome/browser/prerender/prerender_histograms.h"
17 #include "chrome/browser/prerender/prerender_origin.h" 19 #include "chrome/browser/prerender/prerender_origin.h"
18 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_navigator_params.h" 22 #include "chrome/browser/ui/browser_navigator_params.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" 24 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h"
23 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
24 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
25 #include "chrome/test/base/in_process_browser_test.h" 27 #include "chrome/test/base/in_process_browser_test.h"
26 #include "chrome/test/base/ui_test_utils.h" 28 #include "chrome/test/base/ui_test_utils.h"
27 #include "components/prefs/pref_service.h" 29 #include "components/prefs/pref_service.h"
28 #include "content/public/browser/browser_thread.h" 30 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/render_process_host.h" 31 #include "content/public/browser/render_process_host.h"
30 #include "content/public/browser/render_view_host.h" 32 #include "content/public/browser/render_view_host.h"
33 #include "content/public/common/content_switches.h"
31 #include "content/public/test/browser_test_utils.h" 34 #include "content/public/test/browser_test_utils.h"
32 #include "content/public/test/download_test_observer.h" 35 #include "content/public/test/download_test_observer.h"
36 #include "net/dns/mock_host_resolver.h"
33 #include "net/http/failing_http_transaction_factory.h" 37 #include "net/http/failing_http_transaction_factory.h"
34 #include "net/http/http_cache.h" 38 #include "net/http/http_cache.h"
35 #include "net/test/embedded_test_server/embedded_test_server.h" 39 #include "net/test/embedded_test_server/embedded_test_server.h"
36 #include "net/test/url_request/url_request_failed_job.h" 40 #include "net/test/url_request/url_request_failed_job.h"
37 #include "net/url_request/url_request_context.h" 41 #include "net/url_request/url_request_context.h"
38 #include "net/url_request/url_request_context_getter.h" 42 #include "net/url_request/url_request_context_getter.h"
39 43
40 namespace { 44 namespace {
41 45
42 // Waits until specified timing and metadata expectations are satisfied. 46 // Waits until specified timing and metadata expectations are satisfied.
43 class PageLoadMetricsWaiter 47 class PageLoadMetricsWaiter
44 : public page_load_metrics::MetricsWebContentsObserver::TestingObserver { 48 : public page_load_metrics::MetricsWebContentsObserver::TestingObserver {
45 public: 49 public:
46 // A bitvector to express which timing fields to match on. 50 // A bitvector to express which timing fields to match on.
47 enum ExpectedTimingFields { 51 enum ExpectedTimingFields {
48 FIRST_PAINT = 1 << 0, 52 FIRST_LAYOUT = 1 << 0,
49 FIRST_CONTENTFUL_PAINT = 1 << 1, 53 FIRST_PAINT = 1 << 1,
50 STYLE_UPDATE_BEFORE_FCP = 1 << 2 54 FIRST_CONTENTFUL_PAINT = 1 << 2,
55 STYLE_UPDATE_BEFORE_FCP = 1 << 3,
56 DOCUMENT_WRITE_BLOCK_RELOAD = 1 << 4
51 }; 57 };
52 58
53 explicit PageLoadMetricsWaiter(content::WebContents* web_contents) 59 explicit PageLoadMetricsWaiter(content::WebContents* web_contents)
54 : TestingObserver(web_contents) {} 60 : TestingObserver(web_contents) {}
55 61
56 ~PageLoadMetricsWaiter() override { DCHECK_EQ(nullptr, run_loop_.get()); } 62 ~PageLoadMetricsWaiter() override { DCHECK_EQ(nullptr, run_loop_.get()); }
57 63
58 // Add the given expectation to match on. 64 // Add the given expectation to match on.
59 void AddExpectation(ExpectedTimingFields fields) { 65 void AddMainFrameExpectation(ExpectedTimingFields fields) {
60 matching_fields_ |= fields; 66 main_frame_expected_fields_ |= fields;
61 } 67 }
62 68 void AddSubFrameExpectation(ExpectedTimingFields fields) {
63 // Instructs observer to also watch for |count| 69 child_frame_expected_fields_ |= fields;
64 // WebLoadingBehaviorDocumentWriteBlockReload events.
65 void ExpectDocumentWriteBlockReload(int count) {
66 match_document_write_block_reload_ = count;
67 } 70 }
68 71
69 // Waits for a TimingUpdated IPC that matches the fields set by 72 // Waits for a TimingUpdated IPC that matches the fields set by
70 // |AddExpectation|. All matching fields must be set in a TimingUpdated 73 // |AddExpectation|. All matching fields must be set in a TimingUpdated
71 // IPC for it to end this wait. 74 // IPC for it to end this wait.
72 void Wait() { 75 void Wait() {
73 if (expectations_satisfied_) 76 if (expectations_satisfied_)
74 return; 77 return;
75 78
76 run_loop_.reset(new base::RunLoop()); 79 run_loop_.reset(new base::RunLoop());
77 run_loop_->Run(); 80 run_loop_->Run();
78 run_loop_.reset(nullptr); 81 run_loop_.reset(nullptr);
79 82
80 EXPECT_TRUE(expectations_satisfied_); 83 EXPECT_TRUE(expectations_satisfied_);
81 } 84 }
82 85
83 private: 86 private:
87 static int GetMatchedBits(
88 const page_load_metrics::PageLoadTiming& timing,
89 const page_load_metrics::PageLoadMetadata& metadata) {
90 int matched_bits = 0;
91 if (timing.document_timing.first_layout)
92 matched_bits |= FIRST_LAYOUT;
93 if (timing.paint_timing.first_paint)
94 matched_bits |= FIRST_PAINT;
95 if (timing.paint_timing.first_contentful_paint)
96 matched_bits |= FIRST_CONTENTFUL_PAINT;
97 if (timing.style_sheet_timing.update_style_duration_before_fcp)
98 matched_bits |= STYLE_UPDATE_BEFORE_FCP;
99 if (metadata.behavior_flags &
100 blink::WebLoadingBehaviorFlag::
101 kWebLoadingBehaviorDocumentWriteBlockReload)
102 matched_bits |= DOCUMENT_WRITE_BLOCK_RELOAD;
103
104 return matched_bits;
105 }
106
84 void OnTimingUpdated( 107 void OnTimingUpdated(
108 bool is_main_frame,
85 const page_load_metrics::PageLoadTiming& timing, 109 const page_load_metrics::PageLoadTiming& timing,
86 const page_load_metrics::PageLoadMetadata& metadata) override { 110 const page_load_metrics::PageLoadMetadata& metadata) override {
87 if (match_document_write_block_reload_ > 0 && 111 if (expectations_satisfied_)
88 metadata.behavior_flags & 112 return;
89 blink::WebLoadingBehaviorFlag::
90 kWebLoadingBehaviorDocumentWriteBlockReload) {
91 --match_document_write_block_reload_;
92 }
93 113
94 if (match_document_write_block_reload_ > 0) { 114 int matched_bits = GetMatchedBits(timing, metadata);
95 return; 115 if (is_main_frame)
96 } 116 main_frame_expected_fields_ &= ~matched_bits;
117 else
118 child_frame_expected_fields_ &= ~matched_bits;
97 119
98 if ((!(matching_fields_ & FIRST_PAINT) || 120 if (main_frame_expected_fields_ == 0 && child_frame_expected_fields_ == 0) {
99 timing.paint_timing.first_paint) &&
100 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) ||
101 timing.paint_timing.first_contentful_paint) &&
102 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) ||
103 timing.style_sheet_timing.update_style_duration_before_fcp)) {
104 expectations_satisfied_ = true; 121 expectations_satisfied_ = true;
105 if (run_loop_) 122 if (run_loop_)
106 run_loop_->Quit(); 123 run_loop_->Quit();
107 } 124 }
108 } 125 }
109 126
110 std::unique_ptr<base::RunLoop> run_loop_; 127 std::unique_ptr<base::RunLoop> run_loop_;
111 int matching_fields_ = 0; // A bitvector composed from ExpectedTimingFields. 128
129 // Bitvectors composed from ExpectedTimingFields.
130 int child_frame_expected_fields_ = 0;
131 int main_frame_expected_fields_ = 0;
132
112 bool expectations_satisfied_ = false; 133 bool expectations_satisfied_ = false;
113 int match_document_write_block_reload_ = 0;
114 }; 134 };
115 135
136 // Due to crbug/705315, paints in child frames are associated with the main
137 // frame, unless the child frame is cross-origin and Chrome is running with out
138 // of process cross-origin child frames. As a result, some tests wait for
139 // different behavior to be observed depending on which mode we are in.
140 // TODO(crbug/705315): remove this method once the bug is addressed.
141 static bool AreCrossOriginChildFramesOutOfProcess() {
142 return base::CommandLine::ForCurrentProcess()->HasSwitch(
143 switches::kSitePerProcess) ||
144 base::CommandLine::ForCurrentProcess()->HasSwitch(
145 switches::kTopDocumentIsolation);
146 }
147
116 } // namespace 148 } // namespace
117 149
118 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { 150 class PageLoadMetricsBrowserTest : public InProcessBrowserTest {
119 public: 151 public:
120 PageLoadMetricsBrowserTest() {} 152 PageLoadMetricsBrowserTest() {}
121 ~PageLoadMetricsBrowserTest() override {} 153 ~PageLoadMetricsBrowserTest() override {}
122 154
123 protected: 155 protected:
124 void NavigateToUntrackedUrl() { 156 void NavigateToUntrackedUrl() {
125 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 157 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
126 } 158 }
127 159
160 // TODO(crbug/705315): remove this method once the bug is addressed.
161 void SetUpOnMainThread() override {
162 InProcessBrowserTest::SetUpOnMainThread();
163 host_resolver()->AddRule("a.com", "127.0.0.1");
164 host_resolver()->AddRule("b.com", "127.0.0.1");
165 host_resolver()->AddRule("c.com", "127.0.0.1");
166 content::SetupCrossSiteRedirector(embedded_test_server());
167 }
168
128 bool NoPageLoadMetricsRecorded() { 169 bool NoPageLoadMetricsRecorded() {
129 // Determine whether any 'public' page load metrics are recorded. We exclude 170 // Determine whether any 'public' page load metrics are recorded. We exclude
130 // 'internal' metrics as these may be recorded for debugging purposes. 171 // 'internal' metrics as these may be recorded for debugging purposes.
131 size_t total_pageload_histograms = 172 size_t total_pageload_histograms =
132 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); 173 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size();
133 size_t total_internal_histograms = 174 size_t total_internal_histograms =
134 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); 175 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size();
135 DCHECK_GE(total_pageload_histograms, total_internal_histograms); 176 DCHECK_GE(total_pageload_histograms, total_internal_histograms);
136 return total_pageload_histograms - total_internal_histograms == 0; 177 return total_pageload_histograms - total_internal_histograms == 0;
137 } 178 }
(...skipping 24 matching lines...) Expand all
162 } 203 }
163 204
164 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoNavigation) { 205 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoNavigation) {
165 ASSERT_TRUE(embedded_test_server()->Start()); 206 ASSERT_TRUE(embedded_test_server()->Start());
166 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 207 EXPECT_TRUE(NoPageLoadMetricsRecorded());
167 } 208 }
168 209
169 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) { 210 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) {
170 ASSERT_TRUE(embedded_test_server()->Start()); 211 ASSERT_TRUE(embedded_test_server()->Start());
171 212
213 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
214 CreatePageLoadMetricsWaiter();
215 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
172 ui_test_utils::NavigateToURL(browser(), 216 ui_test_utils::NavigateToURL(browser(),
173 embedded_test_server()->GetURL("/title1.html")); 217 embedded_test_server()->GetURL("/title1.html"));
218 timing_waiter->Wait();
174 NavigateToUntrackedUrl(); 219 NavigateToUntrackedUrl();
175 220
176 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); 221 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1);
177 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1); 222 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1);
178 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); 223 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
224 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1);
179 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1); 225 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1);
180 histogram_tester_.ExpectTotalCount( 226 histogram_tester_.ExpectTotalCount(
181 internal::kHistogramParseBlockedOnScriptLoad, 1); 227 internal::kHistogramParseBlockedOnScriptLoad, 1);
182 histogram_tester_.ExpectTotalCount( 228 histogram_tester_.ExpectTotalCount(
183 internal::kHistogramParseBlockedOnScriptExecution, 1); 229 internal::kHistogramParseBlockedOnScriptExecution, 1);
184 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 230 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
185 histogram_tester_.ExpectTotalCount( 231 histogram_tester_.ExpectTotalCount(
186 internal::kHistogramPageTimingForegroundDuration, 1); 232 internal::kHistogramPageTimingForegroundDuration, 1);
187 233
188 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics 234 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics
189 // have been recorded. 235 // have been recorded.
190 EXPECT_FALSE(NoPageLoadMetricsRecorded()); 236 EXPECT_FALSE(NoPageLoadMetricsRecorded());
191 } 237 }
192 238
239 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPaintForEmptyDocument) {
240 ASSERT_TRUE(embedded_test_server()->Start());
241
242 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
243 CreatePageLoadMetricsWaiter();
244 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_LAYOUT);
245 ui_test_utils::NavigateToURL(browser(),
246 embedded_test_server()->GetURL("/empty.html"));
247 timing_waiter->Wait();
248
249 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
250 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0);
251 }
252
253 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
254 NoPaintForEmptyDocumentInChildFrame) {
255 ASSERT_TRUE(embedded_test_server()->Start());
256
257 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
258 CreatePageLoadMetricsWaiter();
259 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_LAYOUT);
260 timing_waiter->AddSubFrameExpectation(PageLoadMetricsWaiter::FIRST_LAYOUT);
261 // TODO(crbug/705315): remove the a.com domain once the bug is addressed.
262 GURL a_url(embedded_test_server()->GetURL(
263 "a.com", "/page_load_metrics/empty_iframe.html"));
264 ui_test_utils::NavigateToURL(browser(), a_url);
265 timing_waiter->Wait();
266
267 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
268 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0);
269 }
270
271 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PaintInChildFrame) {
272 ASSERT_TRUE(embedded_test_server()->Start());
273
274 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
275 CreatePageLoadMetricsWaiter();
276 // TODO(crbug/705315): Once the bug is fixed, remove the else case and make
277 // the if case the default behavior.
278 if (AreCrossOriginChildFramesOutOfProcess()) {
279 timing_waiter->AddSubFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
280 } else {
281 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
282 }
283 // TODO(crbug/705315): remove the a.com domain once the bug is addressed.
284 GURL a_url(embedded_test_server()->GetURL("a.com",
285 "/page_load_metrics/iframe.html"));
286 ui_test_utils::NavigateToURL(browser(), a_url);
287 timing_waiter->Wait();
288
289 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
290 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1);
291 }
292
293 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PaintInMultipleChildFrames) {
294 ASSERT_TRUE(embedded_test_server()->Start());
295
296 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
297 CreatePageLoadMetricsWaiter();
298 // TODO(crbug/705315): Once the bug is fixed, remove the else case and make
299 // the if case the default behavior.
300 if (AreCrossOriginChildFramesOutOfProcess()) {
301 timing_waiter->AddSubFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
302 } else {
303 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
304 }
305
306 // TODO(crbug/705315): remove the a.com domain once the bug is addressed.
307 GURL a_url(embedded_test_server()->GetURL("a.com",
308 "/page_load_metrics/iframes.html"));
309 ui_test_utils::NavigateToURL(browser(), a_url);
310 timing_waiter->Wait();
311
312 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
313 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1);
314 }
315
316 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PaintInMainAndChildFrame) {
317 ASSERT_TRUE(embedded_test_server()->Start());
318
319 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
320 CreatePageLoadMetricsWaiter();
321 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
322 // TODO(crbug/705315): Once the bug is fixed, make the if case the default
323 // behavior.
324 if (AreCrossOriginChildFramesOutOfProcess()) {
325 timing_waiter->AddSubFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
326 }
327
328 // TODO(crbug/705315): remove the a.com domain once the bug is addressed.
329 GURL a_url(embedded_test_server()->GetURL(
330 "a.com", "/page_load_metrics/main_frame_with_iframe.html"));
331 ui_test_utils::NavigateToURL(browser(), a_url);
332 timing_waiter->Wait();
333
334 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
335 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1);
336 }
337
193 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameDocumentNavigation) { 338 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameDocumentNavigation) {
194 ASSERT_TRUE(embedded_test_server()->Start()); 339 ASSERT_TRUE(embedded_test_server()->Start());
195 340
196 ui_test_utils::NavigateToURL(browser(), 341 ui_test_utils::NavigateToURL(browser(),
197 embedded_test_server()->GetURL("/title1.html")); 342 embedded_test_server()->GetURL("/title1.html"));
198 ui_test_utils::NavigateToURL( 343 ui_test_utils::NavigateToURL(
199 browser(), embedded_test_server()->GetURL("/title1.html#hash")); 344 browser(), embedded_test_server()->GetURL("/title1.html#hash"));
200 NavigateToUntrackedUrl(); 345 NavigateToUntrackedUrl();
201 346
202 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); 347 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 436
292 NavigateToUntrackedUrl(); 437 NavigateToUntrackedUrl();
293 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 438 EXPECT_TRUE(NoPageLoadMetricsRecorded());
294 } 439 }
295 440
296 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PreloadDocumentWrite) { 441 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PreloadDocumentWrite) {
297 ASSERT_TRUE(embedded_test_server()->Start()); 442 ASSERT_TRUE(embedded_test_server()->Start());
298 443
299 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 444 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
300 CreatePageLoadMetricsWaiter(); 445 CreatePageLoadMetricsWaiter();
301 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 446 fcp_waiter->AddMainFrameExpectation(
447 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
302 448
303 ui_test_utils::NavigateToURL( 449 ui_test_utils::NavigateToURL(
304 browser(), embedded_test_server()->GetURL( 450 browser(), embedded_test_server()->GetURL(
305 "/page_load_metrics/document_write_external_script.html")); 451 "/page_load_metrics/document_write_external_script.html"));
306 fcp_waiter->Wait(); 452 fcp_waiter->Wait();
307 453
308 histogram_tester_.ExpectTotalCount( 454 histogram_tester_.ExpectTotalCount(
309 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1); 455 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1);
310 } 456 }
311 457
312 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPreloadDocumentWrite) { 458 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPreloadDocumentWrite) {
313 ASSERT_TRUE(embedded_test_server()->Start()); 459 ASSERT_TRUE(embedded_test_server()->Start());
314 460
315 ui_test_utils::NavigateToURL( 461 ui_test_utils::NavigateToURL(
316 browser(), embedded_test_server()->GetURL( 462 browser(), embedded_test_server()->GetURL(
317 "/page_load_metrics/document_write_no_script.html")); 463 "/page_load_metrics/document_write_no_script.html"));
318 NavigateToUntrackedUrl(); 464 NavigateToUntrackedUrl();
319 465
320 histogram_tester_.ExpectTotalCount( 466 histogram_tester_.ExpectTotalCount(
321 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); 467 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0);
322 } 468 }
323 469
324 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWrite) { 470 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWrite) {
325 ASSERT_TRUE(embedded_test_server()->Start()); 471 ASSERT_TRUE(embedded_test_server()->Start());
326 472
327 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 473 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
328 CreatePageLoadMetricsWaiter(); 474 CreatePageLoadMetricsWaiter();
329 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 475 fcp_waiter->AddMainFrameExpectation(
476 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
330 477
331 ui_test_utils::NavigateToURL(browser(), 478 ui_test_utils::NavigateToURL(browser(),
332 embedded_test_server()->GetURL("/title1.html")); 479 embedded_test_server()->GetURL("/title1.html"));
333 fcp_waiter->Wait(); 480 fcp_waiter->Wait();
334 481
335 histogram_tester_.ExpectTotalCount( 482 histogram_tester_.ExpectTotalCount(
336 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); 483 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0);
337 histogram_tester_.ExpectTotalCount( 484 histogram_tester_.ExpectTotalCount(
338 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); 485 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0);
339 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); 486 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0);
340 } 487 }
341 488
342 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteBlock) { 489 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteBlock) {
343 ASSERT_TRUE(embedded_test_server()->Start()); 490 ASSERT_TRUE(embedded_test_server()->Start());
344 491
345 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 492 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
346 CreatePageLoadMetricsWaiter(); 493 CreatePageLoadMetricsWaiter();
347 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 494 fcp_waiter->AddMainFrameExpectation(
495 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
348 496
349 ui_test_utils::NavigateToURL( 497 ui_test_utils::NavigateToURL(
350 browser(), embedded_test_server()->GetURL( 498 browser(), embedded_test_server()->GetURL(
351 "/page_load_metrics/document_write_script_block.html")); 499 "/page_load_metrics/document_write_script_block.html"));
352 fcp_waiter->Wait(); 500 fcp_waiter->Wait();
353 501
354 histogram_tester_.ExpectTotalCount( 502 histogram_tester_.ExpectTotalCount(
355 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); 503 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
356 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); 504 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1);
357 } 505 }
358 506
359 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteReload) { 507 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteReload) {
360 ASSERT_TRUE(embedded_test_server()->Start()); 508 ASSERT_TRUE(embedded_test_server()->Start());
361 509
362 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 510 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
363 CreatePageLoadMetricsWaiter(); 511 CreatePageLoadMetricsWaiter();
364 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 512 fcp_waiter->AddMainFrameExpectation(
365 std::unique_ptr<PageLoadMetricsWaiter> reload_waiter = 513 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
366 CreatePageLoadMetricsWaiter();
367 reload_waiter->ExpectDocumentWriteBlockReload(2);
368
369 ui_test_utils::NavigateToURL( 514 ui_test_utils::NavigateToURL(
370 browser(), embedded_test_server()->GetURL( 515 browser(), embedded_test_server()->GetURL(
371 "/page_load_metrics/document_write_script_block.html")); 516 "/page_load_metrics/document_write_script_block.html"));
517 fcp_waiter->Wait();
518
519 histogram_tester_.ExpectTotalCount(
520 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
521 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1);
372 522
373 // Reload should not log the histogram as the script is not blocked. 523 // Reload should not log the histogram as the script is not blocked.
524 std::unique_ptr<PageLoadMetricsWaiter> reload_waiter =
525 CreatePageLoadMetricsWaiter();
526 reload_waiter->AddMainFrameExpectation(
527 PageLoadMetricsWaiter::DOCUMENT_WRITE_BLOCK_RELOAD);
528 reload_waiter->AddMainFrameExpectation(
529 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
374 ui_test_utils::NavigateToURL( 530 ui_test_utils::NavigateToURL(
375 browser(), embedded_test_server()->GetURL( 531 browser(), embedded_test_server()->GetURL(
376 "/page_load_metrics/document_write_script_block.html")); 532 "/page_load_metrics/document_write_script_block.html"));
533 reload_waiter->Wait();
377 534
535 reload_waiter = CreatePageLoadMetricsWaiter();
536 reload_waiter->AddMainFrameExpectation(
537 PageLoadMetricsWaiter::DOCUMENT_WRITE_BLOCK_RELOAD);
538 reload_waiter->AddMainFrameExpectation(
539 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
378 ui_test_utils::NavigateToURL( 540 ui_test_utils::NavigateToURL(
379 browser(), embedded_test_server()->GetURL( 541 browser(), embedded_test_server()->GetURL(
380 "/page_load_metrics/document_write_script_block.html")); 542 "/page_load_metrics/document_write_script_block.html"));
381
382 histogram_tester_.ExpectTotalCount(
383 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
384
385 fcp_waiter->Wait();
386 reload_waiter->Wait(); 543 reload_waiter->Wait();
387 544
388 histogram_tester_.ExpectTotalCount( 545 histogram_tester_.ExpectTotalCount(
389 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); 546 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
390 547
391 histogram_tester_.ExpectTotalCount( 548 histogram_tester_.ExpectTotalCount(
392 internal::kHistogramDocWriteBlockReloadCount, 2); 549 internal::kHistogramDocWriteBlockReloadCount, 2);
393 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); 550 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1);
394 } 551 }
395 552
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 #if defined(OS_LINUX) && !defined(NDEBUG) 593 #if defined(OS_LINUX) && !defined(NDEBUG)
437 #define MAYBE_BadXhtml DISABLED_BadXhtml 594 #define MAYBE_BadXhtml DISABLED_BadXhtml
438 #else 595 #else
439 #define MAYBE_BadXhtml BadXhtml 596 #define MAYBE_BadXhtml BadXhtml
440 #endif 597 #endif
441 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_BadXhtml) { 598 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_BadXhtml) {
442 ASSERT_TRUE(embedded_test_server()->Start()); 599 ASSERT_TRUE(embedded_test_server()->Start());
443 600
444 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter = 601 std::unique_ptr<PageLoadMetricsWaiter> timing_waiter =
445 CreatePageLoadMetricsWaiter(); 602 CreatePageLoadMetricsWaiter();
446 timing_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_PAINT); 603 timing_waiter->AddMainFrameExpectation(PageLoadMetricsWaiter::FIRST_PAINT);
447 604
448 // When an XHTML page contains invalid XML, it causes a paint of the error 605 // When an XHTML page contains invalid XML, it causes a paint of the error
449 // message without a layout. Page load metrics currently treats this as an 606 // message without a layout. Page load metrics currently treats this as an
450 // error. Eventually, we'll fix this by special casing the handling of 607 // error. Eventually, we'll fix this by special casing the handling of
451 // documents with non-well-formed XML on the blink side. See crbug.com/627607 608 // documents with non-well-formed XML on the blink side. See crbug.com/627607
452 // for more. 609 // for more.
453 ui_test_utils::NavigateToURL( 610 ui_test_utils::NavigateToURL(
454 browser(), 611 browser(),
455 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml")); 612 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml"));
456 613
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 histogram_tester_.ExpectTotalCount( 793 histogram_tester_.ExpectTotalCount(
637 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); 794 internal::kHistogramParseStartToFirstMeaningfulPaint, 1);
638 } 795 }
639 796
640 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 797 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
641 FirstMeaningfulPaintNotRecorded) { 798 FirstMeaningfulPaintNotRecorded) {
642 ASSERT_TRUE(embedded_test_server()->Start()); 799 ASSERT_TRUE(embedded_test_server()->Start());
643 800
644 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 801 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
645 CreatePageLoadMetricsWaiter(); 802 CreatePageLoadMetricsWaiter();
646 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 803 fcp_waiter->AddMainFrameExpectation(
804 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
647 805
648 ui_test_utils::NavigateToURL( 806 ui_test_utils::NavigateToURL(
649 browser(), embedded_test_server()->GetURL( 807 browser(), embedded_test_server()->GetURL(
650 "/page_load_metrics/page_with_active_connections.html")); 808 "/page_load_metrics/page_with_active_connections.html"));
651 fcp_waiter->Wait(); 809 fcp_waiter->Wait();
652 810
653 // Navigate away before a FMP is reported. 811 // Navigate away before a FMP is reported.
654 NavigateToUntrackedUrl(); 812 NavigateToUntrackedUrl();
655 813
656 histogram_tester_.ExpectUniqueSample( 814 histogram_tester_.ExpectUniqueSample(
657 internal::kHistogramFirstMeaningfulPaintStatus, 815 internal::kHistogramFirstMeaningfulPaintStatus,
658 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1); 816 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1);
659 histogram_tester_.ExpectTotalCount( 817 histogram_tester_.ExpectTotalCount(
660 internal::kHistogramFirstMeaningfulPaint, 0); 818 internal::kHistogramFirstMeaningfulPaint, 0);
661 histogram_tester_.ExpectTotalCount( 819 histogram_tester_.ExpectTotalCount(
662 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); 820 internal::kHistogramParseStartToFirstMeaningfulPaint, 0);
663 } 821 }
664 822
665 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 823 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
666 NoStatePrefetchObserverCacheable) { 824 NoStatePrefetchObserverCacheable) {
667 ASSERT_TRUE(embedded_test_server()->Start()); 825 ASSERT_TRUE(embedded_test_server()->Start());
668 826
669 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 827 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
670 CreatePageLoadMetricsWaiter(); 828 CreatePageLoadMetricsWaiter();
671 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 829 fcp_waiter->AddMainFrameExpectation(
830 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
672 831
673 ui_test_utils::NavigateToURL(browser(), 832 ui_test_utils::NavigateToURL(browser(),
674 embedded_test_server()->GetURL("/title1.html")); 833 embedded_test_server()->GetURL("/title1.html"));
675 834
676 fcp_waiter->Wait(); 835 fcp_waiter->Wait();
677 836
678 histogram_tester_.ExpectTotalCount( 837 histogram_tester_.ExpectTotalCount(
679 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0); 838 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0);
680 histogram_tester_.ExpectTotalCount( 839 histogram_tester_.ExpectTotalCount(
681 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1); 840 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1);
682 } 841 }
683 842
684 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 843 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest,
685 NoStatePrefetchObserverNoStore) { 844 NoStatePrefetchObserverNoStore) {
686 ASSERT_TRUE(embedded_test_server()->Start()); 845 ASSERT_TRUE(embedded_test_server()->Start());
687 846
688 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 847 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
689 CreatePageLoadMetricsWaiter(); 848 CreatePageLoadMetricsWaiter();
690 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT); 849 fcp_waiter->AddMainFrameExpectation(
850 PageLoadMetricsWaiter::FIRST_CONTENTFUL_PAINT);
691 851
692 ui_test_utils::NavigateToURL(browser(), 852 ui_test_utils::NavigateToURL(browser(),
693 embedded_test_server()->GetURL("/nostore.html")); 853 embedded_test_server()->GetURL("/nostore.html"));
694 854
695 fcp_waiter->Wait(); 855 fcp_waiter->Wait();
696 856
697 histogram_tester_.ExpectTotalCount( 857 histogram_tester_.ExpectTotalCount(
698 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1); 858 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1);
699 histogram_tester_.ExpectTotalCount( 859 histogram_tester_.ExpectTotalCount(
700 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0); 860 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0);
701 } 861 }
702 862
703 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) { 863 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) {
704 ASSERT_TRUE(embedded_test_server()->Start()); 864 ASSERT_TRUE(embedded_test_server()->Start());
705 865
706 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter = 866 std::unique_ptr<PageLoadMetricsWaiter> fcp_waiter =
707 CreatePageLoadMetricsWaiter(); 867 CreatePageLoadMetricsWaiter();
708 fcp_waiter->AddExpectation(PageLoadMetricsWaiter::STYLE_UPDATE_BEFORE_FCP); 868 fcp_waiter->AddMainFrameExpectation(
869 PageLoadMetricsWaiter::STYLE_UPDATE_BEFORE_FCP);
709 870
710 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here 871 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here
711 // must take >> 5us, otherwise we'll log 0 for the value and it will remain 872 // must take >> 5us, otherwise we'll log 0 for the value and it will remain
712 // unset here. 873 // unset here.
713 ui_test_utils::NavigateToURL( 874 ui_test_utils::NavigateToURL(
714 browser(), 875 browser(),
715 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html")); 876 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html"));
716 NavigateToUntrackedUrl(); 877 NavigateToUntrackedUrl();
717 fcp_waiter->Wait(); 878 fcp_waiter->Wait();
718 879
(...skipping 13 matching lines...) Expand all
732 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( 893 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
733 "/page_load_metrics/large.html")); 894 "/page_load_metrics/large.html"));
734 NavigateToUntrackedUrl(); 895 NavigateToUntrackedUrl();
735 896
736 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 897 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
737 898
738 // Verify that there is a single sample recorded in the 10kB bucket (the size 899 // Verify that there is a single sample recorded in the 10kB bucket (the size
739 // of the main HTML response). 900 // of the main HTML response).
740 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); 901 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1);
741 } 902 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698