OLD | NEW |
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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 {"https://example.com/yay?b\roo#foo", "https://example.com/yay?boo#foo"}, | 321 {"https://example.com/yay?b\roo#foo", "https://example.com/yay?boo#foo"}, |
322 {"https://example.com/yay?boo#f\noo", "https://example.com/yay?boo#foo"}, | 322 {"https://example.com/yay?boo#f\noo", "https://example.com/yay?boo#foo"}, |
323 {"https://example.com/yay?boo#f\too", "https://example.com/yay?boo#foo"}, | 323 {"https://example.com/yay?boo#f\too", "https://example.com/yay?boo#foo"}, |
324 {"https://example.com/yay?boo#f\roo", "https://example.com/yay?boo#foo"}, | 324 {"https://example.com/yay?boo#f\roo", "https://example.com/yay?boo#foo"}, |
325 }; | 325 }; |
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()); | |
332 EXPECT_FALSE(expected.WhitespaceRemoved()); | |
333 } | 331 } |
334 } | 332 } |
335 | 333 |
336 TEST(KURLTest, RelativeRemoveWhitespace) { | 334 TEST(KURLTest, RelativeRemoveWhitespace) { |
337 struct { | 335 struct { |
338 const char* base; | 336 const char* base; |
339 const char* relative; | 337 const char* relative; |
340 bool whitespace_removed; | |
341 } cases[] = { | 338 } cases[] = { |
342 {"http://example.com/", "/path", false}, | 339 {"http://example.com/", "/path"}, {"http://example.com/", "\n/path"}, |
343 {"http://example.com/", "\n/path", true}, | 340 {"http://example.com/", "\r/path"}, {"http://example.com/", "\t/path"}, |
344 {"http://example.com/", "\r/path", true}, | 341 {"http://example.com/", "/pa\nth"}, {"http://example.com/", "/pa\rth"}, |
345 {"http://example.com/", "\t/path", true}, | 342 {"http://example.com/", "/pa\tth"}, {"http://example.com/", "/path\n"}, |
346 {"http://example.com/", "/pa\nth", true}, | 343 {"http://example.com/", "/path\r"}, {"http://example.com/", "/path\t"}, |
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 }; | 344 }; |
353 | 345 |
354 for (const auto& test : cases) { | 346 for (const auto& test : cases) { |
355 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.relative); | 347 SCOPED_TRACE(::testing::Message() << test.base << ", " << test.relative); |
356 const KURL base(kParsedURLString, test.base); | 348 const KURL base(kParsedURLString, test.base); |
357 const KURL expected(kParsedURLString, "http://example.com/path"); | 349 const KURL expected(kParsedURLString, "http://example.com/path"); |
358 const KURL actual(base, test.relative); | 350 const KURL actual(base, test.relative); |
359 EXPECT_EQ(actual, expected); | 351 EXPECT_EQ(actual, expected); |
360 EXPECT_EQ(test.whitespace_removed, actual.WhitespaceRemoved()); | |
361 } | 352 } |
362 } | 353 } |
363 | 354 |
| 355 TEST(KURLTest, AbsolutePotentiallyDanglingMarkup) { |
| 356 struct { |
| 357 const char* input; |
| 358 const char* expected; |
| 359 const bool potentially_dangling_markup; |
| 360 } cases[] = { |
| 361 // Just removable whitespace isn't enough: |
| 362 {"ht\ntps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 363 false}, |
| 364 {"ht\ttps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 365 false}, |
| 366 {"ht\rtps://example.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 367 false}, |
| 368 {"https://exa\nmple.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 369 false}, |
| 370 {"https://exa\tmple.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 371 false}, |
| 372 {"https://exa\rmple.com/yay?boo#foo", "https://example.com/yay?boo#foo", |
| 373 false}, |
| 374 {"https://example.com/y\nay?boo#foo", "https://example.com/yay?boo#foo", |
| 375 false}, |
| 376 {"https://example.com/y\tay?boo#foo", "https://example.com/yay?boo#foo", |
| 377 false}, |
| 378 {"https://example.com/y\ray?boo#foo", "https://example.com/yay?boo#foo", |
| 379 false}, |
| 380 {"https://example.com/yay?b\noo#foo", "https://example.com/yay?boo#foo", |
| 381 false}, |
| 382 {"https://example.com/yay?b\too#foo", "https://example.com/yay?boo#foo", |
| 383 false}, |
| 384 {"https://example.com/yay?b\roo#foo", "https://example.com/yay?boo#foo", |
| 385 false}, |
| 386 {"https://example.com/yay?boo#f\noo", "https://example.com/yay?boo#foo", |
| 387 false}, |
| 388 {"https://example.com/yay?boo#f\too", "https://example.com/yay?boo#foo", |
| 389 false}, |
| 390 {"https://example.com/yay?boo#f\roo", "https://example.com/yay?boo#foo", |
| 391 false}, |
| 392 |
| 393 // Likewise, just a brace won't cut it: |
| 394 {"https://example.com/y<ay?boo#foo", "https://example.com/y%3Cay?boo#foo", |
| 395 false}, |
| 396 {"https://example.com/yay?b<oo#foo", "https://example.com/yay?b%3Coo#foo", |
| 397 false}, |
| 398 {"https://example.com/yay?boo#f<oo", "https://example.com/yay?boo#f<oo", |
| 399 false}, |
| 400 |
| 401 // Both, however: |
| 402 {"ht\ntps://example.com/y<ay?boo#foo", |
| 403 "https://example.com/y%3Cay?boo#foo", true}, |
| 404 {"https://e\nxample.com/y<ay?boo#foo", |
| 405 "https://example.com/y%3Cay?boo#foo", true}, |
| 406 {"https://example.com/y<\nay?boo#foo", |
| 407 "https://example.com/y%3Cay?boo#foo", true}, |
| 408 {"https://example.com/y<ay?b\noo#foo", |
| 409 "https://example.com/y%3Cay?boo#foo", true}, |
| 410 {"https://example.com/y<ay?boo#f\noo", |
| 411 "https://example.com/y%3Cay?boo#foo", true}, |
| 412 {"ht\ntps://example.com/yay?b<oo#foo", |
| 413 "https://example.com/yay?b%3Coo#foo", true}, |
| 414 {"https://e\nxample.com/yay?b<oo#foo", |
| 415 "https://example.com/yay?b%3Coo#foo", true}, |
| 416 {"https://example.com/y\nay?b<oo#foo", |
| 417 "https://example.com/yay?b%3Coo#foo", true}, |
| 418 {"https://example.com/yay?b<\noo#foo", |
| 419 "https://example.com/yay?b%3Coo#foo", true}, |
| 420 {"https://example.com/yay?b<oo#f\noo", |
| 421 "https://example.com/yay?b%3Coo#foo", true}, |
| 422 {"ht\ntps://example.com/yay?boo#f<oo", "https://example.com/yay?boo#f<oo", |
| 423 true}, |
| 424 {"https://e\nxample.com/yay?boo#f<oo", "https://example.com/yay?boo#f<oo", |
| 425 true}, |
| 426 {"https://example.com/y\nay?boo#f<oo", "https://example.com/yay?boo#f<oo", |
| 427 true}, |
| 428 {"https://example.com/yay?b\noo#f<oo", "https://example.com/yay?boo#f<oo", |
| 429 true}, |
| 430 {"https://example.com/yay?boo#f<\noo", "https://example.com/yay?boo#f<oo", |
| 431 true}, |
| 432 }; |
| 433 |
| 434 for (const auto& test : cases) { |
| 435 SCOPED_TRACE(::testing::Message() << test.input << ", " << test.expected); |
| 436 const KURL input(KURL(), test.input); |
| 437 const KURL expected(KURL(), test.expected); |
| 438 EXPECT_EQ(input, expected) << input.GetString() << expected.GetString(); |
| 439 EXPECT_EQ(test.potentially_dangling_markup, |
| 440 input.PotentiallyDanglingMarkup()); |
| 441 EXPECT_FALSE(expected.PotentiallyDanglingMarkup()); |
| 442 } |
| 443 } |
| 444 |
364 TEST(KURLTest, ResolveEmpty) { | 445 TEST(KURLTest, ResolveEmpty) { |
365 KURL empty_base; | 446 KURL empty_base; |
366 | 447 |
367 // WebKit likes to be able to resolve absolute input agains empty base URLs, | 448 // WebKit likes to be able to resolve absolute input agains empty base URLs, |
368 // which would normally be invalid since the base URL is invalid. | 449 // which would normally be invalid since the base URL is invalid. |
369 const char kAbs[] = "http://www.google.com/"; | 450 const char kAbs[] = "http://www.google.com/"; |
370 KURL resolve_abs(empty_base, kAbs); | 451 KURL resolve_abs(empty_base, kAbs); |
371 EXPECT_TRUE(resolve_abs.IsValid()); | 452 EXPECT_TRUE(resolve_abs.IsValid()); |
372 EXPECT_STREQ(kAbs, resolve_abs.GetString().Utf8().data()); | 453 EXPECT_STREQ(kAbs, resolve_abs.GetString().Utf8().data()); |
373 | 454 |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 }; | 864 }; |
784 | 865 |
785 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrer_cases); i++) { | 866 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrer_cases); i++) { |
786 KURL kurl(kParsedURLString, referrer_cases[i].input); | 867 KURL kurl(kParsedURLString, referrer_cases[i].input); |
787 String referrer = kurl.StrippedForUseAsReferrer(); | 868 String referrer = kurl.StrippedForUseAsReferrer(); |
788 EXPECT_STREQ(referrer_cases[i].output, referrer.Utf8().data()); | 869 EXPECT_STREQ(referrer_cases[i].output, referrer.Utf8().data()); |
789 } | 870 } |
790 } | 871 } |
791 | 872 |
792 } // namespace blink | 873 } // namespace blink |
OLD | NEW |