| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "base/time/time.h" | 6 #include "base/time/time.h" |
| 7 #include "content/child/blink_platform_impl.h" | 7 #include "content/child/blink_platform_impl.h" |
| 8 #include "net/base/net_util.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | |
| 11 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | |
| 12 | 9 |
| 13 namespace content { | 10 namespace content { |
| 14 | 11 |
| 15 // Derives BlinkPlatformImpl for testing shared timers. | 12 // Derives BlinkPlatformImpl for testing shared timers. |
| 16 class TestBlinkPlatformImpl : public BlinkPlatformImpl { | 13 class TestBlinkPlatformImpl : public BlinkPlatformImpl { |
| 17 public: | 14 public: |
| 18 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {} | 15 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {} |
| 19 | 16 |
| 20 // Returns mock time when enabled. | 17 // Returns mock time when enabled. |
| 21 virtual double monotonicallyIncreasingTime() OVERRIDE { | 18 virtual double monotonicallyIncreasingTime() OVERRIDE { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 double new_time = base::Time::Now().ToDoubleT() + 1; | 57 double new_time = base::Time::Now().ToDoubleT() + 1; |
| 61 platform_impl.set_mock_monotonically_increasing_time(new_time); | 58 platform_impl.set_mock_monotonically_increasing_time(new_time); |
| 62 | 59 |
| 63 // Resume timers so that the timer set above will be set again to fire | 60 // Resume timers so that the timer set above will be set again to fire |
| 64 // immediately. | 61 // immediately. |
| 65 platform_impl.ResumeSharedTimer(); | 62 platform_impl.ResumeSharedTimer(); |
| 66 | 63 |
| 67 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay()); | 64 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay()); |
| 68 } | 65 } |
| 69 | 66 |
| 70 TEST(BlinkPlatformTest, IsReservedIPAddress_WebURL) { | |
| 71 TestBlinkPlatformImpl platform_impl; | |
| 72 | |
| 73 // Unreserved IPv4 addresses (in various forms). | |
| 74 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://8.8.8.8/"))); | |
| 75 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://99.64.0.0/"))); | |
| 76 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://212.15.0.0/"))); | |
| 77 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://212.15/"))); | |
| 78 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://212.15.0/"))); | |
| 79 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://3557752832/"))); | |
| 80 | |
| 81 // Reserved IPv4 addresses (in various forms). | |
| 82 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://192.168.0.0/"))); | |
| 83 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://192.168.0.6/"))); | |
| 84 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://10.0.0.5/"))); | |
| 85 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://10.0.0/"))); | |
| 86 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://10.0/"))); | |
| 87 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://3232235526/"))); | |
| 88 | |
| 89 // Unreserved IPv6 addresses. | |
| 90 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 91 GURL("http://[FFC0:ba98:7654:3210:FEDC:BA98:7654:3210]/"))); | |
| 92 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 93 GURL("http://[2000:ba98:7654:2301:EFCD:BA98:7654:3210]/"))); | |
| 94 | |
| 95 // Reserved IPv6 addresses. | |
| 96 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://[::1]/"))); | |
| 97 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://[::192.9.5.5]/"))); | |
| 98 EXPECT_TRUE(platform_impl.isReservedIPAddress(GURL("http://[FEED::BEEF]/"))); | |
| 99 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 100 GURL("http://[FEC0:ba98:7654:3210:FEDC:BA98:7654:3210]/"))); | |
| 101 | |
| 102 // Not IP addresses at all. | |
| 103 EXPECT_FALSE(platform_impl.isReservedIPAddress(GURL("http://example.com/"))); | |
| 104 EXPECT_FALSE( | |
| 105 platform_impl.isReservedIPAddress(GURL("http://127.0.0.1.example.com/"))); | |
| 106 | |
| 107 // Moar IPv4 | |
| 108 uint8 address[4] = {0, 0, 0, 1}; | |
| 109 for (int i = 0; i < 256; i++) { | |
| 110 address[0] = i; | |
| 111 std::string addressString = | |
| 112 net::IPAddressToString(address, sizeof(address)); | |
| 113 if (i == 0 || i == 10 || i == 127 || i > 223) { | |
| 114 EXPECT_TRUE( | |
| 115 platform_impl.isReservedIPAddress(GURL("http://" + addressString))); | |
| 116 } else { | |
| 117 EXPECT_FALSE( | |
| 118 platform_impl.isReservedIPAddress(GURL("http://" + addressString))); | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 TEST(BlinkPlatformTest, IsReservedIPAddress_WebSecurityOrigin) { | |
| 124 TestBlinkPlatformImpl platform_impl; | |
| 125 | |
| 126 // Unreserved IPv4 addresses (in various forms). | |
| 127 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 128 blink::WebSecurityOrigin::createFromString("http://8.8.8.8/"))); | |
| 129 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 130 blink::WebSecurityOrigin::createFromString("http://99.64.0.0/"))); | |
| 131 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 132 blink::WebSecurityOrigin::createFromString("http://212.15.0.0/"))); | |
| 133 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 134 blink::WebSecurityOrigin::createFromString("http://212.15/"))); | |
| 135 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 136 blink::WebSecurityOrigin::createFromString("http://212.15.0/"))); | |
| 137 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 138 blink::WebSecurityOrigin::createFromString("http://3557752832/"))); | |
| 139 | |
| 140 // Reserved IPv4 addresses (in various forms). | |
| 141 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 142 blink::WebSecurityOrigin::createFromString("http://192.168.0.0/"))); | |
| 143 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 144 blink::WebSecurityOrigin::createFromString("http://192.168.0.6/"))); | |
| 145 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 146 blink::WebSecurityOrigin::createFromString("http://10.0.0.5/"))); | |
| 147 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 148 blink::WebSecurityOrigin::createFromString("http://10.0.0/"))); | |
| 149 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 150 blink::WebSecurityOrigin::createFromString("http://10.0/"))); | |
| 151 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 152 blink::WebSecurityOrigin::createFromString("http://3232235526/"))); | |
| 153 | |
| 154 // Unreserved IPv6 addresses. | |
| 155 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 156 blink::WebSecurityOrigin::createFromString( | |
| 157 "http://[FFC0:ba98:7654:3210:FEDC:BA98:7654:3210]/"))); | |
| 158 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 159 blink::WebSecurityOrigin::createFromString( | |
| 160 "http://[2000:ba98:7654:2301:EFCD:BA98:7654:3210]/"))); | |
| 161 | |
| 162 // Reserved IPv6 addresses. | |
| 163 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 164 blink::WebSecurityOrigin::createFromString("http://[::1]/"))); | |
| 165 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 166 blink::WebSecurityOrigin::createFromString("http://[::192.9.5.5]/"))); | |
| 167 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 168 blink::WebSecurityOrigin::createFromString("http://[FEED::BEEF]/"))); | |
| 169 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 170 blink::WebSecurityOrigin::createFromString( | |
| 171 "http://[FEC0:ba98:7654:3210:FEDC:BA98:7654:3210]/"))); | |
| 172 | |
| 173 // Not IP addresses at all. | |
| 174 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 175 blink::WebSecurityOrigin::createFromString("http://example.com/"))); | |
| 176 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 177 blink::WebSecurityOrigin::createFromString( | |
| 178 "http://127.0.0.1.example.com/"))); | |
| 179 | |
| 180 // Moar IPv4 | |
| 181 uint8 address[4] = {0, 0, 0, 1}; | |
| 182 for (int i = 0; i < 256; i++) { | |
| 183 address[0] = i; | |
| 184 blink::WebString addressString = blink::WebString::fromUTF8( | |
| 185 "http://" + net::IPAddressToString(address, sizeof(address)) + "/"); | |
| 186 if (i == 0 || i == 10 || i == 127 || i > 223) { | |
| 187 EXPECT_TRUE(platform_impl.isReservedIPAddress( | |
| 188 blink::WebSecurityOrigin::createFromString(addressString))); | |
| 189 } else { | |
| 190 EXPECT_FALSE(platform_impl.isReservedIPAddress( | |
| 191 blink::WebSecurityOrigin::createFromString(addressString))); | |
| 192 } | |
| 193 } | |
| 194 } | |
| 195 | |
| 196 } // namespace content | 67 } // namespace content |
| OLD | NEW |