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

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

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

Powered by Google App Engine
This is Rietveld 408576698