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

Unified 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, 2 months 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/chrome_security_state_model_client_unittest.cc
diff --git a/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc b/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc
index 9a50d7bc05b7e937f30a2843530afc2399932d46..29e1f61a98dd551ab9e984b6697f68a722c14304 100644
--- a/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc
+++ b/chrome/browser/ssl/chrome_security_state_model_client_unittest.cc
@@ -4,9 +4,15 @@
#include "chrome/browser/ssl/chrome_security_state_model_client.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/security_state_model.h"
+#include "components/security_state/switches.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/security_style_explanation.h"
#include "content/public/browser/security_style_explanations.h"
+#include "content/public/browser/ssl_status.h"
#include "net/cert/cert_status_flags.h"
#include "net/ssl/ssl_cipher_suite_names.h"
#include "net/ssl/ssl_connection_status_flags.h"
@@ -242,4 +248,78 @@ TEST(ChromeSecurityStateModelClientTest, HTTPWarningInFuture) {
EXPECT_EQ(1u, explanations.info_explanations.size());
}
+class ChromeSecurityStateModelClientHistogramTest
+ : public ChromeRenderViewHostTestHarness {
+ public:
+ ChromeSecurityStateModelClientHistogramTest() {}
+ ~ChromeSecurityStateModelClientHistogramTest() override {}
+
+ void SetUp() override {
+ ChromeRenderViewHostTestHarness::SetUp();
+
+ ChromeSecurityStateModelClient::CreateForWebContents(web_contents());
+ client = ChromeSecurityStateModelClient::FromWebContents(web_contents());
+ navigateToHTTP();
+ }
+
+ protected:
+ void signalPassword() {
estark 2016/10/26 20:30:56 style: should be signal_password
elawrence 2016/10/26 21:02:39 Done.
+ web_contents()->OnPasswordInputShownOnHttp();
+ client->VisibleSSLStateChanged();
+ }
+
+ 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.
+
+ 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.
+ 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.
+ "Security.HTTPBad.UserWarnedAboutSensitiveInput";
+};
+
+// Tests that UMA logs the omnibox warning when security level is
+// HTTP_SHOW_WARNING.
+TEST_F(ChromeSecurityStateModelClientHistogramTest,
+ HTTPOmniboxWarningHistogram) {
+ // 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.
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ security_state::switches::kMarkHttpAs,
+ security_state::switches::kMarkHttpWithPasswordsOrCcWithChip);
+
+ base::HistogramTester histograms;
+ signalPassword();
+ 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.
+
+ // Fire again and ensure no sample is recorded
+ signalPassword();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 1);
+
+ // Navigate to a new page and ensure a sample is recorded
+ navigateToHTTP();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 1);
+ signalPassword();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 1, 2);
+}
+
+// Tests that UMA logs the console warning when security level is NONE.
+TEST_F(ChromeSecurityStateModelClientHistogramTest,
+ HTTPConsoleWarningHistogram) {
+ // Show Neutral for HTTP
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ security_state::switches::kMarkHttpAs,
+ security_state::switches::kMarkHttpAsNeutral);
+
+ base::HistogramTester histograms;
+ signalPassword();
+ 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.
+
+ // Fire again and ensure no sample is recorded
+ signalPassword();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 1);
+
+ // Navigate to a new page and ensure a sample is recorded
+ navigateToHTTP();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 1);
+ signalPassword();
+ histograms.ExpectUniqueSample(kHTTPBadHistogram, 0, 2);
+}
+
} // namespace

Powered by Google App Engine
This is Rietveld 408576698