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[] = { | |
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.
| |
261 // Resolving a relative path against a non-standard authority-based base | |
262 // URL doesn't alter the authority section. | |
263 {"scheme://Authority/", "../path", true, "scheme://Authority/path"}, | |
264 // A non-standard hierarchical base is resolved with path URL | |
265 // canoncialization rules. | |
266 {"data:/Blah:Blah/", "file.html", true, "data:/Blah:Blah/file.html"}, | |
267 {"data:/Path/../part/part2", "file.html", true, "data:/Path/../part/file.htm l"}, | |
268 // Path URL canonicalization rules also apply to non-standard authority- | |
269 // based URLs. | |
270 {"custom://Authority/", "file.html", true, "custom://Authority/file.html"}, | |
271 {"custom://Authority/", "other://Auth/", true, "other://Auth/"}, | |
272 {"custom://Authority/", "../../file.html", true, "custom://Authority/file.ht ml"}, | |
273 {"custom://Authority/path/", "file.html", true, "custom://Authority/path/fil e.html"}, | |
274 {"custom://Authority:NoCanon/path/", "file.html", true, "custom://Authority: NoCanon/path/file.html"}, | |
275 // It's still possible to get an invalid path URL. | |
276 {"custom://Invalid:!#Auth/", "file.html", false, ""}, | |
277 // A path with an authority section gets canonicalized under standard URL | |
278 // rules, even though the base was non-standard. | |
279 {"content://content.Provider/", "//other.Provider", true, "content://other.p rovider/"}, | |
280 }; | |
281 | |
282 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { | |
283 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; | |
284 url_parse::Parsed base_parsed; | |
285 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), | |
286 &base_parsed); | |
287 | |
288 std::string resolved; | |
289 url_canon::StdStringCanonOutput output(&resolved); | |
290 url_parse::Parsed resolved_parsed; | |
291 bool valid = | |
292 url_util::ResolveRelative(test_data.base, strlen(test_data.base), | |
293 base_parsed, | |
294 test_data.rel, strlen(test_data.rel), | |
295 NULL, &output, &resolved_parsed); | |
296 output.Complete(); | |
297 | |
298 EXPECT_EQ(test_data.is_valid, valid) << i; | |
299 if (test_data.is_valid && valid) | |
300 EXPECT_EQ(test_data.out, resolved) << i; | |
301 } | |
302 } | |
OLD | NEW |