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

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

Issue 2451293002: Add a histogram for each time the HTTP Bad UI is shown (Closed)
Patch Set: 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/chrome_security_state_model_client.h" 5 #include "chrome/browser/ssl/chrome_security_state_model_client.h"
6 6
7 #include "base/command_line.h"
8 #include "base/test/histogram_tester.h"
9 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
7 #include "components/security_state/security_state_model.h" 10 #include "components/security_state/security_state_model.h"
11 #include "components/security_state/switches.h"
12 #include "content/public/browser/navigation_entry.h"
8 #include "content/public/browser/security_style_explanation.h" 13 #include "content/public/browser/security_style_explanation.h"
9 #include "content/public/browser/security_style_explanations.h" 14 #include "content/public/browser/security_style_explanations.h"
15 #include "content/public/browser/ssl_status.h"
10 #include "net/cert/cert_status_flags.h" 16 #include "net/cert/cert_status_flags.h"
11 #include "net/ssl/ssl_cipher_suite_names.h" 17 #include "net/ssl/ssl_cipher_suite_names.h"
12 #include "net/ssl/ssl_connection_status_flags.h" 18 #include "net/ssl/ssl_connection_status_flags.h"
13 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
14 20
15 namespace { 21 namespace {
16 22
17 // Tests that SecurityInfo flags for subresources with certificate 23 // Tests that SecurityInfo flags for subresources with certificate
18 // errors are reflected in the SecurityStyleExplanations produced by 24 // errors are reflected in the SecurityStyleExplanations produced by
19 // ChromeSecurityStateModelClient. 25 // ChromeSecurityStateModelClient.
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 content::SecurityStyleExplanations explanations; 241 content::SecurityStyleExplanations explanations;
236 security_info.security_level = security_state::SecurityStateModel::NONE; 242 security_info.security_level = security_state::SecurityStateModel::NONE;
237 security_info.displayed_private_user_data_input_on_http = true; 243 security_info.displayed_private_user_data_input_on_http = true;
238 blink::WebSecurityStyle security_style = 244 blink::WebSecurityStyle security_style =
239 ChromeSecurityStateModelClient::GetSecurityStyle(security_info, 245 ChromeSecurityStateModelClient::GetSecurityStyle(security_info,
240 &explanations); 246 &explanations);
241 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style); 247 EXPECT_EQ(blink::WebSecurityStyleUnauthenticated, security_style);
242 EXPECT_EQ(1u, explanations.info_explanations.size()); 248 EXPECT_EQ(1u, explanations.info_explanations.size());
243 } 249 }
244 250
251 class ChromeSecurityStateModelClientHistogramTest
252 : public ChromeRenderViewHostTestHarness {
253 public:
254 ChromeSecurityStateModelClientHistogramTest() {}
255 ~ChromeSecurityStateModelClientHistogramTest() override {}
256
257 void SetUp() override {
258 ChromeRenderViewHostTestHarness::SetUp();
259
260 ChromeSecurityStateModelClient::CreateForWebContents(web_contents());
261 client = ChromeSecurityStateModelClient::FromWebContents(web_contents());
262 navigateToHTTP();
263 }
264
265 protected:
266 void signalPassword() {
estark 2016/10/26 20:30:56 style: should be signal_password
elawrence 2016/10/26 21:02:39 Done.
267 web_contents()->OnPasswordInputShownOnHttp();
268 client->VisibleSSLStateChanged();
269 }
270
271 void navigateToHTTP() { NavigateAndCommit(GURL("http://example.test")); }
estark 2016/10/26 20:30:56 style: should be navigate_to_http
elawrence 2016/10/26 21:02:39 Done.
272
273 ChromeSecurityStateModelClient* client;
estark 2016/10/26 20:30:56 style: should be client_ Also non-private data me
elawrence 2016/10/26 21:02:39 Done.
274 const char* kHTTPBadHistogram =
estark 2016/10/26 20:30:56 No need for this to be a class member, I'd just pu
elawrence 2016/10/26 21:02:39 Done.
275 "Security.HTTPBad.UserWarnedAboutSensitiveInput";
276 };
277
278 // Tests that UMA logs the omnibox warning when security level is
279 // HTTP_SHOW_WARNING.
280 TEST_F(ChromeSecurityStateModelClientHistogramTest,
281 HTTPOmniboxWarningHistogram) {
282 // Show Warning Chip
estark 2016/10/26 20:30:56 nit: end comments with periods, here and below. It
elawrence 2016/10/26 21:02:39 Done.
283 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
284 security_state::switches::kMarkHttpAs,
285 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
286
287 base::HistogramTester histograms;
288 signalPassword();
289 histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 1);
estark 2016/10/26 20:30:56 I think `true` instead of `1` for the second arg w
elawrence 2016/10/26 21:02:39 Done.
290
291 // Fire again and ensure no sample is recorded
292 signalPassword();
293 histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 1);
294
295 // Navigate to a new page and ensure a sample is recorded
296 navigateToHTTP();
297 histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 1);
298 signalPassword();
299 histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 2);
300 }
301
302 // Tests that UMA logs the console warning when security level is NONE.
303 TEST_F(ChromeSecurityStateModelClientHistogramTest,
304 HTTPConsoleWarningHistogram) {
305 // Show Neutral for HTTP
306 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
307 security_state::switches::kMarkHttpAs,
308 security_state::switches::kMarkHttpAsNeutral);
309
310 base::HistogramTester histograms;
311 signalPassword();
312 histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 1);
estark 2016/10/26 20:30:56 same comment about false instead of 0
elawrence 2016/10/26 21:02:39 Done.
313
314 // Fire again and ensure no sample is recorded
315 signalPassword();
316 histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 1);
317
318 // Navigate to a new page and ensure a sample is recorded
319 navigateToHTTP();
320 histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 1);
321 signalPassword();
322 histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 2);
323 }
324
245 } // namespace 325 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698