OLD | NEW |
---|---|
1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 242 |
243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) { | 243 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(encode_cases); i++) { |
244 const char* input = encode_cases[i].input; | 244 const char* input = encode_cases[i].input; |
245 url_canon::RawCanonOutputT<char> buffer; | 245 url_canon::RawCanonOutputT<char> buffer; |
246 url_util::EncodeURIComponent(input, strlen(input), &buffer); | 246 url_util::EncodeURIComponent(input, strlen(input), &buffer); |
247 std::string output(buffer.data(), buffer.length()); | 247 std::string output(buffer.data(), buffer.length()); |
248 EXPECT_EQ(encode_cases[i].output, output); | 248 EXPECT_EQ(encode_cases[i].output, output); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 TEST(URLUtilTest, TestResolveRelativeWithNonStandardBase) { | |
253 // This tests non-standard (in the sense that GURL::IsStandard() == false) | |
254 // hierarchical schemes. | |
255 struct ResolveRelativeCase { | |
256 const char* base; | |
257 const char* rel; | |
258 bool is_valid; | |
259 const char* out; | |
260 } resolve_non_standard_cases[] = { | |
261 // Resolving a relative path against a non-hierarchical URL should fail. | |
262 {"scheme:opaque_data", "/path", false, ""}, | |
263 // Resolving a relative path against a non-standard authority-based base | |
264 // URL doesn't alter the authority section. | |
265 {"scheme://Authority/", "../path", true, "scheme://Authority/path"}, | |
266 // A non-standard hierarchical base is resolved with path URL | |
267 // canoncialization rules. | |
268 {"data:/Blah:Blah/", "file.html", true, "data:/Blah:Blah/file.html"}, | |
269 {"data:/Path/../part/part2", "file.html", true, "data:/Path/../part/file.htm l"}, | |
270 // Path URL canonicalization rules also apply to non-standard authority- | |
271 // based URLs. | |
272 {"custom://Authority/", "file.html", true, "custom://Authority/file.html"}, | |
273 {"custom://Authority/", "other://Auth/", true, "other://Auth/"}, | |
274 {"custom://Authority/", "../../file.html", true, "custom://Authority/file.ht ml"}, | |
275 {"custom://Authority/path/", "file.html", true, "custom://Authority/path/fil e.html"}, | |
276 {"custom://Authority:NoCanon/path/", "file.html", true, "custom://Authority: NoCanon/path/file.html"}, | |
277 // It's still possible to get an invalid path URL. | |
278 {"custom://Invalid:!#Auth/", "file.html", false, ""}, | |
279 // A path with an authority section gets canonicalized under standard URL | |
280 // rules, even though the base was non-standard. | |
281 {"content://content.Provider/", "//other.Provider", true, "content://other.p rovider/"}, | |
282 // Resolving an absolute URL doesn't cause canonicalization of the | |
283 // result. | |
284 {"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
| |
285 // Resolving should fail if the base URL is authority-based but is | |
286 // missing a path component (the '/' at the end). | |
287 {"scheme://Authority", "path", false, ""}, | |
288 }; | |
289 | |
290 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { | |
291 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; | |
292 url_parse::Parsed base_parsed; | |
293 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), | |
294 &base_parsed); | |
295 | |
296 std::string resolved; | |
297 url_canon::StdStringCanonOutput output(&resolved); | |
298 url_parse::Parsed resolved_parsed; | |
299 bool valid = | |
300 url_util::ResolveRelative(test_data.base, strlen(test_data.base), | |
301 base_parsed, | |
302 test_data.rel, strlen(test_data.rel), | |
303 NULL, &output, &resolved_parsed); | |
304 output.Complete(); | |
305 | |
306 EXPECT_EQ(test_data.is_valid, valid) << i; | |
307 if (test_data.is_valid && valid) | |
308 EXPECT_EQ(test_data.out, resolved) << i; | |
309 } | |
310 } | |
OLD | NEW |