| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/loader/MixedContentChecker.h" | 5 #include "core/loader/MixedContentChecker.h" |
| 6 | 6 |
| 7 #include "core/frame/Settings.h" | 7 #include "core/frame/Settings.h" |
| 8 #include "core/loader/EmptyClients.h" | 8 #include "core/loader/EmptyClients.h" |
| 9 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "platform/network/ResourceResponse.h" | 10 #include "platform/network/ResourceResponse.h" |
| 11 #include "platform/weborigin/KURL.h" | 11 #include "platform/weborigin/KURL.h" |
| 12 #include "platform/weborigin/SecurityOrigin.h" | 12 #include "platform/weborigin/SecurityOrigin.h" |
| 13 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" | 13 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
| 16 #include <base/macros.h> | 16 #include <base/macros.h> |
| 17 #include <memory> | 17 #include <memory> |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 TEST(MixedContentCheckerTest, IsMixedContent) | 21 TEST(MixedContentCheckerTest, IsMixedContent) |
| 22 { | 22 { |
| 23 struct TestCase { | 23 struct TestCase { |
| 24 const char* origin; | 24 const char* origin; |
| 25 const char* target; | 25 const char* target; |
| 26 bool expectation; | 26 bool expectation; |
| 27 } cases[] = { | 27 } cases[] = { |
| 28 {"http://example.com/foo", "http://example.com/foo", false}, | 28 {"http://example.com/foo", "http://example.com/foo", false}, |
| 29 {"http://example.com/foo", "https://example.com/foo", false}, | 29 {"http://example.com/foo", "https://example.com/foo", false}, |
| 30 {"http://example.com/foo", "data:text/html,<p>Hi!</p>", false}, |
| 30 {"https://example.com/foo", "https://example.com/foo", false}, | 31 {"https://example.com/foo", "https://example.com/foo", false}, |
| 31 {"https://example.com/foo", "wss://example.com/foo", false}, | 32 {"https://example.com/foo", "wss://example.com/foo", false}, |
| 33 {"https://example.com/foo", "data:text/html,<p>Hi!</p>", false}, |
| 34 {"https://example.com/foo", "http://127.0.0.1/", false}, |
| 35 {"https://example.com/foo", "http://[::1]/", false}, |
| 36 |
| 32 {"https://example.com/foo", "http://example.com/foo", true}, | 37 {"https://example.com/foo", "http://example.com/foo", true}, |
| 33 {"https://example.com/foo", "http://google.com/foo", true}, | 38 {"https://example.com/foo", "http://google.com/foo", true}, |
| 34 {"https://example.com/foo", "ws://example.com/foo", true}, | 39 {"https://example.com/foo", "ws://example.com/foo", true}, |
| 35 {"https://example.com/foo", "ws://google.com/foo", true}, | 40 {"https://example.com/foo", "ws://google.com/foo", true}, |
| 41 {"https://example.com/foo", "http://192.168.1.1/", true}, |
| 42 {"https://example.com/foo", "http://localhost/", true}, |
| 36 }; | 43 }; |
| 37 | 44 |
| 38 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) { | 45 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) { |
| 39 const char* origin = cases[i].origin; | 46 const char* origin = cases[i].origin; |
| 40 const char* target = cases[i].target; | 47 const char* target = cases[i].target; |
| 41 bool expectation = cases[i].expectation; | 48 bool expectation = cases[i].expectation; |
| 42 | 49 |
| 43 KURL originUrl(KURL(), origin); | 50 KURL originUrl(KURL(), origin); |
| 44 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; | 51 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; |
| 45 KURL targetUrl(KURL(), target); | 52 KURL targetUrl(KURL(), target); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 ResourceResponse response2; | 111 ResourceResponse response2; |
| 105 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; | 112 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; |
| 106 ASSERT_EQ(WebMixedContent::ContextType::OptionallyBlockable, WebMixedContent
::contextTypeFromRequestContext(requestContext, dummyPageHolder->frame().setting
s()->strictMixedContentCheckingForPlugin())); | 113 ASSERT_EQ(WebMixedContent::ContextType::OptionallyBlockable, WebMixedContent
::contextTypeFromRequestContext(requestContext, dummyPageHolder->frame().setting
s()->strictMixedContentCheckingForPlugin())); |
| 107 response2.setURL(displayedUrl); | 114 response2.setURL(displayedUrl); |
| 108 response2.setSecurityInfo("security info2"); | 115 response2.setSecurityInfo("security info2"); |
| 109 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); | 116 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); |
| 110 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); | 117 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); |
| 111 } | 118 } |
| 112 | 119 |
| 113 } // namespace blink | 120 } // namespace blink |
| OLD | NEW |