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

Unified Diff: src/url_util_unittest.cc

Issue 11367010: Make ResolveRelative work with all hierarchical URLs. (Closed) Base URL: http://git.chromium.org/external/google-url.git@master
Patch Set: fix nits Created 8 years 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
diff --git a/src/url_util_unittest.cc b/src/url_util_unittest.cc
index a0a083821dd56dad143c8305f150a0a20ab40b20..c7b39fecb5dbfadfa82bc7b5a53a64b2a11f95ef 100644
--- a/src/url_util_unittest.cc
+++ b/src/url_util_unittest.cc
@@ -249,3 +249,62 @@ TEST(URLUtilTest, TestEncodeURIComponent) {
}
}
+TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) {
+ // This tests non-standard (in the sense that GURL::IsStandard() == false)
+ // hierarchical schemes.
+ struct ResolveRelativeCase {
+ const char* base;
+ const char* rel;
+ bool is_valid;
+ const char* out;
+ } resolve_non_standard_cases[] = {
+ // Resolving a relative path against a non-hierarchical URL should fail.
+ {"scheme:opaque_data", "/path", false, ""},
+ // Resolving a relative path against a non-standard authority-based base
+ // URL doesn't alter the authority section.
+ {"scheme://Authority/", "../path", true, "scheme://Authority/path"},
+ // A non-standard hierarchical base is resolved with path URL
+ // canoncialization rules.
+ {"data:/Blah:Blah/", "file.html", true, "data:/Blah:Blah/file.html"},
+ {"data:/Path/../part/part2", "file.html", true, "data:/Path/../part/file.html"},
+ // Path URL canonicalization rules also apply to non-standard authority-
+ // based URLs.
+ {"custom://Authority/", "file.html", true, "custom://Authority/file.html"},
+ {"custom://Authority/", "other://Auth/", true, "other://Auth/"},
+ {"custom://Authority/", "../../file.html", true, "custom://Authority/file.html"},
+ {"custom://Authority/path/", "file.html", true, "custom://Authority/path/file.html"},
+ {"custom://Authority:NoCanon/path/", "file.html", true, "custom://Authority:NoCanon/path/file.html"},
+ // It's still possible to get an invalid path URL.
+ {"custom://Invalid:!#Auth/", "file.html", false, ""},
+ // A path with an authority section gets canonicalized under standard URL
+ // rules, even though the base was non-standard.
+ {"content://content.Provider/", "//other.Provider", true, "content://other.provider/"},
+ // Resolving an absolute URL doesn't cause canonicalization of the
+ // result.
+ {"about:blank", "custom://Authority", true, "custom://Authority"},
mkosiba (inactive) 2012/12/18 18:54:07 For now we're going to live with this and ask app
+ // Resolving should fail if the base URL is authority-based but is
+ // missing a path component (the '/' at the end).
+ {"scheme://Authority", "path", false, ""},
+ };
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) {
+ const ResolveRelativeCase& test_data = resolve_non_standard_cases[i];
+ url_parse::Parsed base_parsed;
+ url_parse::ParsePathURL(test_data.base, strlen(test_data.base),
+ &base_parsed);
+
+ std::string resolved;
+ url_canon::StdStringCanonOutput output(&resolved);
+ url_parse::Parsed resolved_parsed;
+ bool valid =
+ url_util::ResolveRelative(test_data.base, strlen(test_data.base),
+ base_parsed,
+ test_data.rel, strlen(test_data.rel),
+ NULL, &output, &resolved_parsed);
+ output.Complete();
+
+ EXPECT_EQ(test_data.is_valid, valid) << i;
+ if (test_data.is_valid && valid)
+ EXPECT_EQ(test_data.out, resolved) << i;
+ }
+}
« 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