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/loader/EmptyClients.h" | 8 #include "core/loader/EmptyClients.h" |
8 #include "core/testing/DummyPageHolder.h" | 9 #include "core/testing/DummyPageHolder.h" |
9 #include "platform/network/ResourceResponse.h" | 10 #include "platform/network/ResourceResponse.h" |
10 #include "platform/weborigin/KURL.h" | 11 #include "platform/weborigin/KURL.h" |
11 #include "platform/weborigin/SecurityOrigin.h" | 12 #include "platform/weborigin/SecurityOrigin.h" |
12 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" | 13 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "wtf/RefPtr.h" | 15 #include "wtf/RefPtr.h" |
15 #include <base/macros.h> | 16 #include <base/macros.h> |
16 | 17 |
(...skipping 29 matching lines...) Expand all Loading... |
46 } | 47 } |
47 | 48 |
48 TEST(MixedContentCheckerTest, ContextTypeForInspector) | 49 TEST(MixedContentCheckerTest, ContextTypeForInspector) |
49 { | 50 { |
50 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1,
1)); | 51 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1,
1)); |
51 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("http://example.test")); | 52 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("http://example.test")); |
52 | 53 |
53 ResourceRequest notMixedContent("https://example.test/foo.jpg"); | 54 ResourceRequest notMixedContent("https://example.test/foo.jpg"); |
54 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); | 55 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); |
55 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript); | 56 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript); |
56 EXPECT_EQ(MixedContentChecker::ContextTypeNotMixedContent, MixedContentCheck
er::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); | 57 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); |
57 | 58 |
58 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("https://example.test")); | 59 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::creat
eFromString("https://example.test")); |
59 EXPECT_EQ(MixedContentChecker::ContextTypeNotMixedContent, MixedContentCheck
er::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); | 60 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, MixedContentChecker
::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent)); |
60 | 61 |
61 ResourceRequest blockableMixedContent("http://example.test/foo.jpg"); | 62 ResourceRequest blockableMixedContent("http://example.test/foo.jpg"); |
62 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); | 63 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); |
63 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript)
; | 64 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript)
; |
64 EXPECT_EQ(MixedContentChecker::ContextTypeBlockable, MixedContentChecker::co
ntextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent)); | 65 EXPECT_EQ(WebMixedContent::ContextType::Blockable, MixedContentChecker::cont
extTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent)); |
65 | 66 |
66 ResourceRequest optionallyBlockableMixedContent("http://example.test/foo.jpg
"); | 67 ResourceRequest optionallyBlockableMixedContent("http://example.test/foo.jpg
"); |
67 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); | 68 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); |
68 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage); | 69 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage); |
69 EXPECT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC
hecker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent
)); | 70 EXPECT_EQ(WebMixedContent::ContextType::OptionallyBlockable, MixedContentChe
cker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent))
; |
70 } | 71 } |
71 | 72 |
72 namespace { | 73 namespace { |
73 | 74 |
74 class MockFrameLoaderClient : public EmptyFrameLoaderClient { | 75 class MockFrameLoaderClient : public EmptyFrameLoaderClient { |
75 public: | 76 public: |
76 MockFrameLoaderClient() | 77 MockFrameLoaderClient() |
77 : EmptyFrameLoaderClient() | 78 : EmptyFrameLoaderClient() |
78 { | 79 { |
79 } | 80 } |
(...skipping 14 matching lines...) Expand all Loading... |
94 | 95 |
95 dummyPageHolder->frame().document()->setURL(mainResourceUrl); | 96 dummyPageHolder->frame().document()->setURL(mainResourceUrl); |
96 ResourceResponse response1; | 97 ResourceResponse response1; |
97 response1.setURL(ranUrl); | 98 response1.setURL(ranUrl); |
98 response1.setSecurityInfo("security info1"); | 99 response1.setSecurityInfo("security info1"); |
99 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl, response1.ge
tSecurityInfo())); | 100 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl, response1.ge
tSecurityInfo())); |
100 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse1, WebURLRequest::FrameTypeNone, WebURLRequest::RequestContextScript); | 101 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse1, WebURLRequest::FrameTypeNone, WebURLRequest::RequestContextScript); |
101 | 102 |
102 ResourceResponse response2; | 103 ResourceResponse response2; |
103 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; | 104 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; |
104 ASSERT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC
hecker::contextTypeFromContext(requestContext, &dummyPageHolder->frame())); | 105 ASSERT_EQ(WebMixedContent::ContextType::OptionallyBlockable, WebMixedContent
::contextTypeFromRequestContext(requestContext, dummyPageHolder->frame().setting
s()->strictMixedContentCheckingForPlugin())); |
105 response2.setURL(displayedUrl); | 106 response2.setURL(displayedUrl); |
106 response2.setSecurityInfo("security info2"); | 107 response2.setSecurityInfo("security info2"); |
107 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); | 108 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo())); |
108 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); | 109 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); |
109 } | 110 } |
110 | 111 |
111 } // namespace blink | 112 } // namespace blink |
OLD | NEW |