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

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

Issue 2823523003: [Page Load Metrics] PageLoadMetrics Mojofication. (Closed)
Patch Set: Addressed comments, remove unnecessary RunUntilIdle, call OnTimingUpdated directly in unit tests Created 3 years, 8 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/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/test/scoped_feature_list.h"
8 #include "base/time/time.h" 9 #include "base/time/time.h"
9 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" 10 #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" 11 #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" 12 #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" 13 #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" 14 #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" 15 #include "chrome/browser/page_load_metrics/page_load_tracker.h"
15 #include "chrome/browser/prerender/prerender_histograms.h" 16 #include "chrome/browser/prerender/prerender_histograms.h"
16 #include "chrome/browser/prerender/prerender_origin.h" 17 #include "chrome/browser/prerender/prerender_origin.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_navigator_params.h" 20 #include "chrome/browser/ui/browser_navigator_params.h"
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
21 #include "chrome/common/page_load_metrics/page_load_metrics_messages.h" 22 #include "chrome/common/chrome_features.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/common/url_constants.h" 24 #include "chrome/common/url_constants.h"
24 #include "chrome/test/base/in_process_browser_test.h" 25 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 26 #include "chrome/test/base/ui_test_utils.h"
26 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
27 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
29 #include "content/public/browser/render_view_host.h" 30 #include "content/public/browser/render_view_host.h"
30 #include "content/public/test/browser_test_utils.h" 31 #include "content/public/test/browser_test_utils.h"
31 #include "content/public/test/download_test_observer.h" 32 #include "content/public/test/download_test_observer.h"
33 #include "content/public/test/web_contents_binding_set_test_binder.h"
34 #include "mojo/public/cpp/bindings/associated_binding.h"
32 #include "net/http/failing_http_transaction_factory.h" 35 #include "net/http/failing_http_transaction_factory.h"
33 #include "net/http/http_cache.h" 36 #include "net/http/http_cache.h"
34 #include "net/test/embedded_test_server/embedded_test_server.h" 37 #include "net/test/embedded_test_server/embedded_test_server.h"
35 #include "net/test/url_request/url_request_failed_job.h" 38 #include "net/test/url_request/url_request_failed_job.h"
36 #include "net/url_request/url_request_context.h" 39 #include "net/url_request/url_request_context.h"
37 #include "net/url_request/url_request_context_getter.h" 40 #include "net/url_request/url_request_context_getter.h"
41 #include "testing/gmock/include/gmock/gmock.h"
38 42
39 namespace { 43 namespace {
40 44
41 // Waits until a PageLoadMetricsMsg_TimingUpdated message IPC is received 45 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) {
42 // matching a PageLoadTiming. See WaitForMatchingIPC for details. 46 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
43 class TimingUpdatedObserver : public content::BrowserMessageFilter { 47 net::HttpCache* cache(
48 getter->GetURLRequestContext()->http_transaction_factory()->GetCache());
49 DCHECK(cache);
50 std::unique_ptr<net::FailingHttpTransactionFactory> factory(
51 new net::FailingHttpTransactionFactory(cache->GetSession(),
52 net::ERR_FAILED));
53 // Throw away old version; since this is a browser test, there is no
54 // need to restore the old state.
55 cache->SetHttpNetworkTransactionFactoryForTesting(std::move(factory));
56 }
57
58 // Wait until we dispatch PageLoadTiming through UpdateTiming.
59 // matching a PageLoadTiming. See WaitForTimingUpdated for details.
60 class PageLoadTimingObserver {
44 public: 61 public:
45 // A bitvector to express which timing fields to match on. 62 // A bitvector to express which timing fields to match on.
46 enum ExpectedTimingFields { 63 enum ExpectedTimingFields {
47 FIRST_PAINT = 1 << 0, 64 FIRST_PAINT = 1 << 0,
48 FIRST_CONTENTFUL_PAINT = 1 << 1, 65 FIRST_CONTENTFUL_PAINT = 1 << 1,
49 STYLE_UPDATE_BEFORE_FCP = 1 << 2 66 STYLE_UPDATE_BEFORE_FCP = 1 << 2
50 }; 67 };
51 68
52 explicit TimingUpdatedObserver(content::RenderWidgetHost* render_widget_host) 69 PageLoadTimingObserver() {
53 : content::BrowserMessageFilter(PageLoadMetricsMsgStart) {
54 render_widget_host->GetProcess()->AddFilter(this);
55
56 // Roundtrip to the IO thread, to ensure that the filter is properly 70 // Roundtrip to the IO thread, to ensure that the filter is properly
57 // installed. 71 // installed.
58 content::BrowserThread::PostTaskAndReply( 72 content::BrowserThread::PostTaskAndReply(
59 content::BrowserThread::IO, FROM_HERE, base::BindOnce(&base::DoNothing), 73 content::BrowserThread::IO, FROM_HERE, base::Bind(&base::DoNothing),
60 base::BindOnce(&TimingUpdatedObserver::Quit, this)); 74 base::Bind(&PageLoadTimingObserver::Quit, base::Unretained(this)));
61 run_loop_.reset(new base::RunLoop()); 75 run_loop_.reset(new base::RunLoop());
62 run_loop_->Run(); 76 run_loop_->Run();
63 run_loop_.reset(nullptr); 77 run_loop_.reset(nullptr);
64 } 78 }
65 79
80 ~PageLoadTimingObserver() {}
81
66 // Add the given timing fields to the set of fields to match on. 82 // Add the given timing fields to the set of fields to match on.
67 void AddMatchingFields(ExpectedTimingFields fields) { 83 void AddMatchingFields(ExpectedTimingFields fields) {
68 matching_fields_ |= fields; 84 matching_fields_ |= fields;
69 } 85 }
70 86
71 // Instructs observer to also watch for |count| 87 // Instructs observer to also watch for |count|
72 // WebLoadingBehaviorDocumentWriteBlockReload events. 88 // WebLoadingBehaviorDocumentWriteBlockReload events.
73 void MatchDocumentWriteBlockReload(int count) { 89 void MatchDocumentWriteBlockReload(int count) {
74 match_document_write_block_reload_ = count; 90 match_document_write_block_reload_ = count;
75 } 91 }
76 92
93 // Waits for a PageLoadTiming that matches the fields set by
77 // Waits for a TimingUpdated IPC that matches the fields set by 94 // Waits for a TimingUpdated IPC that matches the fields set by
78 // |AddMatchingFields|. All matching fields must be set in a TimingUpdated 95 // UpdateTiming to end this wait.
79 // IPC for it to end this wait. 96 void WaitForTimingUpdated() {
80 void WaitForMatchingIPC() {
81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 97 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
82 if (matched_timing_update_) 98 if (matched_timing_update_)
83 return; 99 return;
84 100
85 run_loop_.reset(new base::RunLoop()); 101 run_loop_.reset(new base::RunLoop());
86 run_loop_->Run(); 102 run_loop_->Run();
87 run_loop_.reset(nullptr); 103 run_loop_.reset(nullptr);
88 } 104 }
89 105
90 private: 106 void UpdateTiming(const page_load_metrics::PageLoadTiming& timing,
91 bool OnMessageReceived(const IPC::Message& message) override { 107 const page_load_metrics::PageLoadMetadata& metadata) {
92 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
93
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 && 108 if (match_document_write_block_reload_ > 0 &&
104 metadata.behavior_flags & 109 metadata.behavior_flags &
105 blink::WebLoadingBehaviorFlag:: 110 blink::WebLoadingBehaviorFlag::
106 kWebLoadingBehaviorDocumentWriteBlockReload) { 111 kWebLoadingBehaviorDocumentWriteBlockReload) {
107 --match_document_write_block_reload_; 112 --match_document_write_block_reload_;
108 } 113 }
109 114
110 if (match_document_write_block_reload_ > 0) { 115 if (match_document_write_block_reload_ > 0) {
111 return true; 116 return;
112 } 117 }
113 118
114 if ((!(matching_fields_ & FIRST_PAINT) || 119 if ((!(matching_fields_ & FIRST_PAINT) ||
115 timing.paint_timing.first_paint) && 120 timing.paint_timing.first_paint) &&
116 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) || 121 (!(matching_fields_ & FIRST_CONTENTFUL_PAINT) ||
117 timing.paint_timing.first_contentful_paint) && 122 timing.paint_timing.first_contentful_paint) &&
118 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) || 123 (!(matching_fields_ & STYLE_UPDATE_BEFORE_FCP) ||
119 timing.style_sheet_timing.update_style_duration_before_fcp)) { 124 timing.style_sheet_timing.update_style_duration_before_fcp)) {
120 // Ensure that any other handlers of this message, for example the real 125 // Ensure that any other handlers of this message, for example the real
121 // PageLoadMetric observers, get a chance to handle this message before 126 // PageLoadMetric observers, get a chance to handle this message before
122 // this waiter unblocks. 127 // this waiter unblocks.
123 content::BrowserThread::PostTask( 128 content::BrowserThread::PostTask(
124 content::BrowserThread::IO, FROM_HERE, 129 content::BrowserThread::IO, FROM_HERE,
125 base::BindOnce(&TimingUpdatedObserver::BounceTimingUpdate, this, 130 base::Bind(&PageLoadTimingObserver::BounceTimingUpdate,
126 timing, metadata)); 131 base::Unretained(this)));
127 } 132 }
128 return true;
129 } 133 }
130 134
131 void BounceTimingUpdate(const page_load_metrics::PageLoadTiming& timing, 135 private:
132 const page_load_metrics::PageLoadMetadata& metadata) { 136 void BounceTimingUpdate() {
133 content::BrowserThread::PostTask( 137 content::BrowserThread::PostTask(
134 content::BrowserThread::UI, FROM_HERE, 138 content::BrowserThread::UI, FROM_HERE,
135 base::BindOnce(&TimingUpdatedObserver::SetTimingUpdatedAndQuit, this)); 139 base::Bind(&PageLoadTimingObserver::SetTimingUpdatedAndQuit,
140 base::Unretained(this)));
136 } 141 }
137 142
138 void Quit() { 143 void Quit() {
139 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
140 if (run_loop_) 145 if (run_loop_)
141 run_loop_->Quit(); 146 run_loop_->Quit();
142 } 147 }
143 148
144 void SetTimingUpdatedAndQuit() { 149 void SetTimingUpdatedAndQuit() {
145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 150 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
146 matched_timing_update_ = true; 151 matched_timing_update_ = true;
147 Quit(); 152 Quit();
148 } 153 }
149 154
150 ~TimingUpdatedObserver() override {}
151
152 std::unique_ptr<base::RunLoop> run_loop_; 155 std::unique_ptr<base::RunLoop> run_loop_;
153 int matching_fields_ = 0; // A bitvector composed from ExpectedTimingFields. 156 int matching_fields_ = 0; // A bitvector composed from ExpectedTimingFields.
154 bool matched_timing_update_ = false; 157 bool matched_timing_update_ = false;
155 int match_document_write_block_reload_ = 0; 158 int match_document_write_block_reload_ = 0;
156 }; 159 };
157 160
158 } // namespace 161 } // namespace
159 162
160 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { 163 namespace page_load_metrics {
164
165 class FakePageLoadMetrics : public mojom::PageLoadMetrics {
161 public: 166 public:
162 PageLoadMetricsBrowserTest() {} 167 explicit FakePageLoadMetrics(content::RenderFrameHost* render_frame_host) {
163 ~PageLoadMetricsBrowserTest() override {} 168 metrics_observer_ = content::WebContentsUserData<
169 page_load_metrics::MetricsWebContentsObserver>::
170 FromWebContents(
171 content::WebContents::FromRenderFrameHost(render_frame_host));
172 metrics_observer_->page_load_metrics_binding_for_testing()
173 .SetCurrentTargetFrameForTesting(render_frame_host);
174 }
175
176 ~FakePageLoadMetrics() override {}
177
178 void AddObserver(PageLoadTimingObserver* observer) {
Bryan McQuade 2017/04/26 16:04:34 ah, I see now why you have this class and this met
Ken Rockot(use gerrit already) 2017/04/26 16:11:41 The messages are always going to be dispatched to
Bryan McQuade 2017/04/26 20:41:51 I decided that adding testing hooks to the non-tes
lpy 2017/04/27 10:58:35 It looks good.
179 observers_.push_back(base::WrapUnique(observer));
180 }
181
182 private:
183 void UpdateTiming(const PageLoadTiming& timing,
184 const PageLoadMetadata& metadata) override {
185 metrics_observer_->UpdateTiming(timing, metadata);
186 for (auto& observer : observers_) {
187 observer->UpdateTiming(timing, metadata);
188 }
189 }
190
191 MetricsWebContentsObserver* metrics_observer_;
192 std::vector<std::unique_ptr<PageLoadTimingObserver>> observers_;
193 };
194
195 } // namespace page_load_metrics
196
197 namespace {
198
199 class FakePageLoadMetricsBinder
200 : public content::WebContentsBindingSetTestBinder<
201 page_load_metrics::mojom::PageLoadMetrics> {
202 public:
203 FakePageLoadMetricsBinder(
204 page_load_metrics::mojom::PageLoadMetrics* page_load_metrics)
205 : page_load_metrics_(page_load_metrics) {}
206 ~FakePageLoadMetricsBinder() override {}
207
208 void BindRequest(content::RenderFrameHost* frame_host,
209 page_load_metrics::mojom::PageLoadMetricsAssociatedRequest
210 request) override {
211 bindings_.AddBinding(page_load_metrics_, std::move(request), frame_host);
212 }
213
214 private:
215 page_load_metrics::mojom::PageLoadMetrics* page_load_metrics_;
216 mojo::AssociatedBindingSet<page_load_metrics::mojom::PageLoadMetrics,
217 content::RenderFrameHost*>
218 bindings_;
219
220 DISALLOW_COPY_AND_ASSIGN(FakePageLoadMetricsBinder);
221 };
222
223 } // namespace
224
225 class PageLoadMetricsMojoficationBrowserTest : public InProcessBrowserTest {
226 public:
227 PageLoadMetricsMojoficationBrowserTest() {}
228 ~PageLoadMetricsMojoficationBrowserTest() override {}
229
230 void SetUpCommandLine(base::CommandLine* command_line) override {
231 // We need to set the feature state before the render process is created,
232 // in order for it to inherit the feature state from the browser process.
233 // SetUp() runs too early, and SetUpOnMainThread() runs too late.
234 scoped_feature_list_.InitAndEnableFeature(
235 features::kPageLoadMetricsMojofication);
236 }
164 237
165 protected: 238 protected:
166 void NavigateToUntrackedUrl() { 239 void NavigateToUntrackedUrl() {
167 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 240 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
168 } 241 }
169 242
170 bool NoPageLoadMetricsRecorded() { 243 bool NoPageLoadMetricsRecorded() {
171 // Determine whether any 'public' page load metrics are recorded. We exclude 244 // Determine whether any 'public' page load metrics are recorded. We exclude
172 // 'internal' metrics as these may be recorded for debugging purposes. 245 // 'internal' metrics as these may be recorded for debugging purposes.
173 size_t total_pageload_histograms = 246 size_t total_pageload_histograms =
174 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); 247 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size();
175 size_t total_internal_histograms = 248 size_t total_internal_histograms =
176 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); 249 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size();
177 DCHECK_GE(total_pageload_histograms, total_internal_histograms); 250 DCHECK_GE(total_pageload_histograms, total_internal_histograms);
178 return total_pageload_histograms - total_internal_histograms == 0; 251 return total_pageload_histograms - total_internal_histograms == 0;
179 } 252 }
180 253
181 scoped_refptr<TimingUpdatedObserver> CreateTimingUpdatedObserver() { 254 PageLoadTimingObserver* CreatePageLoadTimingObserver() {
182 content::WebContents* web_contents = 255 if (!fake_page_load_metrics_) {
183 browser()->tab_strip_model()->GetActiveWebContents(); 256 content::WebContents* web_contents =
184 scoped_refptr<TimingUpdatedObserver> observer(new TimingUpdatedObserver( 257 browser()->tab_strip_model()->GetActiveWebContents();
185 web_contents->GetRenderViewHost()->GetWidget())); 258 fake_page_load_metrics_.reset(new page_load_metrics::FakePageLoadMetrics(
259 web_contents->GetMainFrame()));
260 content::WebContentsBindingSet::GetForWebContents<
261 page_load_metrics::mojom::PageLoadMetrics>(web_contents)
262 ->SetBinderForTesting(base::MakeUnique<FakePageLoadMetricsBinder>(
263 fake_page_load_metrics_.get()));
264 }
265 PageLoadTimingObserver* observer = new PageLoadTimingObserver();
266 fake_page_load_metrics_->AddObserver(observer);
186 return observer; 267 return observer;
187 } 268 }
188 269
270 base::test::ScopedFeatureList scoped_feature_list_;
271 std::unique_ptr<page_load_metrics::FakePageLoadMetrics>
272 fake_page_load_metrics_;
189 base::HistogramTester histogram_tester_; 273 base::HistogramTester histogram_tester_;
190 274
191 private: 275 private:
192 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsBrowserTest); 276 DISALLOW_COPY_AND_ASSIGN(PageLoadMetricsMojoficationBrowserTest);
193 }; 277 };
194 278
195 void FailAllNetworkTransactions(net::URLRequestContextGetter* getter) { 279 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, NoNavigation) {
196 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 280 ASSERT_TRUE(
197 net::HttpCache* cache( 281 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
198 getter->GetURLRequestContext()->http_transaction_factory()->GetCache());
199 DCHECK(cache);
200 std::unique_ptr<net::FailingHttpTransactionFactory> factory(
201 new net::FailingHttpTransactionFactory(cache->GetSession(),
202 net::ERR_FAILED));
203 // Throw away old version; since this is a browser test, there is no
204 // need to restore the old state.
205 cache->SetHttpNetworkTransactionFactoryForTesting(std::move(factory));
206 }
207
208 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoNavigation) {
209 ASSERT_TRUE(embedded_test_server()->Start()); 282 ASSERT_TRUE(embedded_test_server()->Start());
210 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 283 EXPECT_TRUE(NoPageLoadMetricsRecorded());
211 } 284 }
212 285
213 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) { 286 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, NewPage) {
287 ASSERT_TRUE(
288 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
214 ASSERT_TRUE(embedded_test_server()->Start()); 289 ASSERT_TRUE(embedded_test_server()->Start());
215 290
216 ui_test_utils::NavigateToURL(browser(), 291 ui_test_utils::NavigateToURL(browser(),
217 embedded_test_server()->GetURL("/title1.html")); 292 embedded_test_server()->GetURL("/title1.html"));
218 NavigateToUntrackedUrl(); 293 NavigateToUntrackedUrl();
219 294
220 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); 295 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1);
221 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1); 296 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1);
222 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); 297 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
223 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1); 298 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1);
224 histogram_tester_.ExpectTotalCount( 299 histogram_tester_.ExpectTotalCount(
225 internal::kHistogramParseBlockedOnScriptLoad, 1); 300 internal::kHistogramParseBlockedOnScriptLoad, 1);
226 histogram_tester_.ExpectTotalCount( 301 histogram_tester_.ExpectTotalCount(
227 internal::kHistogramParseBlockedOnScriptExecution, 1); 302 internal::kHistogramParseBlockedOnScriptExecution, 1);
228 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 303 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
229 histogram_tester_.ExpectTotalCount( 304 histogram_tester_.ExpectTotalCount(
230 internal::kHistogramPageTimingForegroundDuration, 1); 305 internal::kHistogramPageTimingForegroundDuration, 1);
231 306
232 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics 307 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics
233 // have been recorded. 308 // have been recorded.
234 EXPECT_FALSE(NoPageLoadMetricsRecorded()); 309 EXPECT_FALSE(NoPageLoadMetricsRecorded());
235 } 310 }
236 311
237 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameDocumentNavigation) { 312 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
313 SameDocumentNavigation) {
314 ASSERT_TRUE(
315 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
238 ASSERT_TRUE(embedded_test_server()->Start()); 316 ASSERT_TRUE(embedded_test_server()->Start());
239 317
240 ui_test_utils::NavigateToURL(browser(), 318 ui_test_utils::NavigateToURL(browser(),
241 embedded_test_server()->GetURL("/title1.html")); 319 embedded_test_server()->GetURL("/title1.html"));
242 ui_test_utils::NavigateToURL( 320 ui_test_utils::NavigateToURL(
243 browser(), embedded_test_server()->GetURL("/title1.html#hash")); 321 browser(), embedded_test_server()->GetURL("/title1.html#hash"));
244 NavigateToUntrackedUrl(); 322 NavigateToUntrackedUrl();
245 323
246 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); 324 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1);
247 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1); 325 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1);
248 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); 326 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1);
249 } 327 }
250 328
251 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameUrlNavigation) { 329 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
330 SameUrlNavigation) {
331 ASSERT_TRUE(
332 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
252 ASSERT_TRUE(embedded_test_server()->Start()); 333 ASSERT_TRUE(embedded_test_server()->Start());
253 334
254 ui_test_utils::NavigateToURL(browser(), 335 ui_test_utils::NavigateToURL(browser(),
255 embedded_test_server()->GetURL("/title1.html")); 336 embedded_test_server()->GetURL("/title1.html"));
256 ui_test_utils::NavigateToURL(browser(), 337 ui_test_utils::NavigateToURL(browser(),
257 embedded_test_server()->GetURL("/title1.html")); 338 embedded_test_server()->GetURL("/title1.html"));
258 NavigateToUntrackedUrl(); 339 NavigateToUntrackedUrl();
259 340
260 // We expect one histogram sample for each navigation to title1.html. 341 // We expect one histogram sample for each navigation to title1.html.
261 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 2); 342 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 2);
262 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 2); 343 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 2);
263 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 2); 344 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 2);
264 } 345 }
265 346
266 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NonHtmlMainResource) { 347 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
348 NonHtmlMainResource) {
349 ASSERT_TRUE(
350 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
267 ASSERT_TRUE(embedded_test_server()->Start()); 351 ASSERT_TRUE(embedded_test_server()->Start());
268 352
269 ui_test_utils::NavigateToURL(browser(), 353 ui_test_utils::NavigateToURL(browser(),
270 embedded_test_server()->GetURL("/circle.svg")); 354 embedded_test_server()->GetURL("/circle.svg"));
271 NavigateToUntrackedUrl(); 355 NavigateToUntrackedUrl();
272 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 356 EXPECT_TRUE(NoPageLoadMetricsRecorded());
273 } 357 }
274 358
275 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NonHttpOrHttpsUrl) { 359 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
360 NonHttpOrHttpsUrl) {
361 ASSERT_TRUE(
362 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
276 ASSERT_TRUE(embedded_test_server()->Start()); 363 ASSERT_TRUE(embedded_test_server()->Start());
277 364
278 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL)); 365 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIVersionURL));
279 NavigateToUntrackedUrl(); 366 NavigateToUntrackedUrl();
280 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 367 EXPECT_TRUE(NoPageLoadMetricsRecorded());
281 } 368 }
282 369
283 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, HttpErrorPage) { 370 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, HttpErrorPage) {
371 ASSERT_TRUE(
372 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
284 ASSERT_TRUE(embedded_test_server()->Start()); 373 ASSERT_TRUE(embedded_test_server()->Start());
285 374
286 ui_test_utils::NavigateToURL( 375 ui_test_utils::NavigateToURL(
287 browser(), embedded_test_server()->GetURL("/page_load_metrics/404.html")); 376 browser(), embedded_test_server()->GetURL("/page_load_metrics/404.html"));
288 NavigateToUntrackedUrl(); 377 NavigateToUntrackedUrl();
289 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 378 EXPECT_TRUE(NoPageLoadMetricsRecorded());
290 } 379 }
291 380
292 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, ChromeErrorPage) { 381 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
382 ChromeErrorPage) {
383 ASSERT_TRUE(
384 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
293 ASSERT_TRUE(embedded_test_server()->Start()); 385 ASSERT_TRUE(embedded_test_server()->Start());
294 386
295 // Configure the network stack to fail all attempted loads with a network 387 // Configure the network stack to fail all attempted loads with a network
296 // error, which will cause Chrome to display an error page. 388 // error, which will cause Chrome to display an error page.
297 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter = 389 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter =
298 browser()->profile()->GetRequestContext(); 390 browser()->profile()->GetRequestContext();
299 content::BrowserThread::PostTask( 391 content::BrowserThread::PostTask(
300 content::BrowserThread::IO, FROM_HERE, 392 content::BrowserThread::IO, FROM_HERE,
301 base::BindOnce(&FailAllNetworkTransactions, 393 base::Bind(&FailAllNetworkTransactions,
302 base::RetainedRef(url_request_context_getter))); 394 base::RetainedRef(url_request_context_getter)));
303 395
304 ui_test_utils::NavigateToURL(browser(), 396 ui_test_utils::NavigateToURL(browser(),
305 embedded_test_server()->GetURL("/title1.html")); 397 embedded_test_server()->GetURL("/title1.html"));
306 NavigateToUntrackedUrl(); 398 NavigateToUntrackedUrl();
307 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 399 EXPECT_TRUE(NoPageLoadMetricsRecorded());
308 } 400 }
309 401
310 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, Ignore204Pages) { 402 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, Ignore204Pages) {
403 ASSERT_TRUE(
404 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
311 ASSERT_TRUE(embedded_test_server()->Start()); 405 ASSERT_TRUE(embedded_test_server()->Start());
312 406
313 ui_test_utils::NavigateToURL(browser(), 407 ui_test_utils::NavigateToURL(browser(),
314 embedded_test_server()->GetURL("/page204.html")); 408 embedded_test_server()->GetURL("/page204.html"));
315 NavigateToUntrackedUrl(); 409 NavigateToUntrackedUrl();
316 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 410 EXPECT_TRUE(NoPageLoadMetricsRecorded());
317 } 411 }
318 412
319 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, IgnoreDownloads) { 413 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
414 IgnoreDownloads) {
415 ASSERT_TRUE(
416 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
320 ASSERT_TRUE(embedded_test_server()->Start()); 417 ASSERT_TRUE(embedded_test_server()->Start());
321 418
322 base::ScopedTempDir downloads_directory; 419 base::ScopedTempDir downloads_directory;
323 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir()); 420 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
324 browser()->profile()->GetPrefs()->SetFilePath( 421 browser()->profile()->GetPrefs()->SetFilePath(
325 prefs::kDownloadDefaultDirectory, downloads_directory.GetPath()); 422 prefs::kDownloadDefaultDirectory, downloads_directory.GetPath());
326 content::DownloadTestObserverTerminal downloads_observer( 423 content::DownloadTestObserverTerminal downloads_observer(
327 content::BrowserContext::GetDownloadManager(browser()->profile()), 424 content::BrowserContext::GetDownloadManager(browser()->profile()),
328 1, // == wait_count (only waiting for "download-test3.gif"). 425 1, // == wait_count (only waiting for "download-test3.gif").
329 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 426 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
330 427
331 ui_test_utils::NavigateToURL( 428 ui_test_utils::NavigateToURL(
332 browser(), embedded_test_server()->GetURL("/download-test3.gif")); 429 browser(), embedded_test_server()->GetURL("/download-test3.gif"));
333 downloads_observer.WaitForFinished(); 430 downloads_observer.WaitForFinished();
334 431
335 NavigateToUntrackedUrl(); 432 NavigateToUntrackedUrl();
336 EXPECT_TRUE(NoPageLoadMetricsRecorded()); 433 EXPECT_TRUE(NoPageLoadMetricsRecorded());
337 } 434 }
338 435
339 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PreloadDocumentWrite) { 436 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
437 PreloadDocumentWrite) {
438 ASSERT_TRUE(
439 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
340 ASSERT_TRUE(embedded_test_server()->Start()); 440 ASSERT_TRUE(embedded_test_server()->Start());
341 441
342 scoped_refptr<TimingUpdatedObserver> fcp_observer = 442 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
343 CreateTimingUpdatedObserver();
344 fcp_observer->AddMatchingFields( 443 fcp_observer->AddMatchingFields(
345 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 444 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
346 445
347 ui_test_utils::NavigateToURL( 446 ui_test_utils::NavigateToURL(
348 browser(), embedded_test_server()->GetURL( 447 browser(), embedded_test_server()->GetURL(
349 "/page_load_metrics/document_write_external_script.html")); 448 "/page_load_metrics/document_write_external_script.html"));
350 fcp_observer->WaitForMatchingIPC(); 449 fcp_observer->WaitForTimingUpdated();
351 450
352 histogram_tester_.ExpectTotalCount( 451 histogram_tester_.ExpectTotalCount(
353 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1); 452 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 1);
354 } 453 }
355 454
356 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPreloadDocumentWrite) { 455 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
456 NoPreloadDocumentWrite) {
457 ASSERT_TRUE(
458 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
357 ASSERT_TRUE(embedded_test_server()->Start()); 459 ASSERT_TRUE(embedded_test_server()->Start());
358 460
359 ui_test_utils::NavigateToURL( 461 ui_test_utils::NavigateToURL(
360 browser(), embedded_test_server()->GetURL( 462 browser(), embedded_test_server()->GetURL(
361 "/page_load_metrics/document_write_no_script.html")); 463 "/page_load_metrics/document_write_no_script.html"));
362 NavigateToUntrackedUrl(); 464 NavigateToUntrackedUrl();
363 465
364 histogram_tester_.ExpectTotalCount( 466 histogram_tester_.ExpectTotalCount(
365 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); 467 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0);
366 } 468 }
367 469
368 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWrite) { 470 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
471 NoDocumentWrite) {
472 ASSERT_TRUE(
473 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
369 ASSERT_TRUE(embedded_test_server()->Start()); 474 ASSERT_TRUE(embedded_test_server()->Start());
370 475
371 scoped_refptr<TimingUpdatedObserver> fcp_observer = 476 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
372 CreateTimingUpdatedObserver();
373 fcp_observer->AddMatchingFields( 477 fcp_observer->AddMatchingFields(
374 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 478 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
375 479
376 ui_test_utils::NavigateToURL(browser(), 480 ui_test_utils::NavigateToURL(browser(),
377 embedded_test_server()->GetURL("/title1.html")); 481 embedded_test_server()->GetURL("/title1.html"));
378 fcp_observer->WaitForMatchingIPC(); 482 fcp_observer->WaitForTimingUpdated();
379 483
380 histogram_tester_.ExpectTotalCount( 484 histogram_tester_.ExpectTotalCount(
381 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0); 485 internal::kHistogramDocWriteParseStartToFirstContentfulPaint, 0);
382 histogram_tester_.ExpectTotalCount( 486 histogram_tester_.ExpectTotalCount(
383 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); 487 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0);
384 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); 488 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0);
385 } 489 }
386 490
387 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteBlock) { 491 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
492 DocumentWriteBlock) {
493 ASSERT_TRUE(
494 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
388 ASSERT_TRUE(embedded_test_server()->Start()); 495 ASSERT_TRUE(embedded_test_server()->Start());
389 496
390 scoped_refptr<TimingUpdatedObserver> fcp_observer = 497 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
391 CreateTimingUpdatedObserver();
392 fcp_observer->AddMatchingFields( 498 fcp_observer->AddMatchingFields(
393 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 499 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
394 500
395 ui_test_utils::NavigateToURL( 501 ui_test_utils::NavigateToURL(
396 browser(), embedded_test_server()->GetURL( 502 browser(), embedded_test_server()->GetURL(
397 "/page_load_metrics/document_write_script_block.html")); 503 "/page_load_metrics/document_write_script_block.html"));
398 fcp_observer->WaitForMatchingIPC(); 504 fcp_observer->WaitForTimingUpdated();
399 505
400 histogram_tester_.ExpectTotalCount( 506 histogram_tester_.ExpectTotalCount(
401 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); 507 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
402 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); 508 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1);
403 } 509 }
404 510
405 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteReload) { 511 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
512 DocumentWriteReload) {
513 ASSERT_TRUE(
514 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
406 ASSERT_TRUE(embedded_test_server()->Start()); 515 ASSERT_TRUE(embedded_test_server()->Start());
407 516
408 scoped_refptr<TimingUpdatedObserver> fcp_observer = 517 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
409 CreateTimingUpdatedObserver();
410 fcp_observer->AddMatchingFields( 518 fcp_observer->AddMatchingFields(
411 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 519 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
412 scoped_refptr<TimingUpdatedObserver> reload_observer = 520 PageLoadTimingObserver* reload_observer = CreatePageLoadTimingObserver();
413 CreateTimingUpdatedObserver();
414 reload_observer->MatchDocumentWriteBlockReload(2); 521 reload_observer->MatchDocumentWriteBlockReload(2);
415 522
416 ui_test_utils::NavigateToURL( 523 ui_test_utils::NavigateToURL(
417 browser(), embedded_test_server()->GetURL( 524 browser(), embedded_test_server()->GetURL(
418 "/page_load_metrics/document_write_script_block.html")); 525 "/page_load_metrics/document_write_script_block.html"));
419 526
420 // Reload should not log the histogram as the script is not blocked. 527 // Reload should not log the histogram as the script is not blocked.
421 ui_test_utils::NavigateToURL( 528 ui_test_utils::NavigateToURL(
422 browser(), embedded_test_server()->GetURL( 529 browser(), embedded_test_server()->GetURL(
423 "/page_load_metrics/document_write_script_block.html")); 530 "/page_load_metrics/document_write_script_block.html"));
424 531
425 ui_test_utils::NavigateToURL( 532 ui_test_utils::NavigateToURL(
426 browser(), embedded_test_server()->GetURL( 533 browser(), embedded_test_server()->GetURL(
427 "/page_load_metrics/document_write_script_block.html")); 534 "/page_load_metrics/document_write_script_block.html"));
428 535
429 histogram_tester_.ExpectTotalCount( 536 histogram_tester_.ExpectTotalCount(
430 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); 537 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
431 538
432 fcp_observer->WaitForMatchingIPC(); 539 fcp_observer->WaitForTimingUpdated();
433 reload_observer->WaitForMatchingIPC(); 540 reload_observer->WaitForTimingUpdated();
434 541
435 histogram_tester_.ExpectTotalCount( 542 histogram_tester_.ExpectTotalCount(
436 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1); 543 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 1);
437 544
438 histogram_tester_.ExpectTotalCount( 545 histogram_tester_.ExpectTotalCount(
439 internal::kHistogramDocWriteBlockReloadCount, 2); 546 internal::kHistogramDocWriteBlockReloadCount, 2);
440 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1); 547 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 1);
441 } 548 }
442 549
443 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteAsync) { 550 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
551 DocumentWriteAsync) {
552 ASSERT_TRUE(
553 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
444 ASSERT_TRUE(embedded_test_server()->Start()); 554 ASSERT_TRUE(embedded_test_server()->Start());
445 555
446 ui_test_utils::NavigateToURL( 556 ui_test_utils::NavigateToURL(
447 browser(), embedded_test_server()->GetURL( 557 browser(), embedded_test_server()->GetURL(
448 "/page_load_metrics/document_write_script_async.html")); 558 "/page_load_metrics/document_write_script_async.html"));
449 NavigateToUntrackedUrl(); 559 NavigateToUntrackedUrl();
450 560
451 histogram_tester_.ExpectTotalCount( 561 histogram_tester_.ExpectTotalCount(
452 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); 562 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0);
453 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); 563 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0);
454 } 564 }
455 565
456 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, DocumentWriteSameDomain) { 566 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
567 DocumentWriteSameDomain) {
568 ASSERT_TRUE(
569 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
457 ASSERT_TRUE(embedded_test_server()->Start()); 570 ASSERT_TRUE(embedded_test_server()->Start());
458 571
459 ui_test_utils::NavigateToURL( 572 ui_test_utils::NavigateToURL(
460 browser(), embedded_test_server()->GetURL( 573 browser(), embedded_test_server()->GetURL(
461 "/page_load_metrics/document_write_external_script.html")); 574 "/page_load_metrics/document_write_external_script.html"));
462 NavigateToUntrackedUrl(); 575 NavigateToUntrackedUrl();
463 576
464 histogram_tester_.ExpectTotalCount( 577 histogram_tester_.ExpectTotalCount(
465 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); 578 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0);
466 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); 579 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0);
467 } 580 }
468 581
469 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoDocumentWriteScript) { 582 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
583 NoDocumentWriteScript) {
584 ASSERT_TRUE(
585 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
470 ASSERT_TRUE(embedded_test_server()->Start()); 586 ASSERT_TRUE(embedded_test_server()->Start());
471 587
472 ui_test_utils::NavigateToURL( 588 ui_test_utils::NavigateToURL(
473 browser(), embedded_test_server()->GetURL( 589 browser(), embedded_test_server()->GetURL(
474 "/page_load_metrics/document_write_no_script.html")); 590 "/page_load_metrics/document_write_no_script.html"));
475 NavigateToUntrackedUrl(); 591 NavigateToUntrackedUrl();
476 592
477 histogram_tester_.ExpectTotalCount( 593 histogram_tester_.ExpectTotalCount(
478 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0); 594 internal::kHistogramDocWriteBlockParseStartToFirstContentfulPaint, 0);
479 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0); 595 histogram_tester_.ExpectTotalCount(internal::kHistogramDocWriteBlockCount, 0);
480 } 596 }
481 597
482 // TODO(crbug.com/712935): Flaky on Linux dbg. 598 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, BadXhtml) {
483 #if defined(OS_LINUX) && !defined(NDEBUG) 599 ASSERT_TRUE(
484 #define MAYBE_BadXhtml DISABLED_BadXhtml 600 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
485 #else
486 #define MAYBE_BadXhtml BadXhtml
487 #endif
488 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_BadXhtml) {
489 ASSERT_TRUE(embedded_test_server()->Start()); 601 ASSERT_TRUE(embedded_test_server()->Start());
490 602
491 scoped_refptr<TimingUpdatedObserver> timing_observer = 603 PageLoadTimingObserver* timing_observer = CreatePageLoadTimingObserver();
492 CreateTimingUpdatedObserver(); 604 timing_observer->AddMatchingFields(PageLoadTimingObserver::FIRST_PAINT);
493 timing_observer->AddMatchingFields(TimingUpdatedObserver::FIRST_PAINT);
494 605
495 // When an XHTML page contains invalid XML, it causes a paint of the error 606 // 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 607 // 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 608 // 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 609 // documents with non-well-formed XML on the blink side. See crbug.com/627607
499 // for more. 610 // for more.
500 ui_test_utils::NavigateToURL( 611 ui_test_utils::NavigateToURL(
501 browser(), 612 browser(),
502 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml")); 613 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml"));
503 614
504 timing_observer->WaitForMatchingIPC(); 615 timing_observer->WaitForTimingUpdated();
505 616
506 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0); 617 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0);
507 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); 618 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0);
508 histogram_tester_.ExpectTotalCount(page_load_metrics::internal::kErrorEvents, 619 histogram_tester_.ExpectTotalCount(page_load_metrics::internal::kErrorEvents,
509 1); 620 1);
510 histogram_tester_.ExpectBucketCount( 621 histogram_tester_.ExpectBucketCount(
511 page_load_metrics::internal::kErrorEvents, 622 page_load_metrics::internal::kErrorEvents,
512 page_load_metrics::ERR_BAD_TIMING_IPC_INVALID_TIMING, 1); 623 page_load_metrics::ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
513 624
514 histogram_tester_.ExpectTotalCount( 625 histogram_tester_.ExpectTotalCount(
515 page_load_metrics::internal::kPageLoadTimingStatus, 1); 626 page_load_metrics::internal::kPageLoadTimingStatus, 1);
516 histogram_tester_.ExpectBucketCount( 627 histogram_tester_.ExpectBucketCount(
517 page_load_metrics::internal::kPageLoadTimingStatus, 628 page_load_metrics::internal::kPageLoadTimingStatus,
518 page_load_metrics::internal::INVALID_ORDER_FIRST_LAYOUT_FIRST_PAINT, 1); 629 page_load_metrics::internal::INVALID_ORDER_FIRST_LAYOUT_FIRST_PAINT, 1);
519 } 630 }
520 631
521 // Test code that aborts provisional navigations. 632 // Test code that aborts provisional navigations.
522 // TODO(csharrison): Move these to unit tests once the navigation API in content 633 // TODO(csharrison): Move these to unit tests once the navigation API in content
523 // properly calls NavigationHandle/NavigationThrottle methods. 634 // properly calls NavigationHandle/NavigationThrottle methods.
524 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, AbortNewNavigation) { 635 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
636 AbortNewNavigation) {
637 ASSERT_TRUE(
638 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
525 ASSERT_TRUE(embedded_test_server()->Start()); 639 ASSERT_TRUE(embedded_test_server()->Start());
526 640
527 GURL url(embedded_test_server()->GetURL("/title1.html")); 641 GURL url(embedded_test_server()->GetURL("/title1.html"));
528 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK); 642 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
529 content::TestNavigationManager manager( 643 content::TestNavigationManager manager(
530 browser()->tab_strip_model()->GetActiveWebContents(), url); 644 browser()->tab_strip_model()->GetActiveWebContents(), url);
531 645
532 chrome::Navigate(&params); 646 chrome::Navigate(&params);
533 EXPECT_TRUE(manager.WaitForRequestStart()); 647 EXPECT_TRUE(manager.WaitForRequestStart());
534 648
535 GURL url2(embedded_test_server()->GetURL("/title2.html")); 649 GURL url2(embedded_test_server()->GetURL("/title2.html"));
536 chrome::NavigateParams params2(browser(), url2, 650 chrome::NavigateParams params2(browser(), url2,
537 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR); 651 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
538 content::TestNavigationManager manager2( 652 content::TestNavigationManager manager2(
539 browser()->tab_strip_model()->GetActiveWebContents(), url2); 653 browser()->tab_strip_model()->GetActiveWebContents(), url2);
540 chrome::Navigate(&params2); 654 chrome::Navigate(&params2);
541 655
542 manager2.WaitForNavigationFinished(); 656 manager2.WaitForNavigationFinished();
543 histogram_tester_.ExpectTotalCount( 657 histogram_tester_.ExpectTotalCount(
544 internal::kHistogramAbortNewNavigationBeforeCommit, 1); 658 internal::kHistogramAbortNewNavigationBeforeCommit, 1);
545 } 659 }
546 660
547 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, AbortReload) { 661 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, AbortReload) {
662 ASSERT_TRUE(
663 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
548 ASSERT_TRUE(embedded_test_server()->Start()); 664 ASSERT_TRUE(embedded_test_server()->Start());
549 665
550 GURL url(embedded_test_server()->GetURL("/title1.html")); 666 GURL url(embedded_test_server()->GetURL("/title1.html"));
551 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK); 667 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
552 content::TestNavigationManager manager( 668 content::TestNavigationManager manager(
553 browser()->tab_strip_model()->GetActiveWebContents(), url); 669 browser()->tab_strip_model()->GetActiveWebContents(), url);
554 670
555 chrome::Navigate(&params); 671 chrome::Navigate(&params);
556 EXPECT_TRUE(manager.WaitForRequestStart()); 672 EXPECT_TRUE(manager.WaitForRequestStart());
557 673
558 chrome::NavigateParams params2(browser(), url, ui::PAGE_TRANSITION_RELOAD); 674 chrome::NavigateParams params2(browser(), url, ui::PAGE_TRANSITION_RELOAD);
559 content::TestNavigationManager manager2( 675 content::TestNavigationManager manager2(
560 browser()->tab_strip_model()->GetActiveWebContents(), url); 676 browser()->tab_strip_model()->GetActiveWebContents(), url);
561 chrome::Navigate(&params2); 677 chrome::Navigate(&params2);
562 678
563 manager2.WaitForNavigationFinished(); 679 manager2.WaitForNavigationFinished();
564 histogram_tester_.ExpectTotalCount( 680 histogram_tester_.ExpectTotalCount(
565 internal::kHistogramAbortReloadBeforeCommit, 1); 681 internal::kHistogramAbortReloadBeforeCommit, 1);
566 } 682 }
567 683
568 // TODO(crbug.com/675061): Flaky on Win7 dbg. 684 // TODO(crbug.com/675061): Flaky on Win7 dbg.
569 #if defined(OS_WIN) 685 #if defined(OS_WIN)
570 #define MAYBE_AbortClose DISABLED_AbortClose 686 #define MAYBE_AbortClose DISABLED_AbortClose
571 #else 687 #else
572 #define MAYBE_AbortClose AbortClose 688 #define MAYBE_AbortClose AbortClose
573 #endif 689 #endif
574 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, MAYBE_AbortClose) { 690 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
691 MAYBE_AbortClose) {
692 ASSERT_TRUE(
693 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
575 ASSERT_TRUE(embedded_test_server()->Start()); 694 ASSERT_TRUE(embedded_test_server()->Start());
576 695
577 GURL url(embedded_test_server()->GetURL("/title1.html")); 696 GURL url(embedded_test_server()->GetURL("/title1.html"));
578 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK); 697 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
579 content::TestNavigationManager manager( 698 content::TestNavigationManager manager(
580 browser()->tab_strip_model()->GetActiveWebContents(), url); 699 browser()->tab_strip_model()->GetActiveWebContents(), url);
581 700
582 chrome::Navigate(&params); 701 chrome::Navigate(&params);
583 EXPECT_TRUE(manager.WaitForRequestStart()); 702 EXPECT_TRUE(manager.WaitForRequestStart());
584 703
585 browser()->tab_strip_model()->GetActiveWebContents()->Close(); 704 browser()->tab_strip_model()->GetActiveWebContents()->Close();
586 705
587 manager.WaitForNavigationFinished(); 706 manager.WaitForNavigationFinished();
588 707
589 histogram_tester_.ExpectTotalCount(internal::kHistogramAbortCloseBeforeCommit, 708 histogram_tester_.ExpectTotalCount(internal::kHistogramAbortCloseBeforeCommit,
590 1); 709 1);
591 } 710 }
592 711
593 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, AbortMultiple) { 712 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, AbortMultiple) {
713 ASSERT_TRUE(
714 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
594 ASSERT_TRUE(embedded_test_server()->Start()); 715 ASSERT_TRUE(embedded_test_server()->Start());
595 716
596 GURL url(embedded_test_server()->GetURL("/title1.html")); 717 GURL url(embedded_test_server()->GetURL("/title1.html"));
597 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK); 718 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
598 content::TestNavigationManager manager( 719 content::TestNavigationManager manager(
599 browser()->tab_strip_model()->GetActiveWebContents(), url); 720 browser()->tab_strip_model()->GetActiveWebContents(), url);
600 721
601 chrome::Navigate(&params); 722 chrome::Navigate(&params);
602 EXPECT_TRUE(manager.WaitForRequestStart()); 723 EXPECT_TRUE(manager.WaitForRequestStart());
603 724
(...skipping 14 matching lines...) Expand all
618 739
619 EXPECT_TRUE(manager3.WaitForRequestStart()); 740 EXPECT_TRUE(manager3.WaitForRequestStart());
620 manager2.WaitForNavigationFinished(); 741 manager2.WaitForNavigationFinished();
621 742
622 manager3.WaitForNavigationFinished(); 743 manager3.WaitForNavigationFinished();
623 744
624 histogram_tester_.ExpectTotalCount( 745 histogram_tester_.ExpectTotalCount(
625 internal::kHistogramAbortNewNavigationBeforeCommit, 2); 746 internal::kHistogramAbortNewNavigationBeforeCommit, 2);
626 } 747 }
627 748
628 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 749 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
629 NoAbortMetricsOnClientRedirect) { 750 NoAbortMetricsOnClientRedirect) {
751 ASSERT_TRUE(
752 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
630 ASSERT_TRUE(embedded_test_server()->Start()); 753 ASSERT_TRUE(embedded_test_server()->Start());
631 754
632 GURL first_url(embedded_test_server()->GetURL("/title1.html")); 755 GURL first_url(embedded_test_server()->GetURL("/title1.html"));
633 ui_test_utils::NavigateToURL(browser(), first_url); 756 ui_test_utils::NavigateToURL(browser(), first_url);
634 757
635 GURL second_url(embedded_test_server()->GetURL("/title2.html")); 758 GURL second_url(embedded_test_server()->GetURL("/title2.html"));
636 chrome::NavigateParams params(browser(), second_url, 759 chrome::NavigateParams params(browser(), second_url,
637 ui::PAGE_TRANSITION_LINK); 760 ui::PAGE_TRANSITION_LINK);
638 content::TestNavigationManager manager( 761 content::TestNavigationManager manager(
639 browser()->tab_strip_model()->GetActiveWebContents(), second_url); 762 browser()->tab_strip_model()->GetActiveWebContents(), second_url);
640 chrome::Navigate(&params); 763 chrome::Navigate(&params);
641 EXPECT_TRUE(manager.WaitForRequestStart()); 764 EXPECT_TRUE(manager.WaitForRequestStart());
642 765
643 { 766 {
644 content::TestNavigationManager reload_manager( 767 content::TestNavigationManager reload_manager(
645 browser()->tab_strip_model()->GetActiveWebContents(), first_url); 768 browser()->tab_strip_model()->GetActiveWebContents(), first_url);
646 EXPECT_TRUE(content::ExecuteScript( 769 EXPECT_TRUE(content::ExecuteScript(
647 browser()->tab_strip_model()->GetActiveWebContents(), 770 browser()->tab_strip_model()->GetActiveWebContents(),
648 "window.location.reload();")); 771 "window.location.reload();"));
649 } 772 }
650 773
651 manager.WaitForNavigationFinished(); 774 manager.WaitForNavigationFinished();
652 775
653 EXPECT_TRUE(histogram_tester_ 776 EXPECT_TRUE(histogram_tester_
654 .GetTotalCountsForPrefix("PageLoad.Experimental.AbortTiming.") 777 .GetTotalCountsForPrefix("PageLoad.Experimental.AbortTiming.")
655 .empty()); 778 .empty());
656 } 779 }
657 780
658 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 781 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
659 FirstMeaningfulPaintRecorded) { 782 FirstMeaningfulPaintRecorded) {
783 ASSERT_TRUE(
784 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
660 ASSERT_TRUE(embedded_test_server()->Start()); 785 ASSERT_TRUE(embedded_test_server()->Start());
661 786
662 ui_test_utils::NavigateToURL(browser(), 787 ui_test_utils::NavigateToURL(browser(),
663 embedded_test_server()->GetURL("/title1.html")); 788 embedded_test_server()->GetURL("/title1.html"));
664 789
665 // Wait until the renderer finishes observing layouts. 790 // Wait until the renderer finishes observing layouts.
666 const int kNetworkIdleTime = 3000; 791 const int kNetworkIdleTime = 3000;
667 const int kMargin = 500; 792 const int kMargin = 500;
668 const std::string javascript = base::StringPrintf( 793 const std::string javascript = base::StringPrintf(
669 "setTimeout(() => window.domAutomationController.send(true), %d)", 794 "setTimeout(() => window.domAutomationController.send(true), %d)",
670 kNetworkIdleTime + kMargin); 795 kNetworkIdleTime + kMargin);
671 bool result; 796 bool result;
672 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 797 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
673 browser()->tab_strip_model()->GetActiveWebContents(), 798 browser()->tab_strip_model()->GetActiveWebContents(), javascript,
674 javascript, &result)); 799 &result));
675 EXPECT_TRUE(result); 800 EXPECT_TRUE(result);
676 801
677 NavigateToUntrackedUrl(); 802 NavigateToUntrackedUrl();
678 histogram_tester_.ExpectUniqueSample( 803 histogram_tester_.ExpectUniqueSample(
679 internal::kHistogramFirstMeaningfulPaintStatus, 804 internal::kHistogramFirstMeaningfulPaintStatus,
680 internal::FIRST_MEANINGFUL_PAINT_RECORDED, 1); 805 internal::FIRST_MEANINGFUL_PAINT_RECORDED, 1);
681 histogram_tester_.ExpectTotalCount( 806 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstMeaningfulPaint,
682 internal::kHistogramFirstMeaningfulPaint, 1); 807 1);
683 histogram_tester_.ExpectTotalCount( 808 histogram_tester_.ExpectTotalCount(
684 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); 809 internal::kHistogramParseStartToFirstMeaningfulPaint, 1);
685 } 810 }
686 811
687 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 812 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
688 FirstMeaningfulPaintNotRecorded) { 813 FirstMeaningfulPaintNotRecorded) {
814 ASSERT_TRUE(
815 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
689 ASSERT_TRUE(embedded_test_server()->Start()); 816 ASSERT_TRUE(embedded_test_server()->Start());
690 817
691 scoped_refptr<TimingUpdatedObserver> fcp_observer = 818 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
692 CreateTimingUpdatedObserver();
693 fcp_observer->AddMatchingFields( 819 fcp_observer->AddMatchingFields(
694 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 820 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
695 821
696 ui_test_utils::NavigateToURL( 822 ui_test_utils::NavigateToURL(
697 browser(), embedded_test_server()->GetURL( 823 browser(), embedded_test_server()->GetURL(
698 "/page_load_metrics/page_with_active_connections.html")); 824 "/page_load_metrics/page_with_active_connections.html"));
699 fcp_observer->WaitForMatchingIPC(); 825 fcp_observer->WaitForTimingUpdated();
700 826
701 // Navigate away before a FMP is reported. 827 // Navigate away before a FMP is reported.
702 NavigateToUntrackedUrl(); 828 NavigateToUntrackedUrl();
703 829
704 histogram_tester_.ExpectUniqueSample( 830 histogram_tester_.ExpectUniqueSample(
705 internal::kHistogramFirstMeaningfulPaintStatus, 831 internal::kHistogramFirstMeaningfulPaintStatus,
706 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1); 832 internal::FIRST_MEANINGFUL_PAINT_DID_NOT_REACH_NETWORK_STABLE, 1);
707 histogram_tester_.ExpectTotalCount( 833 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstMeaningfulPaint,
708 internal::kHistogramFirstMeaningfulPaint, 0); 834 0);
709 histogram_tester_.ExpectTotalCount( 835 histogram_tester_.ExpectTotalCount(
710 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); 836 internal::kHistogramParseStartToFirstMeaningfulPaint, 0);
711 } 837 }
712 838
713 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 839 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
714 NoStatePrefetchObserverCacheable) { 840 NoStatePrefetchObserverCacheable) {
841 ASSERT_TRUE(
842 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
715 ASSERT_TRUE(embedded_test_server()->Start()); 843 ASSERT_TRUE(embedded_test_server()->Start());
716 844
717 scoped_refptr<TimingUpdatedObserver> fcp_observer = 845 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
718 CreateTimingUpdatedObserver();
719 fcp_observer->AddMatchingFields( 846 fcp_observer->AddMatchingFields(
720 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 847 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
721 848
722 ui_test_utils::NavigateToURL(browser(), 849 ui_test_utils::NavigateToURL(browser(),
723 embedded_test_server()->GetURL("/title1.html")); 850 embedded_test_server()->GetURL("/title1.html"));
724 851
725 fcp_observer->WaitForMatchingIPC(); 852 fcp_observer->WaitForTimingUpdated();
726 853
727 histogram_tester_.ExpectTotalCount( 854 histogram_tester_.ExpectTotalCount(
728 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0); 855 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 0);
729 histogram_tester_.ExpectTotalCount( 856 histogram_tester_.ExpectTotalCount(
730 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1); 857 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 1);
731 } 858 }
732 859
733 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, 860 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest,
734 NoStatePrefetchObserverNoStore) { 861 NoStatePrefetchObserverNoStore) {
862 ASSERT_TRUE(
863 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
735 ASSERT_TRUE(embedded_test_server()->Start()); 864 ASSERT_TRUE(embedded_test_server()->Start());
736 865
737 scoped_refptr<TimingUpdatedObserver> fcp_observer = 866 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
738 CreateTimingUpdatedObserver();
739 fcp_observer->AddMatchingFields( 867 fcp_observer->AddMatchingFields(
740 TimingUpdatedObserver::FIRST_CONTENTFUL_PAINT); 868 PageLoadTimingObserver::FIRST_CONTENTFUL_PAINT);
741 869
742 ui_test_utils::NavigateToURL(browser(), 870 ui_test_utils::NavigateToURL(browser(),
743 embedded_test_server()->GetURL("/nostore.html")); 871 embedded_test_server()->GetURL("/nostore.html"));
744 872
745 fcp_observer->WaitForMatchingIPC(); 873 fcp_observer->WaitForTimingUpdated();
746 874
747 histogram_tester_.ExpectTotalCount( 875 histogram_tester_.ExpectTotalCount(
748 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1); 876 "Prerender.none_PrefetchTTFCP.Reference.NoStore.Visible", 1);
749 histogram_tester_.ExpectTotalCount( 877 histogram_tester_.ExpectTotalCount(
750 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0); 878 "Prerender.none_PrefetchTTFCP.Reference.Cacheable.Visible", 0);
751 } 879 }
752 880
753 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, CSSTiming) { 881 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, CSSTiming) {
882 ASSERT_TRUE(
883 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
754 ASSERT_TRUE(embedded_test_server()->Start()); 884 ASSERT_TRUE(embedded_test_server()->Start());
755 885
756 scoped_refptr<TimingUpdatedObserver> fcp_observer = 886 PageLoadTimingObserver* fcp_observer = CreatePageLoadTimingObserver();
757 CreateTimingUpdatedObserver();
758 fcp_observer->AddMatchingFields( 887 fcp_observer->AddMatchingFields(
759 TimingUpdatedObserver::STYLE_UPDATE_BEFORE_FCP); 888 PageLoadTimingObserver::STYLE_UPDATE_BEFORE_FCP);
760 889
761 // Careful: Blink code clamps timestamps to 5us, so any CSS parsing we do here 890 // 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 891 // must take >> 5us, otherwise we'll log 0 for the value and it will remain
763 // unset here. 892 // unset here.
764 ui_test_utils::NavigateToURL( 893 ui_test_utils::NavigateToURL(
765 browser(), 894 browser(),
766 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html")); 895 embedded_test_server()->GetURL("/page_load_metrics/page_with_css.html"));
767 NavigateToUntrackedUrl(); 896 NavigateToUntrackedUrl();
768 fcp_observer->WaitForMatchingIPC(); 897 fcp_observer->WaitForTimingUpdated();
769 898
770 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint, 899 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstContentfulPaint,
771 1); 900 1);
772 histogram_tester_.ExpectTotalCount( 901 histogram_tester_.ExpectTotalCount(
773 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1); 902 "PageLoad.CSSTiming.Parse.BeforeFirstContentfulPaint", 1);
774 histogram_tester_.ExpectTotalCount( 903 histogram_tester_.ExpectTotalCount(
775 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1); 904 "PageLoad.CSSTiming.Update.BeforeFirstContentfulPaint", 1);
776 histogram_tester_.ExpectTotalCount( 905 histogram_tester_.ExpectTotalCount(
777 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1); 906 "PageLoad.CSSTiming.ParseAndUpdate.BeforeFirstContentfulPaint", 1);
778 } 907 }
779 908
780 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PayloadSize) { 909 IN_PROC_BROWSER_TEST_F(PageLoadMetricsMojoficationBrowserTest, PayloadSize) {
910 ASSERT_TRUE(
911 base::FeatureList::IsEnabled(features::kPageLoadMetricsMojofication));
781 ASSERT_TRUE(embedded_test_server()->Start()); 912 ASSERT_TRUE(embedded_test_server()->Start());
782 913
783 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( 914 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
784 "/page_load_metrics/large.html")); 915 "/page_load_metrics/large.html"));
785 NavigateToUntrackedUrl(); 916 NavigateToUntrackedUrl();
786 917
787 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 918 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
788 919
789 // Verify that there is a single sample recorded in the 10kB bucket (the size 920 // Verify that there is a single sample recorded in the 10kB bucket (the size
790 // of the main HTML response). 921 // of the main HTML response).
791 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); 922 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1);
792 } 923 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698