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

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/KURLTest.cpp

Issue 2890143002: Set 'whitespace_removed' correctly when resolving relative URLs. (Closed)
Patch Set: Test. Created 3 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 // Encoding should not NFC-normalize the string. 296 // Encoding should not NFC-normalize the string.
297 // Contain a combining character ('e' + COMBINING OGONEK). 297 // Contain a combining character ('e' + COMBINING OGONEK).
298 String combining(String::FromUTF8("\x65\xCC\xA8")); 298 String combining(String::FromUTF8("\x65\xCC\xA8"));
299 EXPECT_EQ(EncodeWithURLEscapeSequences(combining), "e%CC%A8"); 299 EXPECT_EQ(EncodeWithURLEscapeSequences(combining), "e%CC%A8");
300 // Contain a precomposed character corresponding to |combining|. 300 // Contain a precomposed character corresponding to |combining|.
301 String precomposed(String::FromUTF8("\xC4\x99")); 301 String precomposed(String::FromUTF8("\xC4\x99"));
302 EXPECT_EQ(EncodeWithURLEscapeSequences(precomposed), "%C4%99"); 302 EXPECT_EQ(EncodeWithURLEscapeSequences(precomposed), "%C4%99");
303 } 303 }
304 304
305 TEST(KURLTest, RemoveWhitespace) { 305 TEST(KURLTest, AbsoluteRemoveWhitespace) {
306 struct { 306 struct {
307 const char* input; 307 const char* input;
308 const char* expected; 308 const char* expected;
309 } cases[] = { 309 } cases[] = {
310 {"ht\ntps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 310 {"ht\ntps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
311 {"ht\ttps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 311 {"ht\ttps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
312 {"ht\rtps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 312 {"ht\rtps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
313 {"https://exa\nmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 313 {"https://exa\nmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
314 {"https://exa\tmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 314 {"https://exa\tmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
315 {"https://exa\rmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"}, 315 {"https://exa\rmple.com/yay?boo#foo", "https://example.com/yay?boo#foo"},
(...skipping 10 matching lines...) Expand all
326 326
327 for (const auto& test : cases) { 327 for (const auto& test : cases) {
328 const KURL input(kParsedURLString, test.input); 328 const KURL input(kParsedURLString, test.input);
329 const KURL expected(kParsedURLString, test.expected); 329 const KURL expected(kParsedURLString, test.expected);
330 EXPECT_EQ(input, expected); 330 EXPECT_EQ(input, expected);
331 EXPECT_TRUE(input.WhitespaceRemoved()); 331 EXPECT_TRUE(input.WhitespaceRemoved());
332 EXPECT_FALSE(expected.WhitespaceRemoved()); 332 EXPECT_FALSE(expected.WhitespaceRemoved());
333 } 333 }
334 } 334 }
335 335
336 TEST(KURLTest, RelativeRemoveWhitespace) {
337 struct {
338 const char* base;
339 const char* relative;
340 bool whitespace_removed;
341 } cases[] = {
342 {"http://example.com/", "/path", false},
343 {"http://example.com/", "\n/path", true},
344 {"http://example.com/", "\r/path", true},
345 {"http://example.com/", "\t/path", true},
346 {"http://example.com/", "/pa\nth", true},
347 {"http://example.com/", "/pa\rth", true},
348 {"http://example.com/", "/pa\tth", true},
349 {"http://example.com/", "/path\n", true},
350 {"http://example.com/", "/path\r", true},
351 {"http://example.com/", "/path\t", true},
352 };
353
354 for (const auto& test : cases) {
355 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.relative);
356 const KURL base(kParsedURLString, test.base);
357 const KURL expected(kParsedURLString, "http://example.com/path");
358 const KURL actual(base, test.relative);
359 EXPECT_EQ(actual, expected);
360 EXPECT_EQ(test.whitespace_removed, actual.WhitespaceRemoved());
361 }
362 }
363
336 TEST(KURLTest, ResolveEmpty) { 364 TEST(KURLTest, ResolveEmpty) {
337 KURL empty_base; 365 KURL empty_base;
338 366
339 // WebKit likes to be able to resolve absolute input agains empty base URLs, 367 // WebKit likes to be able to resolve absolute input agains empty base URLs,
340 // which would normally be invalid since the base URL is invalid. 368 // which would normally be invalid since the base URL is invalid.
341 const char kAbs[] = "http://www.google.com/"; 369 const char kAbs[] = "http://www.google.com/";
342 KURL resolve_abs(empty_base, kAbs); 370 KURL resolve_abs(empty_base, kAbs);
343 EXPECT_TRUE(resolve_abs.IsValid()); 371 EXPECT_TRUE(resolve_abs.IsValid());
344 EXPECT_STREQ(kAbs, resolve_abs.GetString().Utf8().data()); 372 EXPECT_STREQ(kAbs, resolve_abs.GetString().Utf8().data());
345 373
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 }; 783 };
756 784
757 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrer_cases); i++) { 785 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrer_cases); i++) {
758 KURL kurl(kParsedURLString, referrer_cases[i].input); 786 KURL kurl(kParsedURLString, referrer_cases[i].input);
759 String referrer = kurl.StrippedForUseAsReferrer(); 787 String referrer = kurl.StrippedForUseAsReferrer();
760 EXPECT_STREQ(referrer_cases[i].output, referrer.Utf8().data()); 788 EXPECT_STREQ(referrer_cases[i].output, referrer.Utf8().data());
761 } 789 }
762 } 790 }
763 791
764 } // namespace blink 792 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/loader/url-strip-cr-lf-tab-expected.txt ('k') | url/url_canon_relative.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698