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/loader/EmptyClients.h" | 7 #include "core/loader/EmptyClients.h" |
8 #include "core/testing/DummyPageHolder.h" | 8 #include "core/testing/DummyPageHolder.h" |
9 #include "platform/network/ResourceResponse.h" | 9 #include "platform/network/ResourceResponse.h" |
10 #include "platform/weborigin/KURL.h" | 10 #include "platform/weborigin/KURL.h" |
11 #include "platform/weborigin/SecurityOrigin.h" | 11 #include "platform/weborigin/SecurityOrigin.h" |
12 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" | 12 #include "testing/gmock/include/gmock/gmock-generated-function-mockers.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "wtf/RefPtr.h" | 14 #include "wtf/RefPtr.h" |
15 #include <base/macros.h> | 15 #include <base/macros.h> |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 TEST(MixedContentCheckerTest, IsMixedContent) | 19 TEST(MixedContentCheckerTest, IsMixedContent) |
20 { | 20 { |
21 struct TestCase { | 21 struct TestCase { |
22 const char* origin; | 22 const char* origin; |
23 const char* target; | 23 const char* target; |
24 bool expectation; | 24 bool expectation; |
25 } cases[] = { | 25 } cases[] = { |
26 {"http://example.com/foo", "http://example.com/foo", false}, | 26 {"http://example.com/foo", "http://example.com/foo", false}, |
27 {"http://example.com/foo", "https://example.com/foo", false}, | 27 {"http://example.com/foo", "https://example.com/foo", false}, |
| 28 {"http://example.com/foo", "data:text/html,<p>Hi!</p>", false}, |
28 {"https://example.com/foo", "https://example.com/foo", false}, | 29 {"https://example.com/foo", "https://example.com/foo", false}, |
29 {"https://example.com/foo", "wss://example.com/foo", false}, | 30 {"https://example.com/foo", "wss://example.com/foo", false}, |
| 31 {"https://example.com/foo", "data:text/html,<p>Hi!</p>", false}, |
| 32 {"https://example.com/foo", "http://127.0.0.1/", false}, |
| 33 {"https://example.com/foo", "http://localhost/", false}, |
| 34 |
30 {"https://example.com/foo", "http://example.com/foo", true}, | 35 {"https://example.com/foo", "http://example.com/foo", true}, |
31 {"https://example.com/foo", "http://google.com/foo", true}, | 36 {"https://example.com/foo", "http://google.com/foo", true}, |
32 {"https://example.com/foo", "ws://example.com/foo", true}, | 37 {"https://example.com/foo", "ws://example.com/foo", true}, |
33 {"https://example.com/foo", "ws://google.com/foo", true}, | 38 {"https://example.com/foo", "ws://google.com/foo", true}, |
| 39 {"https://example.com/foo", "http://192.168.1.1/", true}, |
34 }; | 40 }; |
35 | 41 |
36 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) { | 42 for (size_t i = 0; i < WTF_ARRAY_LENGTH(cases); ++i) { |
37 const char* origin = cases[i].origin; | 43 const char* origin = cases[i].origin; |
38 const char* target = cases[i].target; | 44 const char* target = cases[i].target; |
39 bool expectation = cases[i].expectation; | 45 bool expectation = cases[i].expectation; |
40 | 46 |
41 KURL originUrl(KURL(), origin); | 47 KURL originUrl(KURL(), origin); |
42 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; | 48 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl))
; |
43 KURL targetUrl(KURL(), target); | 49 KURL targetUrl(KURL(), target); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 ResourceResponse response2; | 108 ResourceResponse response2; |
103 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; | 109 WebURLRequest::RequestContext requestContext = WebURLRequest::RequestContext
Image; |
104 ASSERT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC
hecker::contextTypeFromContext(requestContext, &dummyPageHolder->frame())); | 110 ASSERT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentC
hecker::contextTypeFromContext(requestContext, &dummyPageHolder->frame())); |
105 response2.setURL(displayedUrl); | 111 response2.setURL(displayedUrl); |
106 response2.setSecurityInfo("security info2"); | 112 response2.setSecurityInfo("security info2"); |
107 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo(), WebURL(mainResourceUrl), CString())); | 113 EXPECT_CALL(*client, didDisplayContentWithCertificateErrors(displayedUrl, re
sponse2.getSecurityInfo(), WebURL(mainResourceUrl), CString())); |
108 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); | 114 MixedContentChecker::handleCertificateError(&dummyPageHolder->frame(), respo
nse2, WebURLRequest::FrameTypeNone, requestContext); |
109 } | 115 } |
110 | 116 |
111 } // namespace blink | 117 } // namespace blink |
OLD | NEW |