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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/child/blink_platform_unittest.cc
diff --git a/content/child/blink_platform_unittest.cc b/content/child/blink_platform_unittest.cc
index 88a3c0dc518ac59b0b313d7e6be96d6f741845e6..7f23bebeabf292a8917363012af9ac8b568956b8 100644
--- a/content/child/blink_platform_unittest.cc
+++ b/content/child/blink_platform_unittest.cc
@@ -5,7 +5,9 @@
#include "base/run_loop.h"
#include "base/time/time.h"
#include "content/child/blink_platform_impl.h"
+#include "net/base/net_util.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebString.h"
namespace content {
@@ -64,4 +66,55 @@ TEST(BlinkPlatformTest, SuspendResumeSharedTimer) {
EXPECT_TRUE(base::TimeDelta() == platform_impl.shared_timer_delay());
}
+TEST(BlinkPlatformTest, IsHostnameReservedIPAddress) {
+ TestBlinkPlatformImpl platform_impl;
+
+ // Unreserved IPv4 addresses (in various forms).
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("8.8.8.8"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("99.64.0.0"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15.0.0"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("212.15.0"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("3557752832"));
+
+ // Reserved IPv4 addresses (in various forms).
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("192.168.0.0"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("192.168.0.6"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0.0.5"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0.0"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("10.0"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("3232235526"));
+
+ // Unreserved IPv6 addresses.
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(
+ "[FFC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(
+ "[2000:ba98:7654:2301:EFCD:BA98:7654:3210]"));
+
+ // Reserved IPv6 addresses.
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[::1]"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[::192.9.5.5]"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress("[FEED::BEEF]"));
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress(
+ "[FEC0:ba98:7654:3210:FEDC:BA98:7654:3210]"));
+
+ // Not IP addresses at all.
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress("example.com"));
+ EXPECT_FALSE(
+ platform_impl.isHostnameReservedIPAddress("127.0.0.1.example.com"));
+
+ // Moar IPv4
+ uint8 address[4] = {0, 0, 0, 1};
+ for (int i = 0; i < 256; i++) {
+ address[0] = i;
+ blink::WebString addressString = blink::WebString::fromUTF8(
+ net::IPAddressToString(address, sizeof(address)));
+ if (i == 0 || i == 10 || i == 127 || i > 223) {
+ EXPECT_TRUE(platform_impl.isHostnameReservedIPAddress(addressString));
+ } else {
+ EXPECT_FALSE(platform_impl.isHostnameReservedIPAddress(addressString));
+ }
+ }
+}
+
} // namespace content
« 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