Index: url/url_util_unittest.cc |
diff --git a/url/url_util_unittest.cc b/url/url_util_unittest.cc |
index 8b16d796cf1c027e10386318b5d742aa40fb8a67..378d8f2854e6c916b51a10dde3d5fb560d2974e9 100644 |
--- a/url/url_util_unittest.cc |
+++ b/url/url_util_unittest.cc |
@@ -293,3 +293,48 @@ TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { |
EXPECT_EQ(test_data.out, resolved) << i; |
} |
} |
+ |
+TEST(URLUtilTest, TestKURLCompatMode) { |
+ // Tests the KURL compatibility mode in ResolveRelative |
+ struct ResolveRelativeCase { |
+ const char* base; |
+ const char* rel; |
+ const char* out; |
+ } kurl_compat_cases[] = { |
+ // These were all taken from running tests on KURL in WebKit 534.30. |
+ {"about:blank", "#id", "about:blank#id"}, |
+ {"about:blank#oldfrag", "#id", "about:blank#id"}, |
+ {"javascript:alert('ab#fg')", "#id", "javascript:alert('ab#id"}, |
+ {"myscheme:foo?bar#baz?xxx#yyy?zzz", "#id", "myscheme:foo?bar#id"}, |
+ {"data:foo#bar?xxx#yyy?zzz", "#id", "data:foo#id"}, |
+ {"mailto:joth@example.com#123", "#id", "mailto:joth@example.com#id"}, |
+ }; |
+ |
+ for (int compat_mode = 0; compat_mode < 2; ++compat_mode) { |
+ url_util::SetKURLCompatMode(compat_mode); |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kurl_compat_cases); i++) { |
+ const ResolveRelativeCase& test_data = kurl_compat_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(); |
+ |
+ if (!compat_mode) { |
+ EXPECT_FALSE(valid); |
+ } else { |
+ EXPECT_TRUE(valid); |
+ EXPECT_EQ(test_data.out, resolved) << i; |
+ } |
+ } |
+ } |
+ url_util::SetKURLCompatMode(false); |
+} |