Index: src/url_util_unittest.cc |
diff --git a/src/url_util_unittest.cc b/src/url_util_unittest.cc |
index a0a083821dd56dad143c8305f150a0a20ab40b20..72f3006b00a89c5de59b14693aec21067de5d1a8 100644 |
--- a/src/url_util_unittest.cc |
+++ b/src/url_util_unittest.cc |
@@ -249,3 +249,54 @@ 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[] = { |
brettw
2012/12/13 21:31:44
It would be helpful to see what's going on here if
mkosiba (inactive)
2012/12/18 18:54:07
Done.
|
+ // 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/"}, |
+ }; |
+ |
+ 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; |
+ } |
+} |