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

Unified Diff: src/url_util_unittest.cc

Issue 564011: Remove the rule that "://" means a standard URL. This fixes a number of bugs... (Closed) Base URL: http://google-url.googlecode.com/svn/trunk/
Patch Set: '' Created 10 years, 10 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 | « src/url_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/url_util_unittest.cc
===================================================================
--- src/url_util_unittest.cc (revision 122)
+++ src/url_util_unittest.cc (working copy)
@@ -96,3 +96,51 @@
&new_parsed);
}
+static std::string CheckReplaceScheme(const char* base_url,
+ const char* scheme) {
+ // Make sure the input is canonicalized.
+ url_canon::RawCanonOutput<32> original;
+ url_parse::Parsed original_parsed;
+ url_util::Canonicalize(base_url, strlen(base_url), NULL,
+ &original, &original_parsed);
+
+ url_canon::Replacements<char> replacements;
+ replacements.SetScheme(scheme, url_parse::Component(0, strlen(scheme)));
+
+ std::string output_string;
+ url_canon::StdStringCanonOutput output(&output_string);
+ url_parse::Parsed output_parsed;
+ url_util::ReplaceComponents(original.data(), original.length(),
+ original_parsed, replacements, NULL,
+ &output, &output_parsed);
+
+ output.Complete();
+ return output_string;
+}
+
+TEST(URLUtilTest, ReplaceScheme) {
+ EXPECT_EQ("https://google.com/",
+ CheckReplaceScheme("http://google.com/", "https"));
+ EXPECT_EQ("file://google.com/",
+ CheckReplaceScheme("http://google.com/", "file"));
+ EXPECT_EQ("http://home/Build",
+ CheckReplaceScheme("file:///Home/Build", "http"));
+ EXPECT_EQ("javascript:foo",
+ CheckReplaceScheme("about:foo", "javascript"));
+ EXPECT_EQ("://google.com/",
+ CheckReplaceScheme("http://google.com/", ""));
+ EXPECT_EQ("http://google.com/",
+ CheckReplaceScheme("about:google.com", "http"));
+ EXPECT_EQ("http:", CheckReplaceScheme("", "http"));
+
+#ifdef WIN32
+ // Magic Windows drive letter behavior when converting to a file URL.
+ EXPECT_EQ("file:///E:/foo/",
+ CheckReplaceScheme("http://localhost/e:foo/", "file"));
+#endif
+
+ // This will probably change to "about://google.com/" when we fix
+ // http://crbug.com/160 which should also be an acceptable result.
+ EXPECT_EQ("about://google.com/",
+ CheckReplaceScheme("http://google.com/", "about"));
+}
« no previous file with comments | « src/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698