| OLD | NEW |
| 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/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" | 10 #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
| 27 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 30 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 31 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| 32 #include "content/public/test/download_test_observer.h" | 32 #include "content/public/test/download_test_observer.h" |
| 33 #include "net/dns/mock_host_resolver.h" |
| 33 #include "net/http/failing_http_transaction_factory.h" | 34 #include "net/http/failing_http_transaction_factory.h" |
| 34 #include "net/http/http_cache.h" | 35 #include "net/http/http_cache.h" |
| 35 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 36 #include "net/test/url_request/url_request_failed_job.h" | 37 #include "net/test/url_request/url_request_failed_job.h" |
| 37 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
| 38 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // Waits until specified timing and metadata expectations are satisfied. | 43 // Waits until specified timing and metadata expectations are satisfied. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { | 119 class PageLoadMetricsBrowserTest : public InProcessBrowserTest { |
| 119 public: | 120 public: |
| 120 PageLoadMetricsBrowserTest() {} | 121 PageLoadMetricsBrowserTest() {} |
| 121 ~PageLoadMetricsBrowserTest() override {} | 122 ~PageLoadMetricsBrowserTest() override {} |
| 122 | 123 |
| 123 protected: | 124 protected: |
| 124 void NavigateToUntrackedUrl() { | 125 void NavigateToUntrackedUrl() { |
| 125 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); | 126 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); |
| 126 } | 127 } |
| 127 | 128 |
| 129 void SetUpOnMainThread() override { |
| 130 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 131 host_resolver()->AddRule("b.com", "127.0.0.1"); |
| 132 content::SetupCrossSiteRedirector(embedded_test_server()); |
| 133 } |
| 134 |
| 128 bool NoPageLoadMetricsRecorded() { | 135 bool NoPageLoadMetricsRecorded() { |
| 129 // Determine whether any 'public' page load metrics are recorded. We exclude | 136 // Determine whether any 'public' page load metrics are recorded. We exclude |
| 130 // 'internal' metrics as these may be recorded for debugging purposes. | 137 // 'internal' metrics as these may be recorded for debugging purposes. |
| 131 size_t total_pageload_histograms = | 138 size_t total_pageload_histograms = |
| 132 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); | 139 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size(); |
| 133 size_t total_internal_histograms = | 140 size_t total_internal_histograms = |
| 134 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); | 141 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size(); |
| 135 DCHECK_GE(total_pageload_histograms, total_internal_histograms); | 142 DCHECK_GE(total_pageload_histograms, total_internal_histograms); |
| 136 return total_pageload_histograms - total_internal_histograms == 0; | 143 return total_pageload_histograms - total_internal_histograms == 0; |
| 137 } | 144 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) { | 176 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NewPage) { |
| 170 ASSERT_TRUE(embedded_test_server()->Start()); | 177 ASSERT_TRUE(embedded_test_server()->Start()); |
| 171 | 178 |
| 172 ui_test_utils::NavigateToURL(browser(), | 179 ui_test_utils::NavigateToURL(browser(), |
| 173 embedded_test_server()->GetURL("/title1.html")); | 180 embedded_test_server()->GetURL("/title1.html")); |
| 174 NavigateToUntrackedUrl(); | 181 NavigateToUntrackedUrl(); |
| 175 | 182 |
| 176 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); | 183 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); |
| 177 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1); | 184 histogram_tester_.ExpectTotalCount(internal::kHistogramLoad, 1); |
| 178 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); | 185 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); |
| 186 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1); |
| 179 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1); | 187 histogram_tester_.ExpectTotalCount(internal::kHistogramParseDuration, 1); |
| 180 histogram_tester_.ExpectTotalCount( | 188 histogram_tester_.ExpectTotalCount( |
| 181 internal::kHistogramParseBlockedOnScriptLoad, 1); | 189 internal::kHistogramParseBlockedOnScriptLoad, 1); |
| 182 histogram_tester_.ExpectTotalCount( | 190 histogram_tester_.ExpectTotalCount( |
| 183 internal::kHistogramParseBlockedOnScriptExecution, 1); | 191 internal::kHistogramParseBlockedOnScriptExecution, 1); |
| 184 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); | 192 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); |
| 185 histogram_tester_.ExpectTotalCount( | 193 histogram_tester_.ExpectTotalCount( |
| 186 internal::kHistogramPageTimingForegroundDuration, 1); | 194 internal::kHistogramPageTimingForegroundDuration, 1); |
| 187 | 195 |
| 188 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics | 196 // Verify that NoPageLoadMetricsRecorded returns false when PageLoad metrics |
| 189 // have been recorded. | 197 // have been recorded. |
| 190 EXPECT_FALSE(NoPageLoadMetricsRecorded()); | 198 EXPECT_FALSE(NoPageLoadMetricsRecorded()); |
| 191 } | 199 } |
| 192 | 200 |
| 201 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, NoPaintForEmptyDocument) { |
| 202 ASSERT_TRUE(embedded_test_server()->Start()); |
| 203 |
| 204 ui_test_utils::NavigateToURL(browser(), |
| 205 embedded_test_server()->GetURL("/empty.html")); |
| 206 NavigateToUntrackedUrl(); |
| 207 |
| 208 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); |
| 209 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); |
| 210 } |
| 211 |
| 212 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, |
| 213 NoPaintForEmptyDocumentInFrame) { |
| 214 ASSERT_TRUE(embedded_test_server()->Start()); |
| 215 |
| 216 GURL a_url(embedded_test_server()->GetURL( |
| 217 "a.com", "/page_load_metrics/empty_iframe.html")); |
| 218 ui_test_utils::NavigateToURL(browser(), a_url); |
| 219 NavigateToUntrackedUrl(); |
| 220 |
| 221 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); |
| 222 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); |
| 223 } |
| 224 |
| 225 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, PaintInChildFrame) { |
| 226 ASSERT_TRUE(embedded_test_server()->Start()); |
| 227 |
| 228 GURL a_url(embedded_test_server()->GetURL("a.com", |
| 229 "/page_load_metrics/iframe.html")); |
| 230 ui_test_utils::NavigateToURL(browser(), a_url); |
| 231 NavigateToUntrackedUrl(); |
| 232 |
| 233 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 1); |
| 234 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 1); |
| 235 } |
| 236 |
| 193 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameDocumentNavigation) { | 237 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, SameDocumentNavigation) { |
| 194 ASSERT_TRUE(embedded_test_server()->Start()); | 238 ASSERT_TRUE(embedded_test_server()->Start()); |
| 195 | 239 |
| 196 ui_test_utils::NavigateToURL(browser(), | 240 ui_test_utils::NavigateToURL(browser(), |
| 197 embedded_test_server()->GetURL("/title1.html")); | 241 embedded_test_server()->GetURL("/title1.html")); |
| 198 ui_test_utils::NavigateToURL( | 242 ui_test_utils::NavigateToURL( |
| 199 browser(), embedded_test_server()->GetURL("/title1.html#hash")); | 243 browser(), embedded_test_server()->GetURL("/title1.html#hash")); |
| 200 NavigateToUntrackedUrl(); | 244 NavigateToUntrackedUrl(); |
| 201 | 245 |
| 202 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); | 246 histogram_tester_.ExpectTotalCount(internal::kHistogramDomContentLoaded, 1); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( | 776 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
| 733 "/page_load_metrics/large.html")); | 777 "/page_load_metrics/large.html")); |
| 734 NavigateToUntrackedUrl(); | 778 NavigateToUntrackedUrl(); |
| 735 | 779 |
| 736 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); | 780 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); |
| 737 | 781 |
| 738 // Verify that there is a single sample recorded in the 10kB bucket (the size | 782 // Verify that there is a single sample recorded in the 10kB bucket (the size |
| 739 // of the main HTML response). | 783 // of the main HTML response). |
| 740 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); | 784 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); |
| 741 } | 785 } |
| OLD | NEW |