Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / loader / MixedContentCheckerTest.cpp
blobfb371f2d4e5c1b2476d544b8a965a6855e000a4f
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
3 // found in the LICENSE file.
5 #include "config.h"
6 #include "core/loader/MixedContentChecker.h"
8 #include "core/testing/DummyPageHolder.h"
9 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/SecurityOrigin.h"
11 #include "wtf/RefPtr.h"
13 #include <base/macros.h>
14 #include <gtest/gtest.h>
16 namespace blink {
18 TEST(MixedContentCheckerTest, IsMixedContent)
20 struct TestCase {
21 const char* origin;
22 const char* target;
23 bool expectation;
24 } cases[] = {
25 {"http://example.com/foo", "http://example.com/foo", false},
26 {"http://example.com/foo", "https://example.com/foo", false},
27 {"https://example.com/foo", "https://example.com/foo", false},
28 {"https://example.com/foo", "wss://example.com/foo", false},
29 {"https://example.com/foo", "http://example.com/foo", true},
30 {"https://example.com/foo", "http://google.com/foo", true},
31 {"https://example.com/foo", "ws://example.com/foo", true},
32 {"https://example.com/foo", "ws://google.com/foo", true},
35 for (size_t i = 0; i < arraysize(cases); ++i) {
36 const char* origin = cases[i].origin;
37 const char* target = cases[i].target;
38 bool expectation = cases[i].expectation;
40 KURL originUrl(KURL(), origin);
41 RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl));
42 KURL targetUrl(KURL(), target);
43 EXPECT_EQ(expectation, MixedContentChecker::isMixedContent(securityOrigin.get(), targetUrl)) << "Origin: " << origin << ", Target: " << target << ", Expectation: " << expectation;
47 TEST(MixedContentCheckerTest, ContextTypeForInspector)
49 OwnPtr<DummyPageHolder> dummyPageHolder = DummyPageHolder::create(IntSize(1, 1));
50 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::createFromString("http://example.test"));
52 ResourceRequest notMixedContent("https://example.test/foo.jpg");
53 notMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
54 notMixedContent.setRequestContext(WebURLRequest::RequestContextScript);
55 EXPECT_EQ(MixedContentChecker::ContextTypeNotMixedContent, MixedContentChecker::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent));
57 dummyPageHolder->frame().document()->setSecurityOrigin(SecurityOrigin::createFromString("https://example.test"));
58 EXPECT_EQ(MixedContentChecker::ContextTypeNotMixedContent, MixedContentChecker::contextTypeForInspector(&dummyPageHolder->frame(), notMixedContent));
60 ResourceRequest blockableMixedContent("http://example.test/foo.jpg");
61 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
62 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextScript);
63 EXPECT_EQ(MixedContentChecker::ContextTypeBlockable, MixedContentChecker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent));
65 ResourceRequest optionallyBlockableMixedContent("http://example.test/foo.jpg");
66 blockableMixedContent.setFrameType(WebURLRequest::FrameTypeAuxiliary);
67 blockableMixedContent.setRequestContext(WebURLRequest::RequestContextImage);
68 EXPECT_EQ(MixedContentChecker::ContextTypeOptionallyBlockable, MixedContentChecker::contextTypeForInspector(&dummyPageHolder->frame(), blockableMixedContent));
71 } // namespace blink