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

Side by Side Diff: chrome/browser/ssl/security_state_tab_helper_unittest.cc

Issue 2499243002: Record time to navigation/tab-closed after HTTP-bad warning (Closed)
Patch Set: fix up 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
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 "chrome/browser/ssl/security_state_tab_helper.h" 5 #include "chrome/browser/ssl/security_state_tab_helper.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
10 #include "components/security_state/core/switches.h" 10 #include "components/security_state/core/switches.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 14
15 const char kHTTPBadNavigationHistogram[] =
16 "Security.HTTPBad.NavigationStartedAfterUserWarnedAboutSensitiveInput";
17 const char kHTTPBadWebContentsDestroyedHistogram[] =
18 "Security.HTTPBad.WebContentsDestroyedAfterUserWarnedAboutSensitiveInput";
19
15 class SecurityStateTabHelperHistogramTest 20 class SecurityStateTabHelperHistogramTest
16 : public ChromeRenderViewHostTestHarness, 21 : public ChromeRenderViewHostTestHarness,
17 public testing::WithParamInterface<bool> { 22 public testing::WithParamInterface<bool> {
18 public: 23 public:
19 SecurityStateTabHelperHistogramTest() : helper_(nullptr) {} 24 SecurityStateTabHelperHistogramTest() : helper_(nullptr) {}
20 ~SecurityStateTabHelperHistogramTest() override {} 25 ~SecurityStateTabHelperHistogramTest() override {}
21 26
22 void SetUp() override { 27 void SetUp() override {
23 ChromeRenderViewHostTestHarness::SetUp(); 28 ChromeRenderViewHostTestHarness::SetUp();
24 29
25 SecurityStateTabHelper::CreateForWebContents(web_contents()); 30 SecurityStateTabHelper::CreateForWebContents(web_contents());
26 helper_ = SecurityStateTabHelper::FromWebContents(web_contents()); 31 helper_ = SecurityStateTabHelper::FromWebContents(web_contents());
27 navigate_to_http(); 32 NavigateToHTTP();
28 } 33 }
29 34
30 protected: 35 protected:
31 void signal_sensitive_input() { 36 void SignalSensitiveInput() {
32 if (GetParam()) 37 if (GetParam())
33 web_contents()->OnPasswordInputShownOnHttp(); 38 web_contents()->OnPasswordInputShownOnHttp();
34 else 39 else
35 web_contents()->OnCreditCardInputShownOnHttp(); 40 web_contents()->OnCreditCardInputShownOnHttp();
36 helper_->VisibleSecurityStateChanged(); 41 helper_->VisibleSecurityStateChanged();
37 } 42 }
38 43
39 const std::string histogram_name() { 44 const std::string histogram_name() {
40 if (GetParam()) 45 if (GetParam())
41 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password"; 46 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.Password";
42 else 47 else
43 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard"; 48 return "Security.HTTPBad.UserWarnedAboutSensitiveInput.CreditCard";
44 } 49 }
45 50
46 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); } 51 void NavigateToHTTP() { NavigateAndCommit(GURL("http://example.test")); }
47 52
48 void navigate_to_different_http_page() { 53 void NavigateToDifferentHTTPPage() {
49 NavigateAndCommit(GURL("http://example2.test")); 54 NavigateAndCommit(GURL("http://example2.test"));
50 } 55 }
51 56
52 private: 57 private:
53 SecurityStateTabHelper* helper_; 58 SecurityStateTabHelper* helper_;
54 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperHistogramTest); 59 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperHistogramTest);
55 }; 60 };
56 61
62 // Tests that an UMA histogram is recorded after setting the security
63 // level to HTTP_SHOW_WARNING and navigating away.
64 TEST_P(SecurityStateTabHelperHistogramTest,
65 HTTPOmniboxWarningNavigationHistogram) {
66 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
67 security_state::switches::kMarkHttpAs,
68 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
69
70 base::HistogramTester histograms;
71 SignalSensitiveInput();
72 // Make sure that if the omnibox warning gets dynamically hidden, the
73 // histogram still gets recorded.
74 NavigateToDifferentHTTPPage();
75 if (GetParam())
76 web_contents()->OnAllPasswordInputsHiddenOnHttp();
77 // Destroy the WebContents to simulate the tab being closed after a
78 // navigation.
79 SetContents(nullptr);
80 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 1);
81 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 0);
82 }
83
84 // Tests that an UMA histogram is recorded after showing a console
85 // warning for a sensitive input on HTTP and navigating away.
86 TEST_P(SecurityStateTabHelperHistogramTest,
87 HTTPConsoleWarningNavigationHistogram) {
88 // Same as HTTPOmniboxWarningNavigationHistogram, but ensuring that
89 // the histogram gets recorded even if the command-line switch to show
90 // the omnibox warning is not set.
91 base::HistogramTester histograms;
92 SignalSensitiveInput();
93 NavigateToDifferentHTTPPage();
94 // Destroy the WebContents to simulate the tab being closed after a
95 // navigation.
96 SetContents(nullptr);
97 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 1);
98 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 0);
99 }
100
101 // Tests that an UMA histogram is recorded after setting the security
102 // level to HTTP_SHOW_WARNING and closing the tab.
103 TEST_P(SecurityStateTabHelperHistogramTest,
104 HTTPOmniboxWarningTabClosedHistogram) {
105 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
106 security_state::switches::kMarkHttpAs,
107 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
108
109 base::HistogramTester histograms;
110 SignalSensitiveInput();
111 // Destroy the WebContents to simulate the tab being closed.
112 SetContents(nullptr);
113 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 0);
114 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 1);
115 }
116
117 // Tests that an UMA histogram is recorded after showing a console
118 // warning for a sensitive input on HTTP and closing the tab.
119 TEST_P(SecurityStateTabHelperHistogramTest,
120 HTTPConsoleWarningTabClosedHistogram) {
121 // Same as HTTPOmniboxWarningTabClosedHistogram, but ensuring that the
122 // histogram gets recorded even if the command-line switch to show the
123 // omnibox warning is not set.
elawrence 2016/11/18 17:43:30 Do we need to explicitly write out the flag state
estark 2016/11/18 23:59:35 Oops, sorry, lost that in the rebase too. :( Done.
124 base::HistogramTester histograms;
125 SignalSensitiveInput();
126 // Destroy the WebContents to simulate the tab being closed.
127 SetContents(nullptr);
128 histograms.ExpectTotalCount(kHTTPBadNavigationHistogram, 0);
129 histograms.ExpectTotalCount(kHTTPBadWebContentsDestroyedHistogram, 1);
130 }
131
57 // Tests that UMA logs the omnibox warning when security level is 132 // Tests that UMA logs the omnibox warning when security level is
58 // HTTP_SHOW_WARNING. 133 // HTTP_SHOW_WARNING.
59 TEST_P(SecurityStateTabHelperHistogramTest, HTTPOmniboxWarningHistogram) { 134 TEST_P(SecurityStateTabHelperHistogramTest, HTTPOmniboxWarningHistogram) {
60 // Show Warning Chip. 135 // Show Warning Chip.
61 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 136 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
62 security_state::switches::kMarkHttpAs, 137 security_state::switches::kMarkHttpAs,
63 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip); 138 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
64 139
65 base::HistogramTester histograms; 140 base::HistogramTester histograms;
66 signal_sensitive_input(); 141 SignalSensitiveInput();
67 histograms.ExpectUniqueSample(histogram_name(), true, 1); 142 histograms.ExpectUniqueSample(histogram_name(), true, 1);
68 143
69 // Fire again and ensure no sample is recorded. 144 // Fire again and ensure no sample is recorded.
70 signal_sensitive_input(); 145 SignalSensitiveInput();
71 histograms.ExpectUniqueSample(histogram_name(), true, 1); 146 histograms.ExpectUniqueSample(histogram_name(), true, 1);
72 147
73 // Navigate to a new page and ensure a sample is recorded. 148 // Navigate to a new page and ensure a sample is recorded.
74 navigate_to_different_http_page(); 149 NavigateToDifferentHTTPPage();
75 histograms.ExpectUniqueSample(histogram_name(), true, 1); 150 histograms.ExpectUniqueSample(histogram_name(), true, 1);
76 signal_sensitive_input(); 151 SignalSensitiveInput();
77 histograms.ExpectUniqueSample(histogram_name(), true, 2); 152 histograms.ExpectUniqueSample(histogram_name(), true, 2);
78 } 153 }
79 154
80 // Tests that UMA logs the console warning when security level is NONE. 155 // Tests that UMA logs the console warning when security level is NONE.
81 TEST_P(SecurityStateTabHelperHistogramTest, HTTPConsoleWarningHistogram) { 156 TEST_P(SecurityStateTabHelperHistogramTest, HTTPConsoleWarningHistogram) {
82 // Show Neutral for HTTP 157 // Show Neutral for HTTP
83 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 158 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
84 security_state::switches::kMarkHttpAs, 159 security_state::switches::kMarkHttpAs,
85 security_state::switches::kMarkHttpAsNeutral); 160 security_state::switches::kMarkHttpAsNeutral);
86 161
87 base::HistogramTester histograms; 162 base::HistogramTester histograms;
88 signal_sensitive_input(); 163 SignalSensitiveInput();
89 histograms.ExpectUniqueSample(histogram_name(), false, 1); 164 histograms.ExpectUniqueSample(histogram_name(), false, 1);
90 165
91 // Fire again and ensure no sample is recorded. 166 // Fire again and ensure no sample is recorded.
92 signal_sensitive_input(); 167 SignalSensitiveInput();
93 histograms.ExpectUniqueSample(histogram_name(), false, 1); 168 histograms.ExpectUniqueSample(histogram_name(), false, 1);
94 169
95 // Navigate to a new page and ensure a sample is recorded. 170 // Navigate to a new page and ensure a sample is recorded.
96 navigate_to_different_http_page(); 171 NavigateToDifferentHTTPPage();
97 histograms.ExpectUniqueSample(histogram_name(), false, 1); 172 histograms.ExpectUniqueSample(histogram_name(), false, 1);
98 signal_sensitive_input(); 173 SignalSensitiveInput();
99 histograms.ExpectUniqueSample(histogram_name(), false, 2); 174 histograms.ExpectUniqueSample(histogram_name(), false, 2);
100 } 175 }
101 176
102 INSTANTIATE_TEST_CASE_P(SecurityStateTabHelperHistogramTest, 177 INSTANTIATE_TEST_CASE_P(SecurityStateTabHelperHistogramTest,
103 SecurityStateTabHelperHistogramTest, 178 SecurityStateTabHelperHistogramTest,
104 // Here 'true' to test password field triggered 179 // Here 'true' to test password field triggered
105 // histogram and 'false' to test credit card field. 180 // histogram and 'false' to test credit card field.
106 testing::Bool()); 181 testing::Bool());
107 182
108 } // namespace 183 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698