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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ssl/security_state_tab_helper_unittest.cc
diff --git a/chrome/browser/ssl/security_state_tab_helper_unittest.cc b/chrome/browser/ssl/security_state_tab_helper_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a337b800680c6ac1c6dd8dc90aa0c5cd2e7f52dd
--- /dev/null
+++ b/chrome/browser/ssl/security_state_tab_helper_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ssl/security_state_tab_helper.h"
+
+#include "base/command_line.h"
+#include "base/test/histogram_tester.h"
+#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "components/security_state/core/switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kHTTPBadHistogram[] =
+ "Security.HTTPBad.UserWarnedAboutSensitiveInput";
+
+class SecurityStateTabHelperHistogramTest
+ : public ChromeRenderViewHostTestHarness {
+ public:
+ SecurityStateTabHelperHistogramTest() : helper_(nullptr) {}
+ ~SecurityStateTabHelperHistogramTest() override {}
+
+ void SetUp() override {
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ SecurityStateTabHelper::CreateForWebContents(web_contents());
+ helper_ = SecurityStateTabHelper::FromWebContents(web_contents());
+ navigate_to_http();
+ }
+
+ protected:
+ void signal_password() {
+ web_contents()->OnPasswordInputShownOnHttp();
+ helper_->VisibleSecurityStateChanged();
+ }
+
+ void navigate_to_http() { NavigateAndCommit(GURL("http://example.test")); }
+
+ private:
+ SecurityStateTabHelper* helper_;
+ DISALLOW_COPY_AND_ASSIGN(SecurityStateTabHelperHistogramTest);
+};
+
+// Tests that UMA logs the omnibox warning when security level is
+// HTTP_SHOW_WARNING.
+TEST_F(SecurityStateTabHelperHistogramTest, HTTPOmniboxWarningHistogram) {
+ // Show Warning Chip.
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ security_state::switches::kMarkHttpAs,
+ security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
+
+ base::HistogramTester histograms;
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
+
+ // Fire again and ensure no sample is recorded.
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
+
+ // Navigate to a new page and ensure a sample is recorded.
+ navigate_to_http();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 1);
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, true, 2);
+}
+
+// Tests that UMA logs the console warning when security level is NONE.
+TEST_F(SecurityStateTabHelperHistogramTest, HTTPConsoleWarningHistogram) {
+ // Show Neutral for HTTP
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ security_state::switches::kMarkHttpAs,
+ security_state::switches::kMarkHttpAsNeutral);
+
+ base::HistogramTester histograms;
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
+
+ // Fire again and ensure no sample is recorded.
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
+
+ // Navigate to a new page and ensure a sample is recorded.
+ navigate_to_http();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 1);
+ signal_password();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, false, 2);
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698