Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(922)

Side by Side Diff: third_party/WebKit/Source/core/loader/MixedContentCheckerTest.cpp

Issue 2625633002: Supporting changes in preparation of browser side mixed content checking. (Closed)
Patch Set: Address code review comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "public/platform/WebMixedContent.h"
14 #include "public/platform/WebMixedContentContextType.h"
13 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" 15 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 #include "wtf/RefPtr.h" 17 #include "wtf/RefPtr.h"
16 #include <base/macros.h> 18 #include <base/macros.h>
17 #include <memory> 19 #include <memory>
18 20
19 namespace blink { 21 namespace blink {
20 22
21 TEST(MixedContentCheckerTest, IsMixedContent) { 23 TEST(MixedContentCheckerTest, IsMixedContent) {
22 struct TestCase { 24 struct TestCase {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 63
62 TEST(MixedContentCheckerTest, ContextTypeForInspector) { 64 TEST(MixedContentCheckerTest, ContextTypeForInspector) {
63 std::unique_ptr<DummyPageHolder> dummyPageHolder = 65 std::unique_ptr<DummyPageHolder> dummyPageHolder =
64 DummyPageHolder::create(IntSize(1, 1)); 66 DummyPageHolder::create(IntSize(1, 1));
65 dummyPageHolder->frame().document()->setSecurityOrigin( 67 dummyPageHolder->frame().document()->setSecurityOrigin(
66 SecurityOrigin::createFromString("http://example.test")); 68 SecurityOrigin::createFromString("http://example.test"));
67 69
68 ResourceRequest notMixedContent("https://example.test/foo.jpg"); 70 ResourceRequest notMixedContent("https://example.test/foo.jpg");
69 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); 71 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
70 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript); 72 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript);
71 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, 73 EXPECT_EQ(WebMixedContentContextType::NotMixedContent,
72 MixedContentChecker::contextTypeForInspector( 74 MixedContentChecker::contextTypeForInspector(
73 &dummyPageHolder->frame(), notMixedContent)); 75 &dummyPageHolder->frame(), notMixedContent));
74 76
75 dummyPageHolder->frame().document()->setSecurityOrigin( 77 dummyPageHolder->frame().document()->setSecurityOrigin(
76 SecurityOrigin::createFromString("https://example.test")); 78 SecurityOrigin::createFromString("https://example.test"));
77 EXPECT_EQ(WebMixedContent::ContextType::NotMixedContent, 79 EXPECT_EQ(WebMixedContentContextType::NotMixedContent,
78 MixedContentChecker::contextTypeForInspector( 80 MixedContentChecker::contextTypeForInspector(
79 &dummyPageHolder->frame(), notMixedContent)); 81 &dummyPageHolder->frame(), notMixedContent));
80 82
81 ResourceRequest blockableMixedContent("http://example.test/foo.jpg"); 83 ResourceRequest blockableMixedContent("http://example.test/foo.jpg");
82 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); 84 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
83 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript); 85 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript);
84 EXPECT_EQ(WebMixedContent::ContextType::Blockable, 86 EXPECT_EQ(WebMixedContentContextType::Blockable,
85 MixedContentChecker::contextTypeForInspector( 87 MixedContentChecker::contextTypeForInspector(
86 &dummyPageHolder->frame(), blockableMixedContent)); 88 &dummyPageHolder->frame(), blockableMixedContent));
87 89
88 ResourceRequest optionallyBlockableMixedContent( 90 ResourceRequest optionallyBlockableMixedContent(
89 "http://example.test/foo.jpg"); 91 "http://example.test/foo.jpg");
90 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary); 92 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
91 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage); 93 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage);
92 EXPECT_EQ(WebMixedContent::ContextType::OptionallyBlockable, 94 EXPECT_EQ(WebMixedContentContextType::OptionallyBlockable,
93 MixedContentChecker::contextTypeForInspector( 95 MixedContentChecker::contextTypeForInspector(
94 &dummyPageHolder->frame(), blockableMixedContent)); 96 &dummyPageHolder->frame(), blockableMixedContent));
95 } 97 }
96 98
97 namespace { 99 namespace {
98 100
99 class MockFrameLoaderClient : public EmptyFrameLoaderClient { 101 class MockFrameLoaderClient : public EmptyFrameLoaderClient {
100 public: 102 public:
101 MockFrameLoaderClient() : EmptyFrameLoaderClient() {} 103 MockFrameLoaderClient() : EmptyFrameLoaderClient() {}
102 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&)); 104 MOCK_METHOD1(didDisplayContentWithCertificateErrors, void(const KURL&));
(...skipping 16 matching lines...) Expand all
119 response1.setURL(ranUrl); 121 response1.setURL(ranUrl);
120 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl)); 122 EXPECT_CALL(*client, didRunContentWithCertificateErrors(ranUrl));
121 MixedContentChecker::handleCertificateError( 123 MixedContentChecker::handleCertificateError(
122 &dummyPageHolder->frame(), response1, WebURLRequest::FrameTypeNone, 124 &dummyPageHolder->frame(), response1, WebURLRequest::FrameTypeNone,
123 WebURLRequest::RequestContextScript); 125 WebURLRequest::RequestContextScript);
124 126
125 ResourceResponse response2; 127 ResourceResponse response2;
126 WebURLRequest::RequestContext requestContext = 128 WebURLRequest::RequestContext requestContext =
127 WebURLRequest::RequestContextImage; 129 WebURLRequest::RequestContextImage;
128 ASSERT_EQ( 130 ASSERT_EQ(
129 WebMixedContent::ContextType::OptionallyBlockable, 131 WebMixedContentContextType::OptionallyBlockable,
130 WebMixedContent::contextTypeFromRequestContext( 132 WebMixedContent::contextTypeFromRequestContext(
131 requestContext, dummyPageHolder->frame() 133 requestContext, dummyPageHolder->frame()
132 .settings() 134 .settings()
133 ->getStrictMixedContentCheckingForPlugin())); 135 ->getStrictMixedContentCheckingForPlugin()));
134 response2.setURL(displayedUrl); 136 response2.setURL(displayedUrl);
135 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl)); 137 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl));
136 MixedContentChecker::handleCertificateError( 138 MixedContentChecker::handleCertificateError(
137 &dummyPageHolder->frame(), response2, WebURLRequest::FrameTypeNone, 139 &dummyPageHolder->frame(), response2, WebURLRequest::FrameTypeNone,
138 requestContext); 140 requestContext);
139 } 141 }
140 142
141 } // namespace blink 143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698