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 | 18 |
18 namespace blink { | 19 namespace blink { |
19 | 20 |
20 TEST(MixedContentCheckerTest, IsMixedContent) | 21 TEST(MixedContentCheckerTest, IsMixedContent) |
21 { | 22 { |
22 struct TestCase { | 23 struct TestCase { |
23 const char* origin; | 24 const char* origin; |
24 const char* target; | 25 const char* target; |
25 bool expectation; | 26 bool expectation; |
26 } cases[] = { | 27 } cases[] = { |
(...skipping 14 matching lines...) Expand all Loading... |
41 | 42 |
42 KURL originUrl(KURL(), origin); | 43 KURL originUrl(KURL(), origin); |
43 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; | 44 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; |
44 KURL targetUrl(KURL(), target); | 45 KURL targetUrl(KURL(), target); |
45 EXPECT_EQ(expectation, MixedContentChecker::isMixedContent(securityOrigi
n.get(), targetUrl)) << "Origin: " << origin << ", Target: " << target << ", Exp
ectation: " << expectation; | 46 EXPECT_EQ(expectation, MixedContentChecker::isMixedContent(securityOrigi
n.get(), targetUrl)) << "Origin: " << origin << ", Target: " << target << ", Exp
ectation: " << expectation; |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 TEST(MixedContentCheckerTest, ContextTypeForInspector) | 50 TEST(MixedContentCheckerTest, ContextTypeForInspector) |
50 { | 51 { |
51 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1,
1)); | 52 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(1, 1)); |
52 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("http://example.test")); | 53 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("http://example.test")); |
53 | 54 |
54 ResourceRequest notMixedContent("https://example.test/foo.jpg"); | 55 ResourceRequest notMixedContent("https://example.test/foo.jpg"); |
55 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); | 56 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); |
56 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript); | 57 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript); |
57 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); | 58 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); |
58 | 59 |
59 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("https://example.test")); | 60 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("https://example.test")); |
60 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); | 61 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); |
61 | 62 |
(...skipping 18 matching lines...) Expand all Loading... |
80 } | 81 } |
81 MOCK_METHOD2(didDisplayContentWithCertificateErrors, void(const KURL&, c
onst CString&)); | 82 MOCK_METHOD2(didDisplayContentWithCertificateErrors, void(const KURL&, c
onst CString&)); |
82 MOCK_METHOD2(didRunContentWithCertificateErrors, void(const KURL&, const
CString&)); | 83 MOCK_METHOD2(didRunContentWithCertificateErrors, void(const KURL&, const
CString&)); |
83 }; | 84 }; |
84 | 85 |
85 } // namespace | 86 } // namespace |
86 | 87 |
87 TEST(MixedContentCheckerTest, HandleCertificateError) | 88 TEST(MixedContentCheckerTest, HandleCertificateError) |
88 { | 89 { |
89 MockFrameLoaderClient* client = new MockFrameLoaderClient; | 90 MockFrameLoaderClient* client = new MockFrameLoaderClient; |
90 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1,
1), nullptr, client); | 91 std::unique_ptr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(I
ntSize(1, 1), nullptr, client); |
91 | 92 |
92 KURL mainResourceUrl(KURL(), "https://example.test"); | 93 KURL mainResourceUrl(KURL(), "https://example.test"); |
93 KURL displayedUrl(KURL(), "https://example-displayed.test"); | 94 KURL displayedUrl(KURL(), "https://example-displayed.test"); |
94 KURL ranUrl(KURL(), "https://example-ran.test"); | 95 KURL ranUrl(KURL(), "https://example-ran.test"); |
95 | 96 |
96 dummyPageHolder->frame().document()->setURL(mainResourceUrl); | 97 dummyPageHolder->frame().document()->setURL(mainResourceUrl); |
97 ResourceResponse response1; | 98 ResourceResponse response1; |
98 response1.setURL(ranUrl); | 99 response1.setURL(ranUrl); |
99 response1.setSecurityInfo("security info1"); | 100 response1.setSecurityInfo("security info1"); |
100 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl, response1.ge
tSecurityInfo())); | 101 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl, response1.ge
tSecurityInfo())); |
101 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse1, WebURLRequest::FrameTypeNone, WebURLRequest::RequestContextScript); | 102 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse1, WebURLRequest::FrameTypeNone, WebURLRequest::RequestContextScript); |
102 | 103 |
103 ResourceResponse response2; | 104 ResourceResponse response2; |
104 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; | 105 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; |
105 ASSERT_EQ(WebMixedContent::ContextType::OptionallyBlockable, WebMixedContent
::contextTypeFromRequestContext(requestContext, dummyPageHolder->frame().setting
s()->strictMixedContentCheckingForPlugin())); | 106 ASSERT_EQ(WebMixedContent::ContextType::OptionallyBlockable, WebMixedContent
::contextTypeFromRequestContext(requestContext, dummyPageHolder->frame().setting
s()->strictMixedContentCheckingForPlugin())); |
106 response2.setURL(displayedUrl); | 107 response2.setURL(displayedUrl); |
107 response2.setSecurityInfo("security info2"); | 108 response2.setSecurityInfo("security info2"); |
108 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); | 109 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); |
109 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); | 110 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); |
110 } | 111 } |
111 | 112 |
112 } // namespace blink | 113 } // namespace blink |
OLD | NEW |