Index: components/security_state/content/content_utils_browsertest.cc |
diff --git a/components/security_state/content/content_utils_browsertest.cc b/components/security_state/content/content_utils_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c6b45b08f143adde757436201f3152cfe12480fa |
--- /dev/null |
+++ b/components/security_state/content/content_utils_browsertest.cc |
@@ -0,0 +1,88 @@ |
+// 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 "components/security_state/content/content_utils.h" |
+ |
+#include <memory> |
+ |
+#include "base/files/file_path.h" |
+#include "base/macros.h" |
+#include "content/public/browser/navigation_controller.h" |
+#include "content/public/browser/navigation_entry.h" |
+#include "content/public/browser/ssl_status.h" |
+#include "content/public/browser/web_contents.h" |
+#include "content/public/test/browser_test.h" |
+#include "content/public/test/content_browser_test.h" |
+#include "content/public/test/content_browser_test_utils.h" |
+#include "content/shell/browser/shell.h" |
+#include "net/test/embedded_test_server/embedded_test_server.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "url/gurl.h" |
+ |
+namespace { |
+ |
+using content::NavigateToURL; |
+using security_state::SecurityStateModel; |
+using security_state_content_utils::GetVisibleSecurityState; |
+ |
+const base::FilePath::CharType kDocRoot[] = |
+ FILE_PATH_LITERAL("components/security_state/content/testdata"); |
+ |
+class SecurityStateContentUtilsBrowserTest |
+ : public content::ContentBrowserTest { |
+ public: |
+ SecurityStateContentUtilsBrowserTest() |
+ : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { |
+ https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot)); |
+ } |
+ |
+ protected: |
+ net::EmbeddedTestServer https_server_; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(SecurityStateContentUtilsBrowserTest); |
+}; |
+ |
+// Tests that the NavigationEntry's flags for nonsecure password/credit |
+// card inputs are reflected in the VisibleSecurityState. |
+IN_PROC_BROWSER_TEST_F(SecurityStateContentUtilsBrowserTest, |
+ VisibleSecurityStateNonsecureFormInputs) { |
+ ASSERT_TRUE(https_server_.Start()); |
+ EXPECT_TRUE(NavigateToURL(shell(), https_server_.GetURL("/hello.html"))); |
+ |
+ content::WebContents* contents = shell()->web_contents(); |
+ ASSERT_TRUE(contents); |
+ |
+ // First, test that if the flags aren't set on the NavigationEntry, |
+ // then they also aren't set on the VisibleSecurityState. |
+ content::SSLStatus& ssl_status = |
+ contents->GetController().GetVisibleEntry()->GetSSL(); |
+ ASSERT_FALSE(ssl_status.content_status & |
+ content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); |
+ ASSERT_FALSE(ssl_status.content_status & |
+ content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); |
+ std::unique_ptr<SecurityStateModel::VisibleSecurityState> |
+ visible_security_state_no_sensitive_inputs = |
+ GetVisibleSecurityState(contents); |
+ EXPECT_FALSE(visible_security_state_no_sensitive_inputs |
+ ->displayed_password_field_on_http); |
+ EXPECT_FALSE(visible_security_state_no_sensitive_inputs |
+ ->displayed_credit_card_field_on_http); |
+ |
+ // Now, set the flags on the NavigationEntry and test that they are |
+ // reflected in the VisibleSecurityState. |
+ ssl_status.content_status |= |
+ content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP; |
+ ssl_status.content_status |= |
+ content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP; |
+ std::unique_ptr<SecurityStateModel::VisibleSecurityState> |
+ visible_security_state_sensitive_inputs = |
+ GetVisibleSecurityState(contents); |
+ EXPECT_TRUE(visible_security_state_sensitive_inputs |
+ ->displayed_password_field_on_http); |
+ EXPECT_TRUE(visible_security_state_sensitive_inputs |
+ ->displayed_credit_card_field_on_http); |
+} |
+ |
+} // namespace |