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

Side by Side Diff: url/url_util_unittest.cc

Issue 23468003: Allow fragments to resolve relatively against any scheme (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: really fix Created 7 years, 3 months 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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 base_parsed, 286 base_parsed,
287 test_data.rel, strlen(test_data.rel), 287 test_data.rel, strlen(test_data.rel),
288 NULL, &output, &resolved_parsed); 288 NULL, &output, &resolved_parsed);
289 output.Complete(); 289 output.Complete();
290 290
291 EXPECT_EQ(test_data.is_valid, valid) << i; 291 EXPECT_EQ(test_data.is_valid, valid) << i;
292 if (test_data.is_valid && valid) 292 if (test_data.is_valid && valid)
293 EXPECT_EQ(test_data.out, resolved) << i; 293 EXPECT_EQ(test_data.out, resolved) << i;
294 } 294 }
295 } 295 }
296
297 TEST(URLUtilTest, TestKURLCompatMode) {
298 // Tests the KURL compatibility mode in ResolveRelative
299 struct ResolveRelativeCase {
300 const char* base;
301 const char* rel;
302 const char* out;
303 } kurl_compat_cases[] = {
304 // These were all taken from running tests on KURL in WebKit 534.30.
305 {"about:blank", "#id", "about:blank#id"},
306 {"about:blank#oldfrag", "#id", "about:blank#id"},
307 {"javascript:alert('ab#fg')", "#id", "javascript:alert('ab#id"},
308 {"myscheme:foo?bar#baz?xxx#yyy?zzz", "#id", "myscheme:foo?bar#id"},
309 {"data:foo#bar?xxx#yyy?zzz", "#id", "data:foo#id"},
310 {"mailto:joth@example.com#123", "#id", "mailto:joth@example.com#id"},
311 };
312
313 for (int compat_mode = 0; compat_mode < 2; ++compat_mode) {
314 url_util::SetKURLCompatMode(compat_mode);
315 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kurl_compat_cases); i++) {
316 const ResolveRelativeCase& test_data = kurl_compat_cases[i];
317 url_parse::Parsed base_parsed;
318 url_parse::ParsePathURL(test_data.base, strlen(test_data.base),
319 &base_parsed);
320
321 std::string resolved;
322 url_canon::StdStringCanonOutput output(&resolved);
323 url_parse::Parsed resolved_parsed;
324 bool valid =
325 url_util::ResolveRelative(test_data.base, strlen(test_data.base),
326 base_parsed,
327 test_data.rel, strlen(test_data.rel),
328 NULL, &output, &resolved_parsed);
329 output.Complete();
330
331 if (!compat_mode) {
332 EXPECT_FALSE(valid);
333 } else {
334 EXPECT_TRUE(valid);
335 EXPECT_EQ(test_data.out, resolved) << i;
336 }
337 }
338 }
339 url_util::SetKURLCompatMode(false);
340 }
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