| 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 <base/macros.h> | 7 #include <base/macros.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
| 10 #include "core/loader/EmptyClients.h" | 10 #include "core/loader/EmptyClients.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 {"https://example.com/foo", "http://example.com/foo", true}, | 49 {"https://example.com/foo", "http://example.com/foo", true}, |
| 50 {"https://example.com/foo", "http://google.com/foo", true}, | 50 {"https://example.com/foo", "http://google.com/foo", true}, |
| 51 {"https://example.com/foo", "ws://example.com/foo", true}, | 51 {"https://example.com/foo", "ws://example.com/foo", true}, |
| 52 {"https://example.com/foo", "ws://google.com/foo", true}, | 52 {"https://example.com/foo", "ws://google.com/foo", true}, |
| 53 {"https://example.com/foo", "http://192.168.1.1/", true}, | 53 {"https://example.com/foo", "http://192.168.1.1/", true}, |
| 54 {"https://example.com/foo", "http://localhost/", true}, | 54 {"https://example.com/foo", "http://localhost/", true}, |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 for (const auto& test : cases) { | 57 for (const auto& test : cases) { |
| 58 SCOPED_TRACE(::testing::Message() << "Origin: " << test.origin | 58 SCOPED_TRACE(::testing::Message() |
| 59 << ", Target: " << test.target | 59 << "Origin: " << test.origin << ", Target: " << test.target |
| 60 << ", Expectation: " << test.expectation); | 60 << ", Expectation: " << test.expectation); |
| 61 KURL originUrl(KURL(), test.origin); | 61 KURL originUrl(KURL(), test.origin); |
| 62 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl)); | 62 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl)); |
| 63 KURL targetUrl(KURL(), test.target); | 63 KURL targetUrl(KURL(), test.target); |
| 64 EXPECT_EQ(test.expectation, MixedContentChecker::isMixedContent( | 64 EXPECT_EQ( |
| 65 securityOrigin.get(), targetUrl)); | 65 test.expectation, |
| 66 MixedContentChecker::isMixedContent(securityOrigin.get(), targetUrl)); |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 TEST(MixedContentCheckerTest, ContextTypeForInspector) { | 70 TEST(MixedContentCheckerTest, ContextTypeForInspector) { |
| 70 std::unique_ptr<DummyPageHolder> dummyPageHolder = | 71 std::unique_ptr<DummyPageHolder> dummyPageHolder = |
| 71 DummyPageHolder::create(IntSize(1, 1)); | 72 DummyPageHolder::create(IntSize(1, 1)); |
| 72 dummyPageHolder->frame().document()->setSecurityOrigin( | 73 dummyPageHolder->frame().document()->setSecurityOrigin( |
| 73 SecurityOrigin::createFromString("http://example.test")); | 74 SecurityOrigin::createFromString("http://example.test")); |
| 74 | 75 |
| 75 ResourceRequest notMixedContent("https://example.test/foo.jpg"); | 76 ResourceRequest notMixedContent("https://example.test/foo.jpg"); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 ResourceResponse response1; | 126 ResourceResponse response1; |
| 126 response1.setURL(ranUrl); | 127 response1.setURL(ranUrl); |
| 127 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl)); | 128 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl)); |
| 128 MixedContentChecker::handleCertificateError( | 129 MixedContentChecker::handleCertificateError( |
| 129 &dummyPageHolder->frame(), response1, WebURLRequest::FrameTypeNone, | 130 &dummyPageHolder->frame(), response1, WebURLRequest::FrameTypeNone, |
| 130 WebURLRequest::RequestContextScript); | 131 WebURLRequest::RequestContextScript); |
| 131 | 132 |
| 132 ResourceResponse response2; | 133 ResourceResponse response2; |
| 133 WebURLRequest::RequestContext requestContext = | 134 WebURLRequest::RequestContext requestContext = |
| 134 WebURLRequest::RequestContextImage; | 135 WebURLRequest::RequestContextImage; |
| 135 ASSERT_EQ( | 136 ASSERT_EQ(WebMixedContentContextType::OptionallyBlockable, |
| 136 WebMixedContentContextType::OptionallyBlockable, | 137 WebMixedContent::contextTypeFromRequestContext( |
| 137 WebMixedContent::contextTypeFromRequestContext( | 138 requestContext, |
| 138 requestContext, dummyPageHolder->frame() | 139 dummyPageHolder->frame() |
| 139 .settings() | 140 .settings() |
| 140 ->getStrictMixedContentCheckingForPlugin())); | 141 ->getStrictMixedContentCheckingForPlugin())); |
| 141 response2.setURL(displayedUrl); | 142 response2.setURL(displayedUrl); |
| 142 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl)); | 143 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl)); |
| 143 MixedContentChecker::handleCertificateError( | 144 MixedContentChecker::handleCertificateError( |
| 144 &dummyPageHolder->frame(), response2, WebURLRequest::FrameTypeNone, | 145 &dummyPageHolder->frame(), response2, WebURLRequest::FrameTypeNone, |
| 145 requestContext); | 146 requestContext); |
| 146 } | 147 } |
| 147 | 148 |
| 148 } // namespace blink | 149 } // namespace blink |
| OLD | NEW |