Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / loader / MixedContentCheckerTest.cpp
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.
4
5 #include "config.h"
6 #include "core/loader/MixedContentChecker.h"
7
8 #include "platform/weborigin/KURL.h"
9 #include "platform/weborigin/SecurityOrigin.h"
10 #include "wtf/RefPtr.h"
11
12 #include <base/macros.h>
13 #include <gtest/gtest.h>
14
15 namespace WebCore {
16
17 TEST(MixedContentCheckerTest, IsMixedContent)
18 {
19     struct TestCase {
20         const char* origin;
21         const char* target;
22         bool expectation;
23     } cases[] = {
24         {"http://example.com/foo", "http://example.com/foo", false},
25         {"http://example.com/foo", "https://example.com/foo", false},
26         {"https://example.com/foo", "https://example.com/foo", false},
27         {"https://example.com/foo", "wss://example.com/foo", false},
28         {"https://example.com/foo", "http://example.com/foo", true},
29         {"https://example.com/foo", "http://google.com/foo", true},
30         {"https://example.com/foo", "ws://example.com/foo", true},
31         {"https://example.com/foo", "ws://google.com/foo", true},
32     };
33
34     for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) {
35         const char* origin = cases[i].origin;
36         const char* target = cases[i].target;
37         bool expectation = cases[i].expectation;
38
39         KURL originUrl(KURL(), origin);
40         RefPtr<SecurityOrigin> securityOrigin(SecurityOrigin::create(originUrl));
41         KURL targetUrl(KURL(), target);
42         EXPECT_EQ(expectation, MixedContentChecker::isMixedContent(securityOrigin.get(), targetUrl)) << "Origin: " << origin << ", Target: " << target << ", Expectation: " << expectation;
43     }
44 }
45
46 } // namespace WebCore