Index: url/url_canon_unittest.cc |
diff --git a/url/url_canon_unittest.cc b/url/url_canon_unittest.cc |
index 8f71a911188f4bd2031a3686f09d3b2d91447b4f..0d6056eeedd213885f7b5c27bcdd4a79e1a37818 100644 |
--- a/url/url_canon_unittest.cc |
+++ b/url/url_canon_unittest.cc |
@@ -887,6 +887,50 @@ TEST(URLCanonTest, IPEmpty) { |
EXPECT_FALSE(host_info.IsIPAddress()); |
} |
+// Verifies that CanonicalizeHostSubstring produces the expected output and |
+// does not "fix" IP addresses. Because this code is a subset of |
+// CanonicalizeHost, the shared functionality is not tested. |
+TEST(URLCanonTest, CanonicalizeHostSubstring) { |
+ // Basic sanity check. |
+ { |
+ std::string out_str; |
+ StdStringCanonOutput output(&out_str); |
+ EXPECT_TRUE(CanonicalizeHostSubstring( |
+ "M\xc3\x9cNCHEN.com", Component(0, 12), &output)); |
+ output.Complete(); |
+ EXPECT_EQ("xn--mnchen-3ya.com", out_str); |
+ } |
+ |
+ // Failure case. |
+ { |
+ std::string out_str; |
+ StdStringCanonOutput output(&out_str); |
+ EXPECT_FALSE(CanonicalizeHostSubstring( |
+ WStringToUTF16(L"\xfdd0zyx.com").c_str(), Component(0, 8), &output)); |
+ output.Complete(); |
+ EXPECT_EQ("%EF%BF%BDzyx.com", out_str); |
+ } |
+ |
+ // Should return true for empty input strings. |
+ { |
+ std::string out_str; |
+ StdStringCanonOutput output(&out_str); |
+ EXPECT_TRUE(CanonicalizeHostSubstring("", Component(0, 0), &output)); |
+ output.Complete(); |
+ EXPECT_EQ("", out_str); |
Peter Kasting
2016/10/22 05:04:20
Nit: Since |out_str| is a std::string I tend to pr
|
+ } |
+ |
+ // Numbers that look like IP addresses should not be changed. |
+ { |
+ std::string out_str; |
+ StdStringCanonOutput output(&out_str); |
+ EXPECT_TRUE(CanonicalizeHostSubstring( |
+ "01.02.03.04", Component(0, 11), &output)); |
+ output.Complete(); |
+ EXPECT_EQ("01.02.03.04", out_str); |
+ } |
+} |
+ |
TEST(URLCanonTest, UserInfo) { |
// Note that the canonicalizer should escape and treat empty components as |
// not being there. |