Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: content/child/blink_platform_unittest.cc

Issue 430193002: Wire 'blink::Platform::isHostnameReservedIPAddress()' to 'net::IsReservedIPAddress()'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebString.h"
9 11
10 namespace content { 12 namespace content {
11 13
12 // Derives BlinkPlatformImpl for testing shared timers. 14 // Derives BlinkPlatformImpl for testing shared timers.
13 class TestBlinkPlatformImpl : public BlinkPlatformImpl { 15 class TestBlinkPlatformImpl : public BlinkPlatformImpl {
14 public: 16 public:
15 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {} 17 TestBlinkPlatformImpl() : mock_monotonically_increasing_time_(0) {}
16 18
17 // Returns mock time when enabled. 19 // Returns mock time when enabled.
18 virtual double monotonicallyIncreasingTime() OVERRIDE { 20 virtual double monotonicallyIncreasingTime() OVERRIDE {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 double new_time = base::Time::Now().ToDoubleT() + 1; 59 double new_time = base::Time::Now().ToDoubleT() + 1;
58 platform_impl.set_mock_monotonically_increasing_time(new_time); 60 platform_impl.set_mock_monotonically_increasing_time(new_time);
59 61
60 // Resume timers so that the timer set above will be set again to fire 62 // Resume timers so that the timer set above will be set again to fire
61 // immediately. 63 // immediately.
62 platform_impl.ResumeSharedTimer(); 64 platform_impl.ResumeSharedTimer();
63 65
64 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay()); 66 EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay());
65 } 67 }
66 68
69 TEST(BlinkPlatformTest, IsHostnameReservedIPAddress) {
70 TestBlinkPlatformImpl platform_impl;
71
72 // Unreserved IPv4 addresses (in various forms).
73 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("8.8.8.8"));
74 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("99.64.0.0"));
75 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15.0.0"));
76 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15"));
77 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15.0"));
78 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("3557752832"));
79
80 // Reserved IPv4 addresses (in various forms).
81 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("192.168.0.0"));
82 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("192.168.0.6"));
83 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0.0.5"));
84 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0.0"));
85 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0"));
86 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("3232235526"));
87
88 // Unreserved IPv6 addresses.
89 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(
90 "[FFC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
91 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(
92 "[2000:ba98:7654:2301:EFCD:BA98:7654:3210]"));
93
94 // Reserved IPv6 addresses.
95 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[::1]"));
96 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[::192.9.5.5]"));
97 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[FEED::BEEF]"));
98 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress(
99 "[FEC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
100
101 // Not IP addresses at all.
102 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("example.com"));
103 EXPECT_FALSE(
104 platform_impl.isHostnameReservedIPAddress("127.0.0.1.example.com"));
105
106 // Moar IPv4
107 uint8 address[4] = {0, 0, 0, 1};
108 for (int i = 0; i < 256; i++) {
109 address[0] = i;
110 blink::WebString addressString = blink::WebString::fromUTF8(
111 net::IPAddressToString(address, sizeof(address)));
112 if (i == 0 || i == 10 || i == 127 || i > 223) {
113 EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress(addressString));
114 } else {
115 EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(addressString));
116 }
117 }
118 }
119
67 } // namespace content 120 } // namespace content
OLDNEW
« content/child/blink_platform_impl.cc ('K') | « content/child/blink_platform_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698