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

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

Issue 2804093002: Various page_load_metrics cleanups and improvements (Closed)
Patch Set: fix 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/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"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 public: 160 public:
161 PageLoadMetricsBrowserTest() {} 161 PageLoadMetricsBrowserTest() {}
162 ~PageLoadMetricsBrowserTest() override {} 162 ~PageLoadMetricsBrowserTest() override {}
163 163
164 protected: 164 protected:
165 void NavigateToUntrackedUrl() { 165 void NavigateToUntrackedUrl() {
166 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL)); 166 ui_test_utils::NavigateToURL(browser(), GURL(url::kAboutBlankURL));
167 } 167 }
168 168
169 bool NoPageLoadMetricsRecorded() { 169 bool NoPageLoadMetricsRecorded() {
170 return histogram_tester_.GetTotalCountsForPrefix("PageLoad.").empty(); 170 // Determine whether any 'public' page load metrics are recorded. We exclude
171 // 'internal' metrics as these may be recorded for debugging purposes.
172 size_t total_pageload_histograms =
173 histogram_tester_.GetTotalCountsForPrefix("PageLoad.").size();
174 size_t total_internal_histograms =
175 histogram_tester_.GetTotalCountsForPrefix("PageLoad.Internal.").size();
176 DCHECK_GE(total_pageload_histograms, total_internal_histograms);
177 return total_pageload_histograms - total_internal_histograms == 0;
171 } 178 }
172 179
173 scoped_refptr<TimingUpdatedObserver> CreateTimingUpdatedObserver() { 180 scoped_refptr<TimingUpdatedObserver> CreateTimingUpdatedObserver() {
174 content::WebContents* web_contents = 181 content::WebContents* web_contents =
175 browser()->tab_strip_model()->GetActiveWebContents(); 182 browser()->tab_strip_model()->GetActiveWebContents();
176 scoped_refptr<TimingUpdatedObserver> observer(new TimingUpdatedObserver( 183 scoped_refptr<TimingUpdatedObserver> observer(new TimingUpdatedObserver(
177 web_contents->GetRenderViewHost()->GetWidget())); 184 web_contents->GetRenderViewHost()->GetWidget()));
178 return observer; 185 return observer;
179 } 186 }
180 187
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // documents with non-well-formed XML on the blink side. See crbug.com/627607 491 // documents with non-well-formed XML on the blink side. See crbug.com/627607
485 // for more. 492 // for more.
486 ui_test_utils::NavigateToURL( 493 ui_test_utils::NavigateToURL(
487 browser(), 494 browser(),
488 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml")); 495 embedded_test_server()->GetURL("/page_load_metrics/badxml.xhtml"));
489 496
490 timing_observer->WaitForMatchingIPC(); 497 timing_observer->WaitForMatchingIPC();
491 498
492 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0); 499 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstLayout, 0);
493 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0); 500 histogram_tester_.ExpectTotalCount(internal::kHistogramFirstPaint, 0);
494 histogram_tester_.ExpectBucketCount(page_load_metrics::internal::kErrorEvents, 501 histogram_tester_.ExpectBucketCount(
495 page_load_metrics::ERR_BAD_TIMING_IPC, 1); 502 page_load_metrics::internal::kErrorEvents,
503 page_load_metrics::ERR_BAD_TIMING_IPC_INVALID_TIMING, 1);
496 } 504 }
497 505
498 // Test code that aborts provisional navigations. 506 // Test code that aborts provisional navigations.
499 // TODO(csharrison): Move these to unit tests once the navigation API in content 507 // TODO(csharrison): Move these to unit tests once the navigation API in content
500 // properly calls NavigationHandle/NavigationThrottle methods. 508 // properly calls NavigationHandle/NavigationThrottle methods.
501 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, AbortNewNavigation) { 509 IN_PROC_BROWSER_TEST_F(PageLoadMetricsBrowserTest, AbortNewNavigation) {
502 ASSERT_TRUE(embedded_test_server()->Start()); 510 ASSERT_TRUE(embedded_test_server()->Start());
503 511
504 GURL url(embedded_test_server()->GetURL("/title1.html")); 512 GURL url(embedded_test_server()->GetURL("/title1.html"));
505 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK); 513 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_LINK);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( 761 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(
754 "/page_load_metrics/large.html")); 762 "/page_load_metrics/large.html"));
755 NavigateToUntrackedUrl(); 763 NavigateToUntrackedUrl();
756 764
757 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1); 765 histogram_tester_.ExpectTotalCount(internal::kHistogramTotalBytes, 1);
758 766
759 // Verify that there is a single sample recorded in the 10kB bucket (the size 767 // Verify that there is a single sample recorded in the 10kB bucket (the size
760 // of the main HTML response). 768 // of the main HTML response).
761 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1); 769 histogram_tester_.ExpectBucketCount(internal::kHistogramTotalBytes, 10, 1);
762 } 770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698