Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: url/url_util_unittest.cc

Issue 23835019: Support URL fragment resolution againt non-hierarchical schemes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: brettw2 Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « url/url_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 21 matching lines...) Expand all
128 #ifdef WIN32 128 #ifdef WIN32
129 // Magic Windows drive letter behavior when converting to a file URL. 129 // Magic Windows drive letter behavior when converting to a file URL.
130 EXPECT_EQ("file:///E:/foo/", 130 EXPECT_EQ("file:///E:/foo/",
131 CheckReplaceScheme("http://localhost/e:foo/", "file")); 131 CheckReplaceScheme("http://localhost/e:foo/", "file"));
132 #endif 132 #endif
133 133
134 // This will probably change to "about://google.com/" when we fix 134 // This will probably change to "about://google.com/" when we fix
135 // http://crbug.com/160 which should also be an acceptable result. 135 // http://crbug.com/160 which should also be an acceptable result.
136 EXPECT_EQ("about://google.com/", 136 EXPECT_EQ("about://google.com/",
137 CheckReplaceScheme("http://google.com/", "about")); 137 CheckReplaceScheme("http://google.com/", "about"));
138
139 EXPECT_EQ("http://example.com/%20hello%20# world",
140 CheckReplaceScheme("myscheme:example.com/ hello # world ", "http"));
138 } 141 }
139 142
140 TEST(URLUtilTest, DecodeURLEscapeSequences) { 143 TEST(URLUtilTest, DecodeURLEscapeSequences) {
141 struct DecodeCase { 144 struct DecodeCase {
142 const char* input; 145 const char* input;
143 const char* output; 146 const char* output;
144 } decode_cases[] = { 147 } decode_cases[] = {
145 {"hello, world", "hello, world"}, 148 {"hello, world", "hello, world"},
146 {"%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/", 149 {"%01%02%03%04%05%06%07%08%09%0a%0B%0C%0D%0e%0f/",
147 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/"}, 150 "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0B\x0C\x0D\x0e\x0f/"},
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // Resolving an absolute URL doesn't cause canonicalization of the 266 // Resolving an absolute URL doesn't cause canonicalization of the
264 // result. 267 // result.
265 {"about:blank", "custom://Authority", true, "custom://Authority"}, 268 {"about:blank", "custom://Authority", true, "custom://Authority"},
266 // Fragment URLs can be resolved against a non-standard base. 269 // Fragment URLs can be resolved against a non-standard base.
267 {"scheme://Authority/path", "#fragment", true, 270 {"scheme://Authority/path", "#fragment", true,
268 "scheme://Authority/path#fragment"}, 271 "scheme://Authority/path#fragment"},
269 {"scheme://Authority/", "#fragment", true, "scheme://Authority/#fragment"}, 272 {"scheme://Authority/", "#fragment", true, "scheme://Authority/#fragment"},
270 // Resolving should fail if the base URL is authority-based but is 273 // Resolving should fail if the base URL is authority-based but is
271 // missing a path component (the '/' at the end). 274 // missing a path component (the '/' at the end).
272 {"scheme://Authority", "path", false, ""}, 275 {"scheme://Authority", "path", false, ""},
276 // Test resolving a fragment (only) against any kind of base-URL.
277 {"about:blank", "#id42", true, "about:blank#id42" },
278 {"about:blank", " #id42", true, "about:blank#id42" },
279 {"about:blank#oldfrag", "#newfrag", true, "about:blank#newfrag" },
280 // A surprising side effect of allowing fragments to resolve against
281 // any URL scheme is we might break javascript: URLs by doing so...
282 {"javascript:alert('foo#bar')", "#badfrag", true,
283 "javascript:alert('foo#badfrag" },
273 }; 284 };
274 285
275 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) { 286 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(resolve_non_standard_cases); i++) {
276 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i]; 287 const ResolveRelativeCase& test_data = resolve_non_standard_cases[i];
277 url_parse::Parsed base_parsed; 288 url_parse::Parsed base_parsed;
278 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), 289 url_parse::ParsePathURL(test_data.base, strlen(test_data.base), false,
279 &base_parsed); 290 &base_parsed);
280 291
281 std::string resolved; 292 std::string resolved;
282 url_canon::StdStringCanonOutput output(&resolved); 293 url_canon::StdStringCanonOutput output(&resolved);
283 url_parse::Parsed resolved_parsed; 294 url_parse::Parsed resolved_parsed;
284 bool valid = 295 bool valid =
285 url_util::ResolveRelative(test_data.base, strlen(test_data.base), 296 url_util::ResolveRelative(test_data.base, strlen(test_data.base),
286 base_parsed, 297 base_parsed,
287 test_data.rel, strlen(test_data.rel), 298 test_data.rel, strlen(test_data.rel),
288 NULL, &output, &resolved_parsed); 299 NULL, &output, &resolved_parsed);
289 output.Complete(); 300 output.Complete();
290 301
291 EXPECT_EQ(test_data.is_valid, valid) << i; 302 EXPECT_EQ(test_data.is_valid, valid) << i;
292 if (test_data.is_valid && valid) 303 if (test_data.is_valid && valid)
293 EXPECT_EQ(test_data.out, resolved) << i; 304 EXPECT_EQ(test_data.out, resolved) << i;
294 } 305 }
295 } 306 }
OLDNEW
« no previous file with comments | « url/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698