Chromium Code Reviews| 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 252 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 // An unfortunate 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" }, | |
|
mkosiba (inactive)
2013/08/27 20:55:56
out of curiousity - what would KURL do in this cas
| |
| 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), |
| 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 |