Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 content::WebContentsTester::For(web_contents()) | |
| 60 ->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!
| |
| 61 EXPECT_FALSE(delegate.last_ssl_state().content_status & | |
| 62 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | |
| 63 web_contents()->OnPasswordInputShownOnHttp(); | |
| 64 EXPECT_TRUE(delegate.last_ssl_state().content_status & | |
| 65 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | |
| 66 } | |
| 67 | |
| 68 // Tests that VisibleSSLStateChanged() is called when a credit card input | |
| 69 // is shown on an HTTP page. | |
| 70 TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnHttpCreditCard) { | |
| 71 TestWebContentsDelegate delegate; | |
| 72 web_contents()->SetDelegate(&delegate); | |
| 73 SSLManager manager( | |
| 74 static_cast<NavigationControllerImpl*>(&web_contents()->GetController())); | |
| 75 | |
| 76 content::WebContentsTester::For(web_contents()) | |
| 77 ->NavigateAndCommit(GURL("http://example.test")); | |
| 78 EXPECT_FALSE(delegate.last_ssl_state().content_status & | |
| 79 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | |
| 80 web_contents()->OnCreditCardInputShownOnHttp(); | |
| 81 EXPECT_TRUE(delegate.last_ssl_state().content_status & | |
| 82 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | |
| 83 } | |
| 84 | |
| 85 // Tests that VisibleSSLStateChanged() is called when password and | |
| 86 // credit card inputs are shown on an HTTP page. | |
| 87 TEST_F(SSLManagerTest, NotifyVisibleSSLStateChangeOnPasswordAndHttpCreditCard) { | |
| 88 TestWebContentsDelegate delegate; | |
| 89 web_contents()->SetDelegate(&delegate); | |
| 90 SSLManager manager( | |
| 91 static_cast<NavigationControllerImpl*>(&web_contents()->GetController())); | |
| 92 | |
| 93 content::WebContentsTester::For(web_contents()) | |
| 94 ->NavigateAndCommit(GURL("http://example.test")); | |
| 95 EXPECT_FALSE(delegate.last_ssl_state().content_status & | |
| 96 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | |
| 97 EXPECT_FALSE(delegate.last_ssl_state().content_status & | |
| 98 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | |
| 99 web_contents()->OnPasswordInputShownOnHttp(); | |
| 100 web_contents()->OnCreditCardInputShownOnHttp(); | |
| 101 EXPECT_TRUE(delegate.last_ssl_state().content_status & | |
| 102 SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP); | |
| 103 EXPECT_TRUE(delegate.last_ssl_state().content_status & | |
| 104 SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP); | |
| 105 } | |
| 106 | |
| 107 } // namespace | |
| 108 | |
| 109 } // namespace content | |
| OLD | NEW |