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

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

Issue 2510803003: Pass RapporService to content/browser/ (Closed)
Patch Set: Fix more compile errors in JNI files Created 4 years 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 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"
11 #include "components/rappor/test_rappor_service.h" 11 #include "components/rappor/test_rappor_service.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
14 #include "content/public/test/test_navigation_observer.h" 14 #include "content/public/test/test_navigation_observer.h"
15 15
16 namespace { 16 namespace {
17 17
18 typedef InProcessBrowserTest NavigationMetricsRecorderBrowserTest; 18 typedef InProcessBrowserTest NavigationMetricsRecorderBrowserTest;
19 19
20 IN_PROC_BROWSER_TEST_F(NavigationMetricsRecorderBrowserTest, TestMetrics) { 20 IN_PROC_BROWSER_TEST_F(NavigationMetricsRecorderBrowserTest, TestMetrics) {
21 content::WebContents* web_contents = 21 content::WebContents* web_contents =
22 browser()->tab_strip_model()->GetActiveWebContents(); 22 browser()->tab_strip_model()->GetActiveWebContents();
23 23
24 NavigationMetricsRecorder* recorder = 24 NavigationMetricsRecorder* recorder =
25 content::WebContentsUserData<NavigationMetricsRecorder>::FromWebContents( 25 content::WebContentsUserData<NavigationMetricsRecorder>::FromWebContents(
26 web_contents); 26 web_contents);
27 ASSERT_TRUE(recorder); 27 ASSERT_TRUE(recorder);
28 rappor::TestRapporService rappor_service; 28 rappor::TestRapporServiceImpl rappor_service;
29 recorder->set_rappor_service_for_testing(&rappor_service); 29 recorder->set_rappor_service_for_testing(&rappor_service);
30 30
31 base::HistogramTester histograms; 31 base::HistogramTester histograms;
32 ui_test_utils::NavigateToURL(browser(), 32 ui_test_utils::NavigateToURL(browser(),
33 GURL("data:text/html, <html></html>")); 33 GURL("data:text/html, <html></html>"));
34 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1); 34 histograms.ExpectTotalCount("Navigation.MainFrameScheme", 1);
35 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1); 35 histograms.ExpectBucketCount("Navigation.MainFrameScheme", 5 /* data: */, 1);
36 // Since there was no previous URL, Rappor shouldn't record anything. 36 // Since there was no previous URL, Rappor shouldn't record anything.
37 EXPECT_EQ(0, rappor_service.GetReportsCount()); 37 EXPECT_EQ(0, rappor_service.GetReportsCount());
38 38
39 // Navigate to an empty page and redirect it to a data: URL. Rappor should 39 // Navigate to an empty page and redirect it to a data: URL. Rappor should
40 // record a report. 40 // record a report.
41 ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); 41 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
42 content::TestNavigationObserver observer(web_contents, 1); 42 content::TestNavigationObserver observer(web_contents, 1);
43 EXPECT_TRUE(content::ExecuteScript( 43 EXPECT_TRUE(content::ExecuteScript(
44 web_contents, "window.location.href='data:text/html, <html></html>'")); 44 web_contents, "window.location.href='data:text/html, <html></html>'"));
45 observer.Wait(); 45 observer.Wait();
46 46
47 EXPECT_EQ(1, rappor_service.GetReportsCount()); 47 EXPECT_EQ(1, rappor_service.GetReportsCount());
48 std::string sample; 48 std::string sample;
49 rappor::RapporType type; 49 rappor::RapporType type;
50 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( 50 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
51 "Navigation.Scheme.Data", &sample, &type)); 51 "Navigation.Scheme.Data", &sample, &type));
52 EXPECT_EQ("about://", sample); 52 EXPECT_EQ("about://", sample);
53 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); 53 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
54 } 54 }
55 55
56 } // namespace 56 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698