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

Unified Diff: url/url_canon_unittest.cc

Issue 2433583002: Reduce buggy usage of the registry controlled domain service. (Closed)
Patch Set: Review comments Created 4 years, 2 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
« no previous file with comments | « url/url_canon_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/url_canon_unittest.cc
diff --git a/url/url_canon_unittest.cc b/url/url_canon_unittest.cc
index 837bc19f0821bbae0713a8e9020b8da2a8ecb37a..caaff08de61fdf37fb8f771f08431500cee8761a 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(std::string(), out_str);
+ }
+
+ // 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.
« no previous file with comments | « url/url_canon_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698