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

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

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: update comments. 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
(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 "chrome/browser/ssl/security_state_tab_helper.h"
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"
10 #include "components/security_state/core/switches.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 const char kHTTPBadHistogram[] =
16 "Security.HTTPBad.UserWarnedAboutSensitiveInput";
17
18 class SecurityStateTabHelperHistogramTest
19 : public ChromeRenderViewHostTestHarness {
20 public:
21 SecurityStateTabHelperHistogramTest() : helper_(nullptr) {}
22 ~SecurityStateTabHelperHistogramTest() override {}
23
24 void SetUp() override {
25 ChromeRenderViewHostTestHarness::SetUp();
26
27 SecurityStateTabHelper::CreateForWebContents(web_contents());
28 helper_ = SecurityStateTabHelper::FromWebContents(web_contents());
29 navigate_to_http();
30 }
31
32 protected:
33 void signal_password() {
34 web_contents()->OnPasswordInputShownOnHttp();
35 helper_->VisibleSecurityStateChanged();
36 }
37
38 void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); }
39
40 private:
41 SecurityStateTabHelper* helper_;
42 DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperHistogramTest);
43 };
44
45 // Tests that UMA logs the omnibox warning when security level is
46 // HTTP_SHOW_WARNING.
47 TEST_F(SecurityStateTabHelperHistogramTest, HTTPOmniboxWarningHistogram) {
48 // Show Warning Chip.
49 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
50 security_state::switches::kMarkHttpAs,
51 security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
52
53 base::HistogramTester histograms;
54 signal_password();
55 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
56
57 // Fire again and ensure no sample is recorded.
58 signal_password();
59 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
60
61 // Navigate to a new page and ensure a sample is recorded.
62 navigate_to_http();
63 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
64 signal_password();
65 histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 2);
66 }
67
68 // Tests that UMA logs the console warning when security level is NONE.
69 TEST_F(SecurityStateTabHelperHistogramTest, HTTPConsoleWarningHistogram) {
70 // Show Neutral for HTTP
71 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
72 security_state::switches::kMarkHttpAs,
73 security_state::switches::kMarkHttpAsNeutral);
74
75 base::HistogramTester histograms;
76 signal_password();
77 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
78
79 // Fire again and ensure no sample is recorded.
80 signal_password();
81 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
82
83 // Navigate to a new page and ensure a sample is recorded.
84 navigate_to_http();
85 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
86 signal_password();
87 histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 2);
88 }
89
90 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698