OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "url/url_canon.h" | 6 #include "url/url_canon.h" |
7 #include "url/url_canon_stdstring.h" | 7 #include "url/url_canon_stdstring.h" |
8 #include "url/url_parse.h" | 8 #include "url/url_parse.h" |
9 #include "url/url_test_utils.h" | 9 #include "url/url_test_utils.h" |
10 #include "url/url_util.h" | 10 #include "url/url_util.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 &new_parsed); | 86 &new_parsed); |
87 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, | 87 url_util::ReplaceComponents("", 0, parsed, replacements, NULL, &output, |
88 &new_parsed); | 88 &new_parsed); |
89 } | 89 } |
90 | 90 |
91 static std::string CheckReplaceScheme(const char* base_url, | 91 static std::string CheckReplaceScheme(const char* base_url, |
92 const char* scheme) { | 92 const char* scheme) { |
93 // Make sure the input is canonicalized. | 93 // Make sure the input is canonicalized. |
94 url_canon::RawCanonOutput<32> original; | 94 url_canon::RawCanonOutput<32> original; |
95 url_parse::Parsed original_parsed; | 95 url_parse::Parsed original_parsed; |
96 url_util::Canonicalize(base_url, strlen(base_url), NULL, | 96 url_util::Canonicalize(base_url, strlen(base_url), true, NULL, |
97 &original, &original_parsed); | 97 &original, &original_parsed); |
98 | 98 |
99 url_canon::Replacements<char> replacements; | 99 url_canon::Replacements<char> replacements; |
100 replacements.SetScheme(scheme, url_parse::Component(0, strlen(scheme))); | 100 replacements.SetScheme(scheme, url_parse::Component(0, strlen(scheme))); |
101 | 101 |
102 std::string output_string; | 102 std::string output_string; |
103 url_canon::StdStringCanonOutput output(&output_string); | 103 url_canon::StdStringCanonOutput output(&output_string); |
104 url_parse::Parsed output_parsed; | 104 url_parse::Parsed output_parsed; |
105 url_util::ReplaceComponents(original.data(), original.length(), | 105 url_util::ReplaceComponents(original.data(), original.length(), |
106 original_parsed, replacements, NULL, | 106 original_parsed, replacements, NULL, |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 // Resolving an absolute URL doesn't cause canonicalization of the | 263 // Resolving an absolute URL doesn't cause canonicalization of the |
264 // result. | 264 // result. |
265 {"about:blank", "custom://Authority", true, "custom://Authority"}, | 265 {"about:blank", "custom://Authority", true, "custom://Authority"}, |
266 // Fragment URLs can be resolved against a non-standard base. | 266 // Fragment URLs can be resolved against a non-standard base. |
267 {"scheme://Authority/path", "#fragment", true, | 267 {"scheme://Authority/path", "#fragment", true, |
268 "scheme://Authority/path#fragment"}, | 268 "scheme://Authority/path#fragment"}, |
269 {"scheme://Authority/", "#fragment", true, "scheme://Authority/#fragment"}, | 269 {"scheme://Authority/", "#fragment", true, "scheme://Authority/#fragment"}, |
270 // Resolving should fail if the base URL is authority-based but is | 270 // Resolving should fail if the base URL is authority-based but is |
271 // missing a path component (the '/' at the end). | 271 // missing a path component (the '/' at the end). |
272 {"scheme://Authority", "path", false, ""}, | 272 {"scheme://Authority", "path", false, ""}, |
| 273 // Test resolving a fragment (only) against any kind of base-URL. |
| 274 {"about:blank", "#id42", true, "about:blank#id42" }, |
| 275 {"about:blank#oldfrag", "#newfrag", true, "about:blank#newfrag" }, |
| 276 // A surprising side effect of allowing fragments to resolve against |
| 277 // any URL scheme is we might break javascript: URLs by doing so... |
| 278 {"javascript:alert('foo#bar')", "#badfrag", true, |
| 279 "javascript:alert('foo#badfrag" }, |
273 }; | 280 }; |
274 | 281 |
275 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { | 282 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { |
276 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; | 283 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; |
277 url_parse::Parsed base_parsed; | 284 url_parse::Parsed base_parsed; |
278 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), | 285 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), false, |
279 &base_parsed); | 286 &base_parsed); |
280 | 287 |
281 std::string resolved; | 288 std::string resolved; |
282 url_canon::StdStringCanonOutput output(&resolved); | 289 url_canon::StdStringCanonOutput output(&resolved); |
283 url_parse::Parsed resolved_parsed; | 290 url_parse::Parsed resolved_parsed; |
284 bool valid = | 291 bool valid = |
285 url_util::ResolveRelative(test_data.base, strlen(test_data.base), | 292 url_util::ResolveRelative(test_data.base, strlen(test_data.base), |
286 base_parsed, | 293 base_parsed, |
287 test_data.rel, strlen(test_data.rel), | 294 test_data.rel, strlen(test_data.rel), |
288 NULL, &output, &resolved_parsed); | 295 NULL, &output, &resolved_parsed); |
289 output.Complete(); | 296 output.Complete(); |
290 | 297 |
291 EXPECT_EQ(test_data.is_valid, valid) << i; | 298 EXPECT_EQ(test_data.is_valid, valid) << i; |
292 if (test_data.is_valid && valid) | 299 if (test_data.is_valid && valid) |
293 EXPECT_EQ(test_data.out, resolved) << i; | 300 EXPECT_EQ(test_data.out, resolved) << i; |
294 } | 301 } |
295 } | 302 } |
OLD | NEW |