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 "content/child/blink_platform_impl.h"
7 #include "base/run_loop.h"
8 #include "base/time/time.h"
9 #include "net/base/ip_address_number.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/platform/WebString.h"
12 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
16 TEST(BlinkPlatformTest
, IsReservedIPAddress
) {
17 BlinkPlatformImpl platform_impl
;
19 // Unreserved IPv4 addresses (in various forms).
20 EXPECT_FALSE(platform_impl
.isReservedIPAddress("8.8.8.8"));
21 EXPECT_FALSE(platform_impl
.isReservedIPAddress("99.64.0.0"));
22 EXPECT_FALSE(platform_impl
.isReservedIPAddress("212.15.0.0"));
23 EXPECT_FALSE(platform_impl
.isReservedIPAddress("212.15"));
24 EXPECT_FALSE(platform_impl
.isReservedIPAddress("212.15.0"));
25 EXPECT_FALSE(platform_impl
.isReservedIPAddress("3557752832"));
27 // Reserved IPv4 addresses (in various forms).
28 EXPECT_TRUE(platform_impl
.isReservedIPAddress("192.168.0.0"));
29 EXPECT_TRUE(platform_impl
.isReservedIPAddress("192.168.0.6"));
30 EXPECT_TRUE(platform_impl
.isReservedIPAddress("10.0.0.5"));
31 EXPECT_TRUE(platform_impl
.isReservedIPAddress("10.0.0"));
32 EXPECT_TRUE(platform_impl
.isReservedIPAddress("10.0"));
33 EXPECT_TRUE(platform_impl
.isReservedIPAddress("3232235526"));
35 // Unreserved IPv6 addresses.
36 EXPECT_FALSE(platform_impl
.isReservedIPAddress(
37 "[FFC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
38 EXPECT_FALSE(platform_impl
.isReservedIPAddress(
39 "[2000:ba98:7654:2301:EFCD:BA98:7654:3210]"));
41 // Reserved IPv6 addresses.
42 EXPECT_TRUE(platform_impl
.isReservedIPAddress("[::1]"));
43 EXPECT_TRUE(platform_impl
.isReservedIPAddress("[::192.9.5.5]"));
44 EXPECT_TRUE(platform_impl
.isReservedIPAddress("[FEED::BEEF]"));
45 EXPECT_TRUE(platform_impl
.isReservedIPAddress(
46 "[FEC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
48 // Not IP addresses at all.
49 EXPECT_FALSE(platform_impl
.isReservedIPAddress("example.com"));
50 EXPECT_FALSE(platform_impl
.isReservedIPAddress("127.0.0.1.example.com"));
53 uint8 address
[4] = {0, 0, 0, 1};
54 for (int i
= 0; i
< 256; i
++) {
56 std::string addressString
=
57 net::IPAddressToString(address
, sizeof(address
));
58 if (i
== 0 || i
== 10 || i
== 127 || i
> 223) {
59 EXPECT_TRUE(platform_impl
.isReservedIPAddress(
60 blink::WebString::fromUTF8(addressString
)));
62 EXPECT_FALSE(platform_impl
.isReservedIPAddress(
63 blink::WebString::fromUTF8(addressString
)));
68 TEST(BlinkPlatformTest
, portAllowed
) {
69 BlinkPlatformImpl platform_impl
;
70 EXPECT_TRUE(platform_impl
.portAllowed(GURL("http://example.com")));
71 EXPECT_TRUE(platform_impl
.portAllowed(GURL("file://example.com")));
72 EXPECT_TRUE(platform_impl
.portAllowed(GURL("file://example.com:87")));
73 EXPECT_TRUE(platform_impl
.portAllowed(GURL("ftp://example.com:21")));
74 EXPECT_FALSE(platform_impl
.portAllowed(GURL("ftp://example.com:87")));
75 EXPECT_FALSE(platform_impl
.portAllowed(GURL("ws://example.com:21")));
76 EXPECT_TRUE(platform_impl
.portAllowed(GURL("http://example.com:80")));
77 EXPECT_TRUE(platform_impl
.portAllowed(GURL("http://example.com:8889")));
80 } // namespace content