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

Unified Diff: content/browser/ssl/ssl_manager_unittest.cc

Issue 2410023003: Add unit test for notifying WebContents when SSLStatus changes due to HTTP-bad (Closed)
Patch Set: rebase 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: content/browser/ssl/ssl_manager_unittest.cc
diff --git a/content/browser/ssl/ssl_manager_unittest.cc b/content/browser/ssl/ssl_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b8f36631fd6f4980de4e8ef2e814acf5ec607b91
--- /dev/null
+++ b/content/browser/ssl/ssl_manager_unittest.cc
@@ -0,0 +1,109 @@
+// 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 "content/browser/ssl/ssl_manager.h"
+
+#include "base/macros.h"
+#include "content/browser/site_instance_impl.h"
+#include "content/public/browser/ssl_status.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/test/mock_render_process_host.h"
+#include "content/public/test/test_browser_context.h"
+#include "content/public/test/test_renderer_host.h"
+#include "content/test/test_web_contents.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+namespace {
+
+// A WebContentsDelegate that exposes the visible SSLStatus at the time
+// of the last VisibleSSLStateChanged() call.
+class TestWebContentsDelegate : public WebContentsDelegate {
+ public:
+ TestWebContentsDelegate() : WebContentsDelegate() {}
+ ~TestWebContentsDelegate() override {}
+
+ const SSLStatus& last_ssl_state() { return last_ssl_state_; }
+
+ // WebContentsDelegate:
+ void VisibleSSLStateChanged(const WebContents* source) override {
+ NavigationEntry* entry = source->GetController().GetVisibleEntry();
+ EXPECT_TRUE(entry);
+ last_ssl_state_ = entry->GetSSL();
+ }
+
+ private:
+ SSLStatus last_ssl_state_;
+ DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate);
+};
+
+class SSLManagerTest : public RenderViewHostTestHarness {
+ public:
+ SSLManagerTest() : RenderViewHostTestHarness() {}
+ ~SSLManagerTest() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SSLManagerTest);
+};
+
+// Tests that VisibleSSLStateChanged() is called when a password input
+// is shown on an HTTP page.
+TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnHttpPassword) {
+ TestWebContentsDelegate delegate;
+ web_contents()->SetDelegate(&delegate);
+ SSLManager manager(
+ static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
+
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL("http://example.test"));
nasko 2016/10/12 23:45:53 nit: You could just call NavigateAndCommit, right?
estark 2016/10/13 00:49:25 Done, thanks!
+ EXPECT_FALSE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
+ web_contents()->OnPasswordInputShownOnHttp();
+ EXPECT_TRUE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
+}
+
+// Tests that VisibleSSLStateChanged() is called when a credit card input
+// is shown on an HTTP page.
+TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnHttpCreditCard) {
+ TestWebContentsDelegate delegate;
+ web_contents()->SetDelegate(&delegate);
+ SSLManager manager(
+ static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
+
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL("http://example.test"));
+ EXPECT_FALSE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
+ web_contents()->OnCreditCardInputShownOnHttp();
+ EXPECT_TRUE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
+}
+
+// Tests that VisibleSSLStateChanged() is called when password and
+// credit card inputs are shown on an HTTP page.
+TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnPasswordAndHttpCreditCard) {
+ TestWebContentsDelegate delegate;
+ web_contents()->SetDelegate(&delegate);
+ SSLManager manager(
+ static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
+
+ content::WebContentsTester::For(web_contents())
+ ->NavigateAndCommit(GURL("http://example.test"));
+ EXPECT_FALSE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
+ EXPECT_FALSE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
+ web_contents()->OnPasswordInputShownOnHttp();
+ web_contents()->OnCreditCardInputShownOnHttp();
+ EXPECT_TRUE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
+ EXPECT_TRUE(delegate.last_ssl_state().content_status &
+ SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
+}
+
+} // namespace
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698