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

Side by Side Diff: chrome/browser/tab_contents/navigation_metrics_recorder_browsertest.cc

Issue 2713273002: Increase test coverage for Navigation.MainFrameSchemeDifferentPage (Closed)
Patch Set: Increase test coverage for Navigation.MainFrameSchemeDifferentPage Created 3 years, 9 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 | « no previous file | components/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/test/histogram_tester.h" 5 #include "base/test/histogram_tester.h"
6 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h" 6 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
(...skipping 23 matching lines...) Expand all
34 web_contents); 34 web_contents);
35 ASSERT_TRUE(recorder); 35 ASSERT_TRUE(recorder);
36 rappor::TestRapporServiceImpl rappor_service; 36 rappor::TestRapporServiceImpl rappor_service;
37 recorder->set_rappor_service_for_testing(&rappor_service); 37 recorder->set_rappor_service_for_testing(&rappor_service);
38 38
39 base::HistogramTester histograms; 39 base::HistogramTester histograms;
40 ui_test_utils::NavigateToURL(browser(), 40 ui_test_utils::NavigateToURL(browser(),
41 GURL("data:text/html, <html></html>")); 41 GURL("data:text/html, <html></html>"));
42 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1); 42 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1);
43 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1); 43 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1);
44 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 1);
45 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
46 5 /* data: */, 1);
44 // Since there was no previous URL, Rappor shouldn't record anything. 47 // Since there was no previous URL, Rappor shouldn't record anything.
45 EXPECT_EQ(0, rappor_service.GetReportsCount()); 48 EXPECT_EQ(0, rappor_service.GetReportsCount());
46 49
47 // Navigate to an empty page and redirect it to a data: URL. Rappor should 50 // Navigate to an empty page and redirect it to a data: URL. Rappor should
48 // record a report. 51 // record a report.
49 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 52 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
50 content::TestNavigationObserver observer(web_contents, 1); 53 content::TestNavigationObserver observer(web_contents, 1);
51 EXPECT_TRUE(content::ExecuteScript( 54 EXPECT_TRUE(content::ExecuteScript(
52 web_contents, "window.location.href='data:text/html, <html></html>'")); 55 web_contents, "window.location.href='data:text/html, <html></html>'"));
53 observer.Wait(); 56 observer.Wait();
54 57
55 EXPECT_EQ(1, rappor_service.GetReportsCount()); 58 EXPECT_EQ(1, rappor_service.GetReportsCount());
56 std::string sample; 59 std::string sample;
57 rappor::RapporType type; 60 rappor::RapporType type;
58 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( 61 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
59 "Navigation.Scheme.Data", &sample, &type)); 62 "Navigation.Scheme.Data", &sample, &type));
60 EXPECT_EQ("about://", sample); 63 EXPECT_EQ("about://", sample);
61 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 64 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
62 } 65 }
63 66
64 IN_PROC_BROWSER_TEST_F(NavigationMetricsRecorderBrowserTest, DataURLMimeTypes) { 67 IN_PROC_BROWSER_TEST_F(NavigationMetricsRecorderBrowserTest, DataURLMimeTypes) {
65 base::HistogramTester histograms; 68 base::HistogramTester histograms;
66 content::WebContents* web_contents = 69 content::WebContents* web_contents =
67 browser()->tab_strip_model()->GetActiveWebContents(); 70 browser()->tab_strip_model()->GetActiveWebContents();
68 71
69 // HTML: 72 // HTML:
70 RedirectToUrl(web_contents, GURL("data:text/html, <html></html>")); 73 RedirectToUrl(web_contents, GURL("data:text/html, <html></html>"));
71 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1); 74 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1);
72 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1); 75 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1);
76 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 1);
77 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
78 5 /* data: */, 1);
73 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 1); 79 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 1);
74 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType", 80 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType",
75 NavigationMetricsRecorder::MIME_TYPE_HTML, 1); 81 NavigationMetricsRecorder::MIME_TYPE_HTML, 1);
76 82
77 // SVG: 83 // SVG:
78 RedirectToUrl(web_contents, 84 RedirectToUrl(web_contents,
79 GURL("data:image/svg+xml,<!DOCTYPE svg><svg version=\"1.1\" " 85 GURL("data:image/svg+xml,<!DOCTYPE svg><svg version=\"1.1\" "
80 "xmlns=\"http://www.w3.org/2000/svg\"></svg>")); 86 "xmlns=\"http://www.w3.org/2000/svg\"></svg>"));
81 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 2); 87 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 2);
82 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 2); 88 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 2);
89 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 2);
90 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
91 5 /* data: */, 2);
83 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 2); 92 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 2);
84 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType", 93 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType",
85 NavigationMetricsRecorder::MIME_TYPE_SVG, 1); 94 NavigationMetricsRecorder::MIME_TYPE_SVG, 1);
86 95
87 // Base64 encoded HTML: 96 // Base64 encoded HTML:
88 RedirectToUrl(web_contents, 97 RedirectToUrl(web_contents,
89 GURL("data:text/html;base64, PGh0bWw+YmFzZTY0PC9odG1sPg==")); 98 GURL("data:text/html;base64, PGh0bWw+YmFzZTY0PC9odG1sPg=="));
90 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 3); 99 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 3);
91 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 3); 100 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 3);
101 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 3);
102 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
103 5 /* data: */, 3);
92 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 3); 104 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 3);
93 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType", 105 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType",
94 NavigationMetricsRecorder::MIME_TYPE_HTML, 2); 106 NavigationMetricsRecorder::MIME_TYPE_HTML, 2);
95 107
96 // Plain text: 108 // Plain text:
97 RedirectToUrl(web_contents, GURL("data:text/plain, test")); 109 RedirectToUrl(web_contents, GURL("data:text/plain, test"));
98 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 4); 110 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 4);
99 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 4); 111 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 4);
112 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 4);
113 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
114 5 /* data: */, 4);
100 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 4); 115 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 4);
101 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType", 116 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType",
102 NavigationMetricsRecorder::MIME_TYPE_OTHER, 1); 117 NavigationMetricsRecorder::MIME_TYPE_OTHER, 1);
103 118
104 // Base64 encoded PNG: 119 // Base64 encoded PNG:
105 RedirectToUrl( 120 RedirectToUrl(
106 web_contents, 121 web_contents,
107 GURL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA" 122 GURL("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
108 "AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO" 123 "AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO"
109 "9TXL0Y4OHwAAAABJRU5ErkJggg==")); 124 "9TXL0Y4OHwAAAABJRU5ErkJggg=="));
110 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 5); 125 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 5);
111 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 5); 126 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 5);
127 histograms.ExpectTotalCount("Navigation.MainFrameSchemeDifferentPage", 5);
128 histograms.ExpectBucketCount("Navigation.MainFrameSchemeDifferentPage",
129 5 /* data: */, 5);
112 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 5); 130 histograms.ExpectTotalCount("Navigation.MainFrameScheme.DataUrl.MimeType", 5);
113 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType", 131 histograms.ExpectBucketCount("Navigation.MainFrameScheme.DataUrl.MimeType",
114 NavigationMetricsRecorder::MIME_TYPE_OTHER, 2); 132 NavigationMetricsRecorder::MIME_TYPE_OTHER, 2);
115 } 133 }
116 134
117 } // namespace 135 } // namespace
OLDNEW
« no previous file with comments | « no previous file | components/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698