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

Side by Side 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: nasko comment 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 unified diff | Download patch
« no previous file with comments | « content/browser/ssl/ssl_manager.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/browser/ssl/ssl_manager.h"
6
7 #include "base/macros.h"
8 #include "content/browser/site_instance_impl.h"
9 #include "content/public/browser/ssl_status.h"
10 #include "content/public/browser/web_contents_delegate.h"
11 #include "content/public/test/mock_render_process_host.h"
12 #include "content/public/test/test_browser_context.h"
13 #include "content/public/test/test_renderer_host.h"
14 #include "content/test/test_web_contents.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace content {
18
19 namespace {
20
21 // A WebContentsDelegate that exposes the visible SSLStatus at the time
22 // of the last VisibleSSLStateChanged() call.
23 class TestWebContentsDelegate : public WebContentsDelegate {
24 public:
25 TestWebContentsDelegate() : WebContentsDelegate() {}
26 ~TestWebContentsDelegate() override {}
27
28 const SSLStatus& last_ssl_state() { return last_ssl_state_; }
29
30 // WebContentsDelegate:
31 void VisibleSSLStateChanged(const WebContents* source) override {
32 NavigationEntry* entry = source->GetController().GetVisibleEntry();
33 EXPECT_TRUE(entry);
34 last_ssl_state_ = entry->GetSSL();
35 }
36
37 private:
38 SSLStatus last_ssl_state_;
39 DISALLOW_COPY_AND_ASSIGN(TestWebContentsDelegate);
40 };
41
42 class SSLManagerTest : public RenderViewHostTestHarness {
43 public:
44 SSLManagerTest() : RenderViewHostTestHarness() {}
45 ~SSLManagerTest() override {}
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(SSLManagerTest);
49 };
50
51 // Tests that VisibleSSLStateChanged() is called when a password input
52 // is shown on an HTTP page.
53 TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnHttpPassword) {
54 TestWebContentsDelegate delegate;
55 web_contents()->SetDelegate(&delegate);
56 SSLManager manager(
57 static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
58
59 NavigateAndCommit(GURL("http://example.test"));
60 EXPECT_FALSE(delegate.last_ssl_state().content_status &
61 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
62 web_contents()->OnPasswordInputShownOnHttp();
63 EXPECT_TRUE(delegate.last_ssl_state().content_status &
64 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
65 }
66
67 // Tests that VisibleSSLStateChanged() is called when a credit card input
68 // is shown on an HTTP page.
69 TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnHttpCreditCard) {
70 TestWebContentsDelegate delegate;
71 web_contents()->SetDelegate(&delegate);
72 SSLManager manager(
73 static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
74
75 NavigateAndCommit(GURL("http://example.test"));
76 EXPECT_FALSE(delegate.last_ssl_state().content_status &
77 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
78 web_contents()->OnCreditCardInputShownOnHttp();
79 EXPECT_TRUE(delegate.last_ssl_state().content_status &
80 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
81 }
82
83 // Tests that VisibleSSLStateChanged() is called when password and
84 // credit card inputs are shown on an HTTP page.
85 TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnPasswordAndHttpCreditCard) {
86 TestWebContentsDelegate delegate;
87 web_contents()->SetDelegate(&delegate);
88 SSLManager manager(
89 static_cast<NavigationControllerImpl*>(&web_contents()->GetController()));
90
91 NavigateAndCommit(GURL("http://example.test"));
92 EXPECT_FALSE(delegate.last_ssl_state().content_status &
93 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
94 EXPECT_FALSE(delegate.last_ssl_state().content_status &
95 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
96 web_contents()->OnPasswordInputShownOnHttp();
97 web_contents()->OnCreditCardInputShownOnHttp();
98 EXPECT_TRUE(delegate.last_ssl_state().content_status &
99 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP);
100 EXPECT_TRUE(delegate.last_ssl_state().content_status &
101 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP);
102 }
103
104 } // namespace
105
106 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/ssl/ssl_manager.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698