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

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

Issue 2400953003: Add browser test for NavigationMetricsRecorder (Closed)
Patch Set: Rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/tab_contents/navigation_metrics_recorder.cc ('k') | chrome/test/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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/test/histogram_tester.h"
6 #include "chrome/browser/tab_contents/navigation_metrics_recorder.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h"
11 #include "components/rappor/test_rappor_service.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/test_navigation_observer.h"
15
16 namespace {
17
18 typedef InProcessBrowserTest NavigationMetricsRecorderBrowserTest;
19
20 IN_PROC_BROWSER_TEST_F(NavigationMetricsRecorderBrowserTest, TestMetrics) {
21 content::WebContents* web_contents =
22 browser()->tab_strip_model()->GetActiveWebContents();
23
24 NavigationMetricsRecorder* recorder =
25 content::WebContentsUserData<NavigationMetricsRecorder>::FromWebContents(
26 web_contents);
27 ASSERT_TRUE(recorder);
28 rappor::TestRapporService rappor_service;
29 recorder->set_rappor_service_for_testing(&rappor_service);
30
31 base::HistogramTester histograms;
32 ui_test_utils::NavigateToURL(browser(),
33 GURL("data:text/html, <html></html>"));
34 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1);
35 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1);
36 // Since there was no previous URL, Rappor shouldn't record anything.
37 EXPECT_EQ(0, rappor_service.GetReportsCount());
38
39 // Navigate to an empty page and redirect it to a data: URL. Rappor should
40 // record a report.
41 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
42 content::TestNavigationObserver observer(web_contents, 1);
43 EXPECT_TRUE(content::ExecuteScript(
44 web_contents, "window.location.href='data:text/html, <html></html>'"));
45 observer.Wait();
46
47 EXPECT_EQ(1, rappor_service.GetReportsCount());
48 std::string sample;
49 rappor::RapporType type;
50 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
51 "Navigation.Scheme.Data", &sample, &type));
52 EXPECT_EQ("about://", sample);
53 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
54 }
55
56 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/navigation_metrics_recorder.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698