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

Side by Side Diff: components/security_state/content/content_utils_browsertest.cc

Issue 2448943002: Refactor SecurityStateModel/Clients for simplicity and reusability. (Closed)
Patch Set: sync. 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 "components/security_state/content/content_utils.h"
6
7 #include <memory>
8
9 #include "base/files/file_path.h"
10 #include "base/macros.h"
11 #include "components/security_state/core/security_state.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/ssl_status.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test.h"
17 #include "content/public/test/content_browser_test.h"
18 #include "content/public/test/content_browser_test_utils.h"
19 #include "content/shell/browser/shell.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "url/gurl.h"
23
24 namespace {
25
26 using content::NavigateToURL;
27 using security_state::GetVisibleSecurityState;
28
29 const base::FilePath::CharType kDocRoot[] =
30 FILE_PATH_LITERAL("components/security_state/content/testdata");
31
32 class SecurityStateContentUtilsBrowserTest
33 : public content::ContentBrowserTest {
34 public:
35 SecurityStateContentUtilsBrowserTest()
36 : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {
37 https_server_.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
38 }
39
40 protected:
41 net::EmbeddedTestServer https_server_;
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(SecurityStateContentUtilsBrowserTest);
45 };
46
47 // Tests that the NavigationEntry's flags for nonsecure password/credit
48 // card inputs are reflected in the VisibleSecurityState.
49 IN_PROC_BROWSER_TEST_F(SecurityStateContentUtilsBrowserTest,
50 VisibleSecurityStateNonsecureFormInputs) {
51 ASSERT_TRUE(https_server_.Start());
52 EXPECT_TRUE(NavigateToURL(shell(), https_server_.GetURL("/hello.html")));
53
54 content::WebContents* contents = shell()->web_contents();
55 ASSERT_TRUE(contents);
56
57 // First, test that if the flags aren't set on the NavigationEntry,
58 // then they also aren't set on the VisibleSecurityState.
59 content::SSLStatus& ssl_status =
60 contents->GetController().GetVisibleEntry()->GetSSL();
61 ASSERT_FALSE(ssl_status.content_status &
62 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
63 ASSERT_FALSE(ssl_status.content_status &
64 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
65 std::unique_ptr<security_state::VisibleSecurityState>
66 visible_security_state_no_sensitive_inputs =
67 GetVisibleSecurityState(contents);
68 EXPECT_FALSE(visible_security_state_no_sensitive_inputs
69 ->displayed_password_field_on_http);
70 EXPECT_FALSE(visible_security_state_no_sensitive_inputs
71 ->displayed_credit_card_field_on_http);
72
73 // Now, set the flags on the NavigationEntry and test that they are
74 // reflected in the VisibleSecurityState.
75 ssl_status.content_status |=
76 content::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP;
77 ssl_status.content_status |=
78 content::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP;
79 std::unique_ptr<security_state::VisibleSecurityState>
80 visible_security_state_sensitive_inputs =
81 GetVisibleSecurityState(contents);
82 EXPECT_TRUE(visible_security_state_sensitive_inputs
83 ->displayed_password_field_on_http);
84 EXPECT_TRUE(visible_security_state_sensitive_inputs
85 ->displayed_credit_card_field_on_http);
86 }
87
88 } // namespace
OLDNEW
« no previous file with comments | « components/security_state/content/content_utils.cc ('k') | components/security_state/content/content_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698