| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/base/net_util.h" | 5 #include "components/url_formatter/url_formatter.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/format_macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 18 | 17 |
| 19 using base::ASCIIToUTF16; | |
| 20 using base::WideToUTF16; | |
| 21 | 18 |
| 22 namespace net { | 19 namespace url_formatter { |
| 23 | 20 |
| 24 namespace { | 21 namespace { |
| 25 | 22 |
| 23 using base::WideToUTF16; |
| 24 using base::ASCIIToUTF16; |
| 25 |
| 26 const size_t kNpos = base::string16::npos; | 26 const size_t kNpos = base::string16::npos; |
| 27 | 27 |
| 28 const char* const kLanguages[] = { | 28 const char* const kLanguages[] = { |
| 29 "", "en", "zh-CN", "ja", "ko", | 29 "", "en", "zh-CN", "ja", "ko", |
| 30 "he", "ar", "ru", "el", "fr", | 30 "he", "ar", "ru", "el", "fr", |
| 31 "de", "pt", "sv", "th", "hi", | 31 "de", "pt", "sv", "th", "hi", |
| 32 "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en", | 32 "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en", |
| 33 "zh,ru,en" | 33 "zh,ru,en" |
| 34 }; | 34 }; |
| 35 | 35 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 struct AdjustOffsetCase { | 367 struct AdjustOffsetCase { |
| 368 size_t input_offset; | 368 size_t input_offset; |
| 369 size_t output_offset; | 369 size_t output_offset; |
| 370 }; | 370 }; |
| 371 | 371 |
| 372 struct UrlTestData { | 372 struct UrlTestData { |
| 373 const char* const description; | 373 const char* const description; |
| 374 const char* const input; | 374 const char* const input; |
| 375 const char* const languages; | 375 const char* const languages; |
| 376 FormatUrlTypes format_types; | 376 FormatUrlTypes format_types; |
| 377 UnescapeRule::Type escape_rules; | 377 net::UnescapeRule::Type escape_rules; |
| 378 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily. | 378 const wchar_t* output; // Use |wchar_t| to handle Unicode constants easily. |
| 379 size_t prefix_len; | 379 size_t prefix_len; |
| 380 }; | 380 }; |
| 381 | 381 |
| 382 // A helper for IDN*{Fast,Slow}. | 382 // A helper for IDN*{Fast,Slow}. |
| 383 // Append "::<language list>" to |expected| and |actual| to make it | 383 // Append "::<language list>" to |expected| and |actual| to make it |
| 384 // easy to tell which sub-case fails without debugging. | 384 // easy to tell which sub-case fails without debugging. |
| 385 void AppendLanguagesToOutputs(const char* languages, | 385 void AppendLanguagesToOutputs(const char* languages, |
| 386 base::string16* expected, | 386 base::string16* expected, |
| 387 base::string16* actual) { | 387 base::string16* actual) { |
| 388 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages); | 388 base::string16 to_append = ASCIIToUTF16("::") + ASCIIToUTF16(languages); |
| 389 expected->append(to_append); | 389 expected->append(to_append); |
| 390 actual->append(to_append); | 390 actual->append(to_append); |
| 391 } | 391 } |
| 392 | 392 |
| 393 // A pair of helpers for the FormatUrlWithOffsets() test. | 393 // A pair of helpers for the FormatUrlWithOffsets() test. |
| 394 void VerboseExpect(size_t expected, | 394 void VerboseExpect(size_t expected, |
| 395 size_t actual, | 395 size_t actual, |
| 396 const std::string& original_url, | 396 const std::string& original_url, |
| 397 size_t position, | 397 size_t position, |
| 398 const base::string16& formatted_url) { | 398 const base::string16& formatted_url) { |
| 399 EXPECT_EQ(expected, actual) << "Original URL: " << original_url | 399 EXPECT_EQ(expected, actual) << "Original URL: " << original_url |
| 400 << " (at char " << position << ")\nFormatted URL: " << formatted_url; | 400 << " (at char " << position << ")\nFormatted URL: " << formatted_url; |
| 401 } | 401 } |
| 402 | 402 |
| 403 void CheckAdjustedOffsets(const std::string& url_string, | 403 void CheckAdjustedOffsets(const std::string& url_string, |
| 404 const std::string& languages, | 404 const std::string& languages, |
| 405 FormatUrlTypes format_types, | 405 FormatUrlTypes format_types, |
| 406 UnescapeRule::Type unescape_rules, | 406 net::UnescapeRule::Type unescape_rules, |
| 407 const size_t* output_offsets) { | 407 const size_t* output_offsets) { |
| 408 GURL url(url_string); | 408 GURL url(url_string); |
| 409 size_t url_length = url_string.length(); | 409 size_t url_length = url_string.length(); |
| 410 std::vector<size_t> offsets; | 410 std::vector<size_t> offsets; |
| 411 for (size_t i = 0; i <= url_length + 1; ++i) | 411 for (size_t i = 0; i <= url_length + 1; ++i) |
| 412 offsets.push_back(i); | 412 offsets.push_back(i); |
| 413 offsets.push_back(500000); // Something larger than any input length. | 413 offsets.push_back(500000); // Something larger than any input length. |
| 414 offsets.push_back(std::string::npos); | 414 offsets.push_back(std::string::npos); |
| 415 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, | 415 base::string16 formatted_url = FormatUrlWithOffsets(url, languages, |
| 416 format_types, unescape_rules, NULL, NULL, &offsets); | 416 format_types, unescape_rules, NULL, NULL, &offsets); |
| 417 for (size_t i = 0; i < url_length; ++i) | 417 for (size_t i = 0; i < url_length; ++i) |
| 418 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url); | 418 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url); |
| 419 VerboseExpect(formatted_url.length(), offsets[url_length], url_string, | 419 VerboseExpect(formatted_url.length(), offsets[url_length], url_string, |
| 420 url_length, formatted_url); | 420 url_length, formatted_url); |
| 421 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string, | 421 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string, |
| 422 500000, formatted_url); | 422 500000, formatted_url); |
| 423 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string, | 423 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string, |
| 424 std::string::npos, formatted_url); | 424 std::string::npos, formatted_url); |
| 425 } | 425 } |
| 426 | 426 |
| 427 } // anonymous namespace | 427 TEST(UrlFormatterTest, IDNToUnicodeFast) { |
| 428 | |
| 429 TEST(NetUtilTest, IDNToUnicodeFast) { | |
| 430 for (size_t i = 0; i < arraysize(idn_cases); i++) { | 428 for (size_t i = 0; i < arraysize(idn_cases); i++) { |
| 431 for (size_t j = 0; j < arraysize(kLanguages); j++) { | 429 for (size_t j = 0; j < arraysize(kLanguages); j++) { |
| 432 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow | 430 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow |
| 433 if (j == 3 || j == 17 || j == 18) | 431 if (j == 3 || j == 17 || j == 18) |
| 434 continue; | 432 continue; |
| 435 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); | 433 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); |
| 436 base::string16 expected(idn_cases[i].unicode_allowed[j] ? | 434 base::string16 expected(idn_cases[i].unicode_allowed[j] ? |
| 437 WideToUTF16(idn_cases[i].unicode_output) : | 435 WideToUTF16(idn_cases[i].unicode_output) : |
| 438 ASCIIToUTF16(idn_cases[i].input)); | 436 ASCIIToUTF16(idn_cases[i].input)); |
| 439 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); | 437 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); |
| 440 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input | 438 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input |
| 441 << "\", languages: \"" << kLanguages[j] | 439 << "\", languages: \"" << kLanguages[j] |
| 442 << "\""; | 440 << "\""; |
| 443 } | 441 } |
| 444 } | 442 } |
| 445 } | 443 } |
| 446 | 444 |
| 447 TEST(NetUtilTest, IDNToUnicodeSlow) { | 445 TEST(UrlFormatterTest, IDNToUnicodeSlow) { |
| 448 for (size_t i = 0; i < arraysize(idn_cases); i++) { | 446 for (size_t i = 0; i < arraysize(idn_cases); i++) { |
| 449 for (size_t j = 0; j < arraysize(kLanguages); j++) { | 447 for (size_t j = 0; j < arraysize(kLanguages); j++) { |
| 450 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast | 448 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast |
| 451 if (!(j == 3 || j == 17 || j == 18)) | 449 if (!(j == 3 || j == 17 || j == 18)) |
| 452 continue; | 450 continue; |
| 453 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); | 451 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); |
| 454 base::string16 expected(idn_cases[i].unicode_allowed[j] ? | 452 base::string16 expected(idn_cases[i].unicode_allowed[j] ? |
| 455 WideToUTF16(idn_cases[i].unicode_output) : | 453 WideToUTF16(idn_cases[i].unicode_output) : |
| 456 ASCIIToUTF16(idn_cases[i].input)); | 454 ASCIIToUTF16(idn_cases[i].input)); |
| 457 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); | 455 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); |
| 458 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input | 456 EXPECT_EQ(expected, output) << "input: \"" << idn_cases[i].input |
| 459 << "\", languages: \"" << kLanguages[j] | 457 << "\", languages: \"" << kLanguages[j] |
| 460 << "\""; | 458 << "\""; |
| 461 } | 459 } |
| 462 } | 460 } |
| 463 } | 461 } |
| 464 | 462 |
| 465 // ulocdata_getExemplarSet may fail with some locales (currently bn, gu, and | 463 // ulocdata_getExemplarSet may fail with some locales (currently bn, gu, and |
| 466 // te), which was causing a crash (See http://crbug.com/510551). This may be an | 464 // te), which was causing a crash (See http://crbug.com/510551). This may be an |
| 467 // icu bug, but regardless, that should not cause a crash. | 465 // icu bug, but regardless, that should not cause a crash. |
| 468 TEST(NetUtilTest, IDNToUnicodeNeverCrashes) { | 466 TEST(UrlFormatterTest, IDNToUnicodeNeverCrashes) { |
| 469 for (char c1 = 'a'; c1 <= 'z'; c1++) { | 467 for (char c1 = 'a'; c1 <= 'z'; c1++) { |
| 470 for (char c2 = 'a'; c2 <= 'z'; c2++) { | 468 for (char c2 = 'a'; c2 <= 'z'; c2++) { |
| 471 std::string lang = base::StringPrintf("%c%c", c1, c2); | 469 std::string lang = base::StringPrintf("%c%c", c1, c2); |
| 472 base::string16 output(IDNToUnicode("xn--74h", lang)); | 470 base::string16 output(IDNToUnicode("xn--74h", lang)); |
| 473 } | 471 } |
| 474 } | 472 } |
| 475 } | 473 } |
| 476 | 474 |
| 477 TEST(NetUtilTest, StripWWW) { | 475 TEST(UrlFormatterTest, FormatUrl) { |
| 478 EXPECT_EQ(base::string16(), StripWWW(base::string16())); | |
| 479 EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www."))); | |
| 480 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah"))); | |
| 481 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah"))); | |
| 482 } | |
| 483 | |
| 484 // This is currently a windows specific function. | |
| 485 #if defined(OS_WIN) | |
| 486 namespace { | |
| 487 | |
| 488 struct GetDirectoryListingEntryCase { | |
| 489 const wchar_t* name; | |
| 490 const char* const raw_bytes; | |
| 491 bool is_dir; | |
| 492 int64_t filesize; | |
| 493 base::Time time; | |
| 494 const char* const expected; | |
| 495 }; | |
| 496 | |
| 497 } // namespace | |
| 498 | |
| 499 TEST(NetUtilTest, GetDirectoryListingEntry) { | |
| 500 const GetDirectoryListingEntryCase test_cases[] = { | |
| 501 {L"Foo", | |
| 502 "", | |
| 503 false, | |
| 504 10000, | |
| 505 base::Time(), | |
| 506 "<script>addRow(\"Foo\",\"Foo\",0,\"9.8 kB\",\"\");</script>\n"}, | |
| 507 {L"quo\"tes", | |
| 508 "", | |
| 509 false, | |
| 510 10000, | |
| 511 base::Time(), | |
| 512 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" | |
| 513 "\n"}, | |
| 514 {L"quo\"tes", | |
| 515 "quo\"tes", | |
| 516 false, | |
| 517 10000, | |
| 518 base::Time(), | |
| 519 "<script>addRow(\"quo\\\"tes\",\"quo%22tes\",0,\"9.8 kB\",\"\");</script>" | |
| 520 "\n"}, | |
| 521 // U+D55C0 U+AE00. raw_bytes is empty (either a local file with | |
| 522 // UTF-8/UTF-16 encoding or a remote file on an ftp server using UTF-8 | |
| 523 {L"\xD55C\xAE00.txt", | |
| 524 "", | |
| 525 false, | |
| 526 10000, | |
| 527 base::Time(), | |
| 528 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\"," | |
| 529 "\"%ED%95%9C%EA%B8%80.txt\",0,\"9.8 kB\",\"\");</script>\n"}, | |
| 530 // U+D55C0 U+AE00. raw_bytes is the corresponding EUC-KR sequence: | |
| 531 // a local or remote file in EUC-KR. | |
| 532 {L"\xD55C\xAE00.txt", | |
| 533 "\xC7\xD1\xB1\xDB.txt", | |
| 534 false, | |
| 535 10000, | |
| 536 base::Time(), | |
| 537 "<script>addRow(\"\xED\x95\x9C\xEA\xB8\x80.txt\",\"%C7%D1%B1%DB.txt\"" | |
| 538 ",0,\"9.8 kB\",\"\");</script>\n"}, | |
| 539 }; | |
| 540 | |
| 541 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 542 const std::string results = GetDirectoryListingEntry( | |
| 543 WideToUTF16(test_cases[i].name), | |
| 544 test_cases[i].raw_bytes, | |
| 545 test_cases[i].is_dir, | |
| 546 test_cases[i].filesize, | |
| 547 test_cases[i].time); | |
| 548 EXPECT_EQ(test_cases[i].expected, results); | |
| 549 } | |
| 550 } | |
| 551 | |
| 552 #endif | |
| 553 | |
| 554 TEST(NetUtilTest, FormatUrl) { | |
| 555 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword; | 476 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword; |
| 556 const UrlTestData tests[] = { | 477 const UrlTestData tests[] = { |
| 557 {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0}, | 478 {"Empty URL", "", "", default_format_type, net::UnescapeRule::NORMAL, L"", |
| 479 0}, |
| 558 | 480 |
| 559 {"Simple URL", | 481 {"Simple URL", "http://www.google.com/", "", default_format_type, |
| 560 "http://www.google.com/", "", default_format_type, UnescapeRule::NORMAL, | 482 net::UnescapeRule::NORMAL, L"http://www.google.com/", 7}, |
| 561 L"http://www.google.com/", 7}, | |
| 562 | 483 |
| 563 {"With a port number and a reference", | 484 {"With a port number and a reference", |
| 564 "http://www.google.com:8080/#\xE3\x82\xB0", "", default_format_type, | 485 "http://www.google.com:8080/#\xE3\x82\xB0", "", default_format_type, |
| 565 UnescapeRule::NORMAL, | 486 net::UnescapeRule::NORMAL, L"http://www.google.com:8080/#\x30B0", 7}, |
| 566 L"http://www.google.com:8080/#\x30B0", 7}, | |
| 567 | 487 |
| 568 // -------- IDN tests -------- | 488 // -------- IDN tests -------- |
| 569 {"Japanese IDN with ja", | 489 {"Japanese IDN with ja", "http://xn--l8jvb1ey91xtjb.jp", "ja", |
| 570 "http://xn--l8jvb1ey91xtjb.jp", "ja", default_format_type, | 490 default_format_type, net::UnescapeRule::NORMAL, |
| 571 UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, | 491 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, |
| 572 | 492 |
| 573 {"Japanese IDN with en", | 493 {"Japanese IDN with en", "http://xn--l8jvb1ey91xtjb.jp", "en", |
| 574 "http://xn--l8jvb1ey91xtjb.jp", "en", default_format_type, | 494 default_format_type, net::UnescapeRule::NORMAL, |
| 575 UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7}, | 495 L"http://xn--l8jvb1ey91xtjb.jp/", 7}, |
| 576 | 496 |
| 577 {"Japanese IDN without any languages", | 497 {"Japanese IDN without any languages", "http://xn--l8jvb1ey91xtjb.jp", "", |
| 578 "http://xn--l8jvb1ey91xtjb.jp", "", default_format_type, | 498 default_format_type, net::UnescapeRule::NORMAL, |
| 579 UnescapeRule::NORMAL, | 499 // Single script is safe for empty languages. |
| 580 // Single script is safe for empty languages. | 500 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, |
| 581 L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7}, | |
| 582 | 501 |
| 583 {"mailto: with Japanese IDN", | 502 {"mailto: with Japanese IDN", "mailto:foo@xn--l8jvb1ey91xtjb.jp", "ja", |
| 584 "mailto:foo@xn--l8jvb1ey91xtjb.jp", "ja", default_format_type, | 503 default_format_type, net::UnescapeRule::NORMAL, |
| 585 UnescapeRule::NORMAL, | 504 // GURL doesn't assume an email address's domain part as a host name. |
| 586 // GURL doesn't assume an email address's domain part as a host name. | 505 L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7}, |
| 587 L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7}, | |
| 588 | 506 |
| 589 {"file: with Japanese IDN", | 507 {"file: with Japanese IDN", "file://xn--l8jvb1ey91xtjb.jp/config.sys", |
| 590 "file://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type, | 508 "ja", default_format_type, net::UnescapeRule::NORMAL, |
| 591 UnescapeRule::NORMAL, | 509 L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7}, |
| 592 L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7}, | |
| 593 | 510 |
| 594 {"ftp: with Japanese IDN", | 511 {"ftp: with Japanese IDN", "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", |
| 595 "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", "ja", default_format_type, | 512 default_format_type, net::UnescapeRule::NORMAL, |
| 596 UnescapeRule::NORMAL, | 513 L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6}, |
| 597 L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6}, | |
| 598 | 514 |
| 599 // -------- omit_username_password flag tests -------- | 515 // -------- omit_username_password flag tests -------- |
| 600 {"With username and password, omit_username_password=false", | 516 {"With username and password, omit_username_password=false", |
| 601 "http://user:passwd@example.com/foo", "", | 517 "http://user:passwd@example.com/foo", "", kFormatUrlOmitNothing, |
| 602 kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 518 net::UnescapeRule::NORMAL, L"http://user:passwd@example.com/foo", 19}, |
| 603 L"http://user:passwd@example.com/foo", 19}, | |
| 604 | 519 |
| 605 {"With username and password, omit_username_password=true", | 520 {"With username and password, omit_username_password=true", |
| 606 "http://user:passwd@example.com/foo", "", default_format_type, | 521 "http://user:passwd@example.com/foo", "", default_format_type, |
| 607 UnescapeRule::NORMAL, L"http://example.com/foo", 7}, | 522 net::UnescapeRule::NORMAL, L"http://example.com/foo", 7}, |
| 608 | 523 |
| 609 {"With username and no password", | 524 {"With username and no password", "http://user@example.com/foo", "", |
| 610 "http://user@example.com/foo", "", default_format_type, | 525 default_format_type, net::UnescapeRule::NORMAL, |
| 611 UnescapeRule::NORMAL, L"http://example.com/foo", 7}, | 526 L"http://example.com/foo", 7}, |
| 612 | 527 |
| 613 {"Just '@' without username and password", | 528 {"Just '@' without username and password", "http://@example.com/foo", "", |
| 614 "http://@example.com/foo", "", default_format_type, UnescapeRule::NORMAL, | 529 default_format_type, net::UnescapeRule::NORMAL, |
| 615 L"http://example.com/foo", 7}, | 530 L"http://example.com/foo", 7}, |
| 616 | 531 |
| 617 // GURL doesn't think local-part of an email address is username for URL. | 532 // GURL doesn't think local-part of an email address is username for URL. |
| 618 {"mailto:, omit_username_password=true", | 533 {"mailto:, omit_username_password=true", "mailto:foo@example.com", "", |
| 619 "mailto:foo@example.com", "", default_format_type, UnescapeRule::NORMAL, | 534 default_format_type, net::UnescapeRule::NORMAL, |
| 620 L"mailto:foo@example.com", 7}, | 535 L"mailto:foo@example.com", 7}, |
| 621 | 536 |
| 622 // -------- unescape flag tests -------- | 537 // -------- unescape flag tests -------- |
| 623 {"Do not unescape", | 538 {"Do not unescape", |
| 624 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" | 539 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" |
| 625 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" | 540 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" |
| 626 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type, | 541 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", |
| 627 UnescapeRule::NONE, | 542 "en", default_format_type, net::UnescapeRule::NONE, |
| 628 // GURL parses %-encoded hostnames into Punycode. | 543 // GURL parses %-encoded hostnames into Punycode. |
| 629 L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" | 544 L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" |
| 630 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 7}, | 545 L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", |
| 546 7}, |
| 631 | 547 |
| 632 {"Unescape normally", | 548 {"Unescape normally", |
| 633 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" | 549 "http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/" |
| 634 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" | 550 "%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB" |
| 635 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", "en", default_format_type, | 551 "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", |
| 636 UnescapeRule::NORMAL, | 552 "en", default_format_type, net::UnescapeRule::NORMAL, |
| 637 L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB" | 553 L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB" |
| 638 L"?q=\x30B0\x30FC\x30B0\x30EB", 7}, | 554 L"?q=\x30B0\x30FC\x30B0\x30EB", |
| 555 7}, |
| 639 | 556 |
| 640 {"Unescape normally with BiDi control character", | 557 {"Unescape normally with BiDi control character", |
| 641 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", "en", default_format_type, | 558 "http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", "en", |
| 642 UnescapeRule::NORMAL, L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7}, | 559 default_format_type, net::UnescapeRule::NORMAL, |
| 560 L"http://example.com/%E2%80%AEabc?q=%E2%80%8Fxy", 7}, |
| 643 | 561 |
| 644 {"Unescape normally including unescape spaces", | 562 {"Unescape normally including unescape spaces", |
| 645 "http://www.google.com/search?q=Hello%20World", "en", default_format_type, | 563 "http://www.google.com/search?q=Hello%20World", "en", |
| 646 UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7}, | 564 default_format_type, net::UnescapeRule::SPACES, |
| 565 L"http://www.google.com/search?q=Hello World", 7}, |
| 647 | 566 |
| 648 /* | 567 /* |
| 649 {"unescape=true with some special characters", | 568 {"unescape=true with some special characters", |
| 650 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "", | 569 "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", "", |
| 651 kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 570 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, |
| 652 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25}, | 571 L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25}, |
| 653 */ | 572 */ |
| 654 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...". | 573 // Disabled: the resultant URL becomes "...user%253A:%2540passwd...". |
| 655 | 574 |
| 656 // -------- omit http: -------- | 575 // -------- omit http: -------- |
| 657 {"omit http with user name", | 576 {"omit http with user name", "http://user@example.com/foo", "", |
| 658 "http://user@example.com/foo", "", kFormatUrlOmitAll, | 577 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"example.com/foo", 0}, |
| 659 UnescapeRule::NORMAL, L"example.com/foo", 0}, | |
| 660 | 578 |
| 661 {"omit http", | 579 {"omit http", "http://www.google.com/", "en", kFormatUrlOmitHTTP, |
| 662 "http://www.google.com/", "en", kFormatUrlOmitHTTP, | 580 net::UnescapeRule::NORMAL, L"www.google.com/", 0}, |
| 663 UnescapeRule::NORMAL, L"www.google.com/", | |
| 664 0}, | |
| 665 | 581 |
| 666 {"omit http with https", | 582 {"omit http with https", "https://www.google.com/", "en", |
| 667 "https://www.google.com/", "en", kFormatUrlOmitHTTP, | 583 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, |
| 668 UnescapeRule::NORMAL, L"https://www.google.com/", | 584 L"https://www.google.com/", 8}, |
| 669 8}, | |
| 670 | 585 |
| 671 {"omit http starts with ftp.", | 586 {"omit http starts with ftp.", "http://ftp.google.com/", "en", |
| 672 "http://ftp.google.com/", "en", kFormatUrlOmitHTTP, | 587 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, L"http://ftp.google.com/", |
| 673 UnescapeRule::NORMAL, L"http://ftp.google.com/", | 588 7}, |
| 674 7}, | |
| 675 | 589 |
| 676 // -------- omit trailing slash on bare hostname -------- | 590 // -------- omit trailing slash on bare hostname -------- |
| 677 {"omit slash when it's the entire path", | 591 {"omit slash when it's the entire path", "http://www.google.com/", "en", |
| 678 "http://www.google.com/", "en", | 592 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| 679 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, | 593 L"http://www.google.com", 7}, |
| 680 L"http://www.google.com", 7}, | 594 {"omit slash when there's a ref", "http://www.google.com/#ref", "en", |
| 681 {"omit slash when there's a ref", | 595 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| 682 "http://www.google.com/#ref", "en", | 596 L"http://www.google.com/#ref", 7}, |
| 683 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, | 597 {"omit slash when there's a query", "http://www.google.com/?", "en", |
| 684 L"http://www.google.com/#ref", 7}, | 598 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| 685 {"omit slash when there's a query", | 599 L"http://www.google.com/?", 7}, |
| 686 "http://www.google.com/?", "en", | 600 {"omit slash when it's not the entire path", "http://www.google.com/foo", |
| 687 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, | 601 "en", kFormatUrlOmitTrailingSlashOnBareHostname, |
| 688 L"http://www.google.com/?", 7}, | 602 net::UnescapeRule::NORMAL, L"http://www.google.com/foo", 7}, |
| 689 {"omit slash when it's not the entire path", | 603 {"omit slash for nonstandard URLs", "data:/", "en", |
| 690 "http://www.google.com/foo", "en", | 604 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| 691 kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, | 605 L"data:/", 5}, |
| 692 L"http://www.google.com/foo", 7}, | 606 {"omit slash for file URLs", "file:///", "en", |
| 693 {"omit slash for nonstandard URLs", | 607 kFormatUrlOmitTrailingSlashOnBareHostname, net::UnescapeRule::NORMAL, |
| 694 "data:/", "en", kFormatUrlOmitTrailingSlashOnBareHostname, | 608 L"file:///", 7}, |
| 695 UnescapeRule::NORMAL, L"data:/", 5}, | |
| 696 {"omit slash for file URLs", | |
| 697 "file:///", "en", kFormatUrlOmitTrailingSlashOnBareHostname, | |
| 698 UnescapeRule::NORMAL, L"file:///", 7}, | |
| 699 | 609 |
| 700 // -------- view-source: -------- | 610 // -------- view-source: -------- |
| 701 {"view-source", | 611 {"view-source", "view-source:http://xn--qcka1pmc.jp/", "ja", |
| 702 "view-source:http://xn--qcka1pmc.jp/", "ja", default_format_type, | 612 default_format_type, net::UnescapeRule::NORMAL, |
| 703 UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", | 613 L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 19}, |
| 704 19}, | |
| 705 | 614 |
| 706 {"view-source of view-source", | 615 {"view-source of view-source", |
| 707 "view-source:view-source:http://xn--qcka1pmc.jp/", "ja", | 616 "view-source:view-source:http://xn--qcka1pmc.jp/", "ja", |
| 708 default_format_type, UnescapeRule::NORMAL, | 617 default_format_type, net::UnescapeRule::NORMAL, |
| 709 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12}, | 618 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12}, |
| 710 | 619 |
| 711 // view-source should omit http and trailing slash where non-view-source | 620 // view-source should omit http and trailing slash where non-view-source |
| 712 // would. | 621 // would. |
| 713 {"view-source omit http", | 622 {"view-source omit http", "view-source:http://a.b/c", "en", |
| 714 "view-source:http://a.b/c", "en", kFormatUrlOmitAll, | 623 kFormatUrlOmitAll, net::UnescapeRule::NORMAL, L"view-source:a.b/c", 12}, |
| 715 UnescapeRule::NORMAL, L"view-source:a.b/c", | 624 {"view-source omit http starts with ftp.", "view-source:http://ftp.b/c", |
| 716 12}, | 625 "en", kFormatUrlOmitAll, net::UnescapeRule::NORMAL, |
| 717 {"view-source omit http starts with ftp.", | 626 L"view-source:http://ftp.b/c", 19}, |
| 718 "view-source:http://ftp.b/c", "en", kFormatUrlOmitAll, | 627 {"view-source omit slash when it's the entire path", |
| 719 UnescapeRule::NORMAL, L"view-source:http://ftp.b/c", | 628 "view-source:http://a.b/", "en", kFormatUrlOmitAll, |
| 720 19}, | 629 net::UnescapeRule::NORMAL, L"view-source:a.b", 12}, |
| 721 {"view-source omit slash when it's the entire path", | |
| 722 "view-source:http://a.b/", "en", kFormatUrlOmitAll, | |
| 723 UnescapeRule::NORMAL, L"view-source:a.b", | |
| 724 12}, | |
| 725 }; | 630 }; |
| 726 | 631 |
| 727 for (size_t i = 0; i < arraysize(tests); ++i) { | 632 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 728 size_t prefix_len; | 633 size_t prefix_len; |
| 729 base::string16 formatted = FormatUrl( | 634 base::string16 formatted = FormatUrl( |
| 730 GURL(tests[i].input), tests[i].languages, tests[i].format_types, | 635 GURL(tests[i].input), tests[i].languages, tests[i].format_types, |
| 731 tests[i].escape_rules, NULL, &prefix_len, NULL); | 636 tests[i].escape_rules, NULL, &prefix_len, NULL); |
| 732 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; | 637 EXPECT_EQ(WideToUTF16(tests[i].output), formatted) << tests[i].description; |
| 733 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; | 638 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; |
| 734 } | 639 } |
| 735 } | 640 } |
| 736 | 641 |
| 737 TEST(NetUtilTest, FormatUrlParsed) { | 642 TEST(UrlFormatterTest, FormatUrlParsed) { |
| 738 // No unescape case. | 643 // No unescape case. |
| 739 url::Parsed parsed; | 644 url::Parsed parsed; |
| 740 base::string16 formatted = FormatUrl( | 645 base::string16 formatted = |
| 741 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" | 646 FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" |
| 742 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), | 647 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), |
| 743 "ja", kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL, | 648 "ja", kFormatUrlOmitNothing, net::UnescapeRule::NONE, &parsed, |
| 744 NULL); | 649 NULL, NULL); |
| 745 EXPECT_EQ(WideToUTF16( | 650 EXPECT_EQ(WideToUTF16( |
| 746 L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080" | 651 L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080" |
| 747 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"), formatted); | 652 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0"), formatted); |
| 748 EXPECT_EQ(WideToUTF16(L"%E3%82%B0"), | 653 EXPECT_EQ(WideToUTF16(L"%E3%82%B0"), |
| 749 formatted.substr(parsed.username.begin, parsed.username.len)); | 654 formatted.substr(parsed.username.begin, parsed.username.len)); |
| 750 EXPECT_EQ(WideToUTF16(L"%E3%83%BC"), | 655 EXPECT_EQ(WideToUTF16(L"%E3%83%BC"), |
| 751 formatted.substr(parsed.password.begin, parsed.password.len)); | 656 formatted.substr(parsed.password.begin, parsed.password.len)); |
| 752 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), | 657 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), |
| 753 formatted.substr(parsed.host.begin, parsed.host.len)); | 658 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 754 EXPECT_EQ(WideToUTF16(L"8080"), | 659 EXPECT_EQ(WideToUTF16(L"8080"), |
| 755 formatted.substr(parsed.port.begin, parsed.port.len)); | 660 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 756 EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"), | 661 EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"), |
| 757 formatted.substr(parsed.path.begin, parsed.path.len)); | 662 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 758 EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"), | 663 EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"), |
| 759 formatted.substr(parsed.query.begin, parsed.query.len)); | 664 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 760 EXPECT_EQ(WideToUTF16(L"\x30B0"), | 665 EXPECT_EQ(WideToUTF16(L"\x30B0"), |
| 761 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 666 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 762 | 667 |
| 763 // Unescape case. | 668 // Unescape case. |
| 764 formatted = FormatUrl( | 669 formatted = |
| 765 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" | 670 FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" |
| 766 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), | 671 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), |
| 767 "ja", kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL, | 672 "ja", kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, &parsed, |
| 768 NULL); | 673 NULL, NULL); |
| 769 EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080" | 674 EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080" |
| 770 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); | 675 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); |
| 771 EXPECT_EQ(WideToUTF16(L"\x30B0"), | 676 EXPECT_EQ(WideToUTF16(L"\x30B0"), |
| 772 formatted.substr(parsed.username.begin, parsed.username.len)); | 677 formatted.substr(parsed.username.begin, parsed.username.len)); |
| 773 EXPECT_EQ(WideToUTF16(L"\x30FC"), | 678 EXPECT_EQ(WideToUTF16(L"\x30FC"), |
| 774 formatted.substr(parsed.password.begin, parsed.password.len)); | 679 formatted.substr(parsed.password.begin, parsed.password.len)); |
| 775 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), | 680 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), |
| 776 formatted.substr(parsed.host.begin, parsed.host.len)); | 681 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 777 EXPECT_EQ(WideToUTF16(L"8080"), | 682 EXPECT_EQ(WideToUTF16(L"8080"), |
| 778 formatted.substr(parsed.port.begin, parsed.port.len)); | 683 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 779 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), | 684 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), |
| 780 formatted.substr(parsed.path.begin, parsed.path.len)); | 685 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 781 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), | 686 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), |
| 782 formatted.substr(parsed.query.begin, parsed.query.len)); | 687 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 783 EXPECT_EQ(WideToUTF16(L"\x30B0"), | 688 EXPECT_EQ(WideToUTF16(L"\x30B0"), |
| 784 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 689 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 785 | 690 |
| 786 // Omit_username_password + unescape case. | 691 // Omit_username_password + unescape case. |
| 787 formatted = FormatUrl( | 692 formatted = |
| 788 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" | 693 FormatUrl(GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" |
| 789 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), | 694 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), |
| 790 "ja", kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed, | 695 "ja", kFormatUrlOmitUsernamePassword, net::UnescapeRule::NORMAL, |
| 791 NULL, NULL); | 696 &parsed, NULL, NULL); |
| 792 EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" | 697 EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" |
| 793 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); | 698 L"/\x30B0/?q=\x30B0#\x30B0"), formatted); |
| 794 EXPECT_FALSE(parsed.username.is_valid()); | 699 EXPECT_FALSE(parsed.username.is_valid()); |
| 795 EXPECT_FALSE(parsed.password.is_valid()); | 700 EXPECT_FALSE(parsed.password.is_valid()); |
| 796 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), | 701 EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), |
| 797 formatted.substr(parsed.host.begin, parsed.host.len)); | 702 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 798 EXPECT_EQ(WideToUTF16(L"8080"), | 703 EXPECT_EQ(WideToUTF16(L"8080"), |
| 799 formatted.substr(parsed.port.begin, parsed.port.len)); | 704 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 800 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), | 705 EXPECT_EQ(WideToUTF16(L"/\x30B0/"), |
| 801 formatted.substr(parsed.path.begin, parsed.path.len)); | 706 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 802 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), | 707 EXPECT_EQ(WideToUTF16(L"q=\x30B0"), |
| 803 formatted.substr(parsed.query.begin, parsed.query.len)); | 708 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 804 EXPECT_EQ(WideToUTF16(L"\x30B0"), | 709 EXPECT_EQ(WideToUTF16(L"\x30B0"), |
| 805 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 710 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 806 | 711 |
| 807 // View-source case. | 712 // View-source case. |
| 808 formatted = | 713 formatted = |
| 809 FormatUrl(GURL("view-source:http://user:passwd@host:81/path?query#ref"), | 714 FormatUrl(GURL("view-source:http://user:passwd@host:81/path?query#ref"), |
| 810 std::string(), | 715 std::string(), kFormatUrlOmitUsernamePassword, |
| 811 kFormatUrlOmitUsernamePassword, | 716 net::UnescapeRule::NORMAL, &parsed, NULL, NULL); |
| 812 UnescapeRule::NORMAL, | |
| 813 &parsed, | |
| 814 NULL, | |
| 815 NULL); | |
| 816 EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"), | 717 EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"), |
| 817 formatted); | 718 formatted); |
| 818 EXPECT_EQ(WideToUTF16(L"view-source:http"), | 719 EXPECT_EQ(WideToUTF16(L"view-source:http"), |
| 819 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); | 720 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); |
| 820 EXPECT_FALSE(parsed.username.is_valid()); | 721 EXPECT_FALSE(parsed.username.is_valid()); |
| 821 EXPECT_FALSE(parsed.password.is_valid()); | 722 EXPECT_FALSE(parsed.password.is_valid()); |
| 822 EXPECT_EQ(WideToUTF16(L"host"), | 723 EXPECT_EQ(WideToUTF16(L"host"), |
| 823 formatted.substr(parsed.host.begin, parsed.host.len)); | 724 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 824 EXPECT_EQ(WideToUTF16(L"81"), | 725 EXPECT_EQ(WideToUTF16(L"81"), |
| 825 formatted.substr(parsed.port.begin, parsed.port.len)); | 726 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 826 EXPECT_EQ(WideToUTF16(L"/path"), | 727 EXPECT_EQ(WideToUTF16(L"/path"), |
| 827 formatted.substr(parsed.path.begin, parsed.path.len)); | 728 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 828 EXPECT_EQ(WideToUTF16(L"query"), | 729 EXPECT_EQ(WideToUTF16(L"query"), |
| 829 formatted.substr(parsed.query.begin, parsed.query.len)); | 730 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 830 EXPECT_EQ(WideToUTF16(L"ref"), | 731 EXPECT_EQ(WideToUTF16(L"ref"), |
| 831 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 732 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 832 | 733 |
| 833 // omit http case. | 734 // omit http case. |
| 834 formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"), | 735 formatted = FormatUrl(GURL("http://host:8000/a?b=c#d"), std::string(), |
| 835 std::string(), | 736 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, &parsed, |
| 836 kFormatUrlOmitHTTP, | 737 NULL, NULL); |
| 837 UnescapeRule::NORMAL, | |
| 838 &parsed, | |
| 839 NULL, | |
| 840 NULL); | |
| 841 EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted); | 738 EXPECT_EQ(WideToUTF16(L"host:8000/a?b=c#d"), formatted); |
| 842 EXPECT_FALSE(parsed.scheme.is_valid()); | 739 EXPECT_FALSE(parsed.scheme.is_valid()); |
| 843 EXPECT_FALSE(parsed.username.is_valid()); | 740 EXPECT_FALSE(parsed.username.is_valid()); |
| 844 EXPECT_FALSE(parsed.password.is_valid()); | 741 EXPECT_FALSE(parsed.password.is_valid()); |
| 845 EXPECT_EQ(WideToUTF16(L"host"), | 742 EXPECT_EQ(WideToUTF16(L"host"), |
| 846 formatted.substr(parsed.host.begin, parsed.host.len)); | 743 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 847 EXPECT_EQ(WideToUTF16(L"8000"), | 744 EXPECT_EQ(WideToUTF16(L"8000"), |
| 848 formatted.substr(parsed.port.begin, parsed.port.len)); | 745 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 849 EXPECT_EQ(WideToUTF16(L"/a"), | 746 EXPECT_EQ(WideToUTF16(L"/a"), |
| 850 formatted.substr(parsed.path.begin, parsed.path.len)); | 747 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 851 EXPECT_EQ(WideToUTF16(L"b=c"), | 748 EXPECT_EQ(WideToUTF16(L"b=c"), |
| 852 formatted.substr(parsed.query.begin, parsed.query.len)); | 749 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 853 EXPECT_EQ(WideToUTF16(L"d"), | 750 EXPECT_EQ(WideToUTF16(L"d"), |
| 854 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 751 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 855 | 752 |
| 856 // omit http starts with ftp case. | 753 // omit http starts with ftp case. |
| 857 formatted = FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"), | 754 formatted = FormatUrl(GURL("http://ftp.host:8000/a?b=c#d"), std::string(), |
| 858 std::string(), | 755 kFormatUrlOmitHTTP, net::UnescapeRule::NORMAL, &parsed, |
| 859 kFormatUrlOmitHTTP, | 756 NULL, NULL); |
| 860 UnescapeRule::NORMAL, | |
| 861 &parsed, | |
| 862 NULL, | |
| 863 NULL); | |
| 864 EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted); | 757 EXPECT_EQ(WideToUTF16(L"http://ftp.host:8000/a?b=c#d"), formatted); |
| 865 EXPECT_TRUE(parsed.scheme.is_valid()); | 758 EXPECT_TRUE(parsed.scheme.is_valid()); |
| 866 EXPECT_FALSE(parsed.username.is_valid()); | 759 EXPECT_FALSE(parsed.username.is_valid()); |
| 867 EXPECT_FALSE(parsed.password.is_valid()); | 760 EXPECT_FALSE(parsed.password.is_valid()); |
| 868 EXPECT_EQ(WideToUTF16(L"http"), | 761 EXPECT_EQ(WideToUTF16(L"http"), |
| 869 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); | 762 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); |
| 870 EXPECT_EQ(WideToUTF16(L"ftp.host"), | 763 EXPECT_EQ(WideToUTF16(L"ftp.host"), |
| 871 formatted.substr(parsed.host.begin, parsed.host.len)); | 764 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 872 EXPECT_EQ(WideToUTF16(L"8000"), | 765 EXPECT_EQ(WideToUTF16(L"8000"), |
| 873 formatted.substr(parsed.port.begin, parsed.port.len)); | 766 formatted.substr(parsed.port.begin, parsed.port.len)); |
| 874 EXPECT_EQ(WideToUTF16(L"/a"), | 767 EXPECT_EQ(WideToUTF16(L"/a"), |
| 875 formatted.substr(parsed.path.begin, parsed.path.len)); | 768 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 876 EXPECT_EQ(WideToUTF16(L"b=c"), | 769 EXPECT_EQ(WideToUTF16(L"b=c"), |
| 877 formatted.substr(parsed.query.begin, parsed.query.len)); | 770 formatted.substr(parsed.query.begin, parsed.query.len)); |
| 878 EXPECT_EQ(WideToUTF16(L"d"), | 771 EXPECT_EQ(WideToUTF16(L"d"), |
| 879 formatted.substr(parsed.ref.begin, parsed.ref.len)); | 772 formatted.substr(parsed.ref.begin, parsed.ref.len)); |
| 880 | 773 |
| 881 // omit http starts with 'f' case. | 774 // omit http starts with 'f' case. |
| 882 formatted = FormatUrl(GURL("http://f/"), | 775 formatted = FormatUrl(GURL("http://f/"), std::string(), kFormatUrlOmitHTTP, |
| 883 std::string(), | 776 net::UnescapeRule::NORMAL, &parsed, NULL, NULL); |
| 884 kFormatUrlOmitHTTP, | |
| 885 UnescapeRule::NORMAL, | |
| 886 &parsed, | |
| 887 NULL, | |
| 888 NULL); | |
| 889 EXPECT_EQ(WideToUTF16(L"f/"), formatted); | 777 EXPECT_EQ(WideToUTF16(L"f/"), formatted); |
| 890 EXPECT_FALSE(parsed.scheme.is_valid()); | 778 EXPECT_FALSE(parsed.scheme.is_valid()); |
| 891 EXPECT_FALSE(parsed.username.is_valid()); | 779 EXPECT_FALSE(parsed.username.is_valid()); |
| 892 EXPECT_FALSE(parsed.password.is_valid()); | 780 EXPECT_FALSE(parsed.password.is_valid()); |
| 893 EXPECT_FALSE(parsed.port.is_valid()); | 781 EXPECT_FALSE(parsed.port.is_valid()); |
| 894 EXPECT_TRUE(parsed.path.is_valid()); | 782 EXPECT_TRUE(parsed.path.is_valid()); |
| 895 EXPECT_FALSE(parsed.query.is_valid()); | 783 EXPECT_FALSE(parsed.query.is_valid()); |
| 896 EXPECT_FALSE(parsed.ref.is_valid()); | 784 EXPECT_FALSE(parsed.ref.is_valid()); |
| 897 EXPECT_EQ(WideToUTF16(L"f"), | 785 EXPECT_EQ(WideToUTF16(L"f"), |
| 898 formatted.substr(parsed.host.begin, parsed.host.len)); | 786 formatted.substr(parsed.host.begin, parsed.host.len)); |
| 899 EXPECT_EQ(WideToUTF16(L"/"), | 787 EXPECT_EQ(WideToUTF16(L"/"), |
| 900 formatted.substr(parsed.path.begin, parsed.path.len)); | 788 formatted.substr(parsed.path.begin, parsed.path.len)); |
| 901 } | 789 } |
| 902 | 790 |
| 903 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL | 791 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL |
| 904 // results in the original GURL, for each ASCII character in the path. | 792 // results in the original GURL, for each ASCII character in the path. |
| 905 TEST(NetUtilTest, FormatUrlRoundTripPathASCII) { | 793 TEST(UrlFormatterTest, FormatUrlRoundTripPathASCII) { |
| 906 for (unsigned char test_char = 32; test_char < 128; ++test_char) { | 794 for (unsigned char test_char = 32; test_char < 128; ++test_char) { |
| 907 GURL url(std::string("http://www.google.com/") + | 795 GURL url(std::string("http://www.google.com/") + |
| 908 static_cast<char>(test_char)); | 796 static_cast<char>(test_char)); |
| 909 size_t prefix_len; | 797 size_t prefix_len; |
| 910 base::string16 formatted = FormatUrl(url, | 798 base::string16 formatted = |
| 911 std::string(), | 799 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword, |
| 912 kFormatUrlOmitUsernamePassword, | 800 net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL); |
| 913 UnescapeRule::NORMAL, | |
| 914 NULL, | |
| 915 &prefix_len, | |
| 916 NULL); | |
| 917 EXPECT_EQ(url.spec(), GURL(formatted).spec()); | 801 EXPECT_EQ(url.spec(), GURL(formatted).spec()); |
| 918 } | 802 } |
| 919 } | 803 } |
| 920 | 804 |
| 921 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL | 805 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL |
| 922 // results in the original GURL, for each escaped ASCII character in the path. | 806 // results in the original GURL, for each escaped ASCII character in the path. |
| 923 TEST(NetUtilTest, FormatUrlRoundTripPathEscaped) { | 807 TEST(UrlFormatterTest, FormatUrlRoundTripPathEscaped) { |
| 924 for (unsigned char test_char = 32; test_char < 128; ++test_char) { | 808 for (unsigned char test_char = 32; test_char < 128; ++test_char) { |
| 925 std::string original_url("http://www.google.com/"); | 809 std::string original_url("http://www.google.com/"); |
| 926 original_url.push_back('%'); | 810 original_url.push_back('%'); |
| 927 original_url.append(base::HexEncode(&test_char, 1)); | 811 original_url.append(base::HexEncode(&test_char, 1)); |
| 928 | 812 |
| 929 GURL url(original_url); | 813 GURL url(original_url); |
| 930 size_t prefix_len; | 814 size_t prefix_len; |
| 931 base::string16 formatted = FormatUrl(url, | 815 base::string16 formatted = |
| 932 std::string(), | 816 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword, |
| 933 kFormatUrlOmitUsernamePassword, | 817 net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL); |
| 934 UnescapeRule::NORMAL, | |
| 935 NULL, | |
| 936 &prefix_len, | |
| 937 NULL); | |
| 938 EXPECT_EQ(url.spec(), GURL(formatted).spec()); | 818 EXPECT_EQ(url.spec(), GURL(formatted).spec()); |
| 939 } | 819 } |
| 940 } | 820 } |
| 941 | 821 |
| 942 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL | 822 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL |
| 943 // results in the original GURL, for each ASCII character in the query. | 823 // results in the original GURL, for each ASCII character in the query. |
| 944 TEST(NetUtilTest, FormatUrlRoundTripQueryASCII) { | 824 TEST(UrlFormatterTest, FormatUrlRoundTripQueryASCII) { |
| 945 for (unsigned char test_char = 32; test_char < 128; ++test_char) { | 825 for (unsigned char test_char = 32; test_char < 128; ++test_char) { |
| 946 GURL url(std::string("http://www.google.com/?") + | 826 GURL url(std::string("http://www.google.com/?") + |
| 947 static_cast<char>(test_char)); | 827 static_cast<char>(test_char)); |
| 948 size_t prefix_len; | 828 size_t prefix_len; |
| 949 base::string16 formatted = FormatUrl(url, | 829 base::string16 formatted = |
| 950 std::string(), | 830 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword, |
| 951 kFormatUrlOmitUsernamePassword, | 831 net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL); |
| 952 UnescapeRule::NORMAL, | |
| 953 NULL, | |
| 954 &prefix_len, | |
| 955 NULL); | |
| 956 EXPECT_EQ(url.spec(), GURL(formatted).spec()); | 832 EXPECT_EQ(url.spec(), GURL(formatted).spec()); |
| 957 } | 833 } |
| 958 } | 834 } |
| 959 | 835 |
| 960 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL | 836 // Make sure that calling FormatUrl on a GURL and then converting back to a GURL |
| 961 // only results in a different GURL for certain characters. | 837 // only results in a different GURL for certain characters. |
| 962 TEST(NetUtilTest, FormatUrlRoundTripQueryEscaped) { | 838 TEST(UrlFormatterTest, FormatUrlRoundTripQueryEscaped) { |
| 963 // A full list of characters which FormatURL should unescape and GURL should | 839 // A full list of characters which FormatURL should unescape and GURL should |
| 964 // not escape again, when they appear in a query string. | 840 // not escape again, when they appear in a query string. |
| 965 const char kUnescapedCharacters[] = | 841 const char kUnescapedCharacters[] = |
| 966 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~"; | 842 "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~"; |
| 967 for (unsigned char test_char = 0; test_char < 128; ++test_char) { | 843 for (unsigned char test_char = 0; test_char < 128; ++test_char) { |
| 968 std::string original_url("http://www.google.com/?"); | 844 std::string original_url("http://www.google.com/?"); |
| 969 original_url.push_back('%'); | 845 original_url.push_back('%'); |
| 970 original_url.append(base::HexEncode(&test_char, 1)); | 846 original_url.append(base::HexEncode(&test_char, 1)); |
| 971 | 847 |
| 972 GURL url(original_url); | 848 GURL url(original_url); |
| 973 size_t prefix_len; | 849 size_t prefix_len; |
| 974 base::string16 formatted = FormatUrl(url, | 850 base::string16 formatted = |
| 975 std::string(), | 851 FormatUrl(url, std::string(), kFormatUrlOmitUsernamePassword, |
| 976 kFormatUrlOmitUsernamePassword, | 852 net::UnescapeRule::NORMAL, NULL, &prefix_len, NULL); |
| 977 UnescapeRule::NORMAL, | |
| 978 NULL, | |
| 979 &prefix_len, | |
| 980 NULL); | |
| 981 | 853 |
| 982 if (test_char && | 854 if (test_char && |
| 983 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { | 855 strchr(kUnescapedCharacters, static_cast<char>(test_char))) { |
| 984 EXPECT_NE(url.spec(), GURL(formatted).spec()); | 856 EXPECT_NE(url.spec(), GURL(formatted).spec()); |
| 985 } else { | 857 } else { |
| 986 EXPECT_EQ(url.spec(), GURL(formatted).spec()); | 858 EXPECT_EQ(url.spec(), GURL(formatted).spec()); |
| 987 } | 859 } |
| 988 } | 860 } |
| 989 } | 861 } |
| 990 | 862 |
| 991 TEST(NetUtilTest, FormatUrlWithOffsets) { | 863 TEST(UrlFormatterTest, FormatUrlWithOffsets) { |
| 992 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, | 864 CheckAdjustedOffsets(std::string(), "en", kFormatUrlOmitNothing, |
| 993 UnescapeRule::NORMAL, NULL); | 865 net::UnescapeRule::NORMAL, NULL); |
| 994 | 866 |
| 995 const size_t basic_offsets[] = { | 867 const size_t basic_offsets[] = { |
| 996 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | 868 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 997 21, 22, 23, 24, 25 | 869 21, 22, 23, 24, 25 |
| 998 }; | 870 }; |
| 999 CheckAdjustedOffsets("http://www.google.com/foo/", "en", | 871 CheckAdjustedOffsets("http://www.google.com/foo/", "en", |
| 1000 kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 872 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, |
| 1001 basic_offsets); | 873 basic_offsets); |
| 1002 | 874 |
| 1003 const size_t omit_auth_offsets_1[] = { | 875 const size_t omit_auth_offsets_1[] = { |
| 1004 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, | 876 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 7, |
| 1005 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 | 877 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
| 1006 }; | 878 }; |
| 1007 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", | 879 CheckAdjustedOffsets("http://foo:bar@www.google.com/", "en", |
| 1008 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, | 880 kFormatUrlOmitUsernamePassword, |
| 1009 omit_auth_offsets_1); | 881 net::UnescapeRule::NORMAL, omit_auth_offsets_1); |
| 1010 | 882 |
| 1011 const size_t omit_auth_offsets_2[] = { | 883 const size_t omit_auth_offsets_2[] = { |
| 1012 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, | 884 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, 7, 8, 9, 10, 11, 12, 13, 14, |
| 1013 15, 16, 17, 18, 19, 20, 21 | 885 15, 16, 17, 18, 19, 20, 21 |
| 1014 }; | 886 }; |
| 1015 CheckAdjustedOffsets("http://foo@www.google.com/", "en", | 887 CheckAdjustedOffsets("http://foo@www.google.com/", "en", |
| 1016 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, | 888 kFormatUrlOmitUsernamePassword, |
| 1017 omit_auth_offsets_2); | 889 net::UnescapeRule::NORMAL, omit_auth_offsets_2); |
| 1018 | 890 |
| 1019 const size_t dont_omit_auth_offsets[] = { | 891 const size_t dont_omit_auth_offsets[] = { |
| 1020 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 892 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1021 kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 893 kNpos, kNpos, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1022 kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | 894 kNpos, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, |
| 1023 30, 31 | 895 30, 31 |
| 1024 }; | 896 }; |
| 1025 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com". | 897 // Unescape to "http://foo\x30B0:\x30B0bar@www.google.com". |
| 1026 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", | 898 CheckAdjustedOffsets("http://foo%E3%82%B0:%E3%82%B0bar@www.google.com/", "en", |
| 1027 kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 899 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, |
| 1028 dont_omit_auth_offsets); | 900 dont_omit_auth_offsets); |
| 1029 | 901 |
| 1030 const size_t view_source_offsets[] = { | 902 const size_t view_source_offsets[] = { |
| 1031 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos, | 903 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, kNpos, |
| 1032 kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 | 904 kNpos, kNpos, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 |
| 1033 }; | 905 }; |
| 1034 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", | 906 CheckAdjustedOffsets("view-source:http://foo@www.google.com/", "en", |
| 1035 kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, | 907 kFormatUrlOmitUsernamePassword, |
| 1036 view_source_offsets); | 908 net::UnescapeRule::NORMAL, view_source_offsets); |
| 1037 | 909 |
| 1038 const size_t idn_hostname_offsets_1[] = { | 910 const size_t idn_hostname_offsets_1[] = { |
| 1039 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 911 0, 1, 2, 3, 4, 5, 6, 7, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1040 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, | 912 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 12, |
| 1041 13, 14, 15, 16, 17, 18, 19 | 913 13, 14, 15, 16, 17, 18, 19 |
| 1042 }; | 914 }; |
| 1043 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/". | 915 // Convert punycode to "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/". |
| 1044 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", | 916 CheckAdjustedOffsets("http://xn--l8jvb1ey91xtjb.jp/foo/", "ja", |
| 1045 kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 917 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, |
| 1046 idn_hostname_offsets_1); | 918 idn_hostname_offsets_1); |
| 1047 | 919 |
| 1048 const size_t idn_hostname_offsets_2[] = { | 920 const size_t idn_hostname_offsets_2[] = { |
| 1049 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, | 921 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1050 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos, | 922 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 14, 15, kNpos, kNpos, kNpos, |
| 1051 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 923 kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1052 kNpos, 19, 20, 21, 22, 23, 24 | 924 kNpos, 19, 20, 21, 22, 23, 24 |
| 1053 }; | 925 }; |
| 1054 // Convert punycode to | 926 // Convert punycode to |
| 1055 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/". | 927 // "http://test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test/". |
| 1056 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", | 928 CheckAdjustedOffsets("http://test.xn--cy2a840a.xn--1lq90ic7f1rc.test/", |
| 1057 "zh-CN", kFormatUrlOmitNothing, UnescapeRule::NORMAL, | 929 "zh-CN", kFormatUrlOmitNothing, |
| 1058 idn_hostname_offsets_2); | 930 net::UnescapeRule::NORMAL, idn_hostname_offsets_2); |
| 1059 | 931 |
| 1060 const size_t unescape_offsets[] = { | 932 const size_t unescape_offsets[] = { |
| 1061 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | 933 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 1062 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos, | 934 21, 22, 23, 24, 25, kNpos, kNpos, 26, 27, 28, 29, 30, kNpos, kNpos, kNpos, |
| 1063 kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, | 935 kNpos, kNpos, kNpos, kNpos, kNpos, 31, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1064 kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, | 936 kNpos, kNpos, kNpos, 32, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, |
| 1065 kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos | 937 kNpos, 33, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos |
| 1066 }; | 938 }; |
| 1067 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB". | 939 // Unescape to "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB". |
| 1068 CheckAdjustedOffsets( | 940 CheckAdjustedOffsets( |
| 1069 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", | 941 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", |
| 1070 "en", kFormatUrlOmitNothing, UnescapeRule::SPACES, unescape_offsets); | 942 "en", kFormatUrlOmitNothing, net::UnescapeRule::SPACES, unescape_offsets); |
| 1071 | 943 |
| 1072 const size_t ref_offsets[] = { | 944 const size_t ref_offsets[] = { |
| 1073 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, | 945 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, |
| 1074 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, | 946 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, kNpos, kNpos, 32, kNpos, kNpos, |
| 1075 33 | 947 33 |
| 1076 }; | 948 }; |
| 1077 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z". | 949 // Unescape to "http://www.google.com/foo.html#\x30B0\x30B0z". |
| 1078 CheckAdjustedOffsets( | 950 CheckAdjustedOffsets( |
| 1079 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", | 951 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z", "en", |
| 1080 kFormatUrlOmitNothing, UnescapeRule::NORMAL, ref_offsets); | 952 kFormatUrlOmitNothing, net::UnescapeRule::NORMAL, ref_offsets); |
| 1081 | 953 |
| 1082 const size_t omit_http_offsets[] = { | 954 const size_t omit_http_offsets[] = { |
| 1083 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | 955 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, |
| 1084 10, 11, 12, 13, 14 | 956 10, 11, 12, 13, 14 |
| 1085 }; | 957 }; |
| 1086 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP, | 958 CheckAdjustedOffsets("http://www.google.com/", "en", kFormatUrlOmitHTTP, |
| 1087 UnescapeRule::NORMAL, omit_http_offsets); | 959 net::UnescapeRule::NORMAL, omit_http_offsets); |
| 1088 | 960 |
| 1089 const size_t omit_http_start_with_ftp_offsets[] = { | 961 const size_t omit_http_start_with_ftp_offsets[] = { |
| 1090 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 | 962 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
| 1091 }; | 963 }; |
| 1092 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, | 964 CheckAdjustedOffsets("http://ftp.google.com/", "en", kFormatUrlOmitHTTP, |
| 1093 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); | 965 net::UnescapeRule::NORMAL, |
| 966 omit_http_start_with_ftp_offsets); |
| 1094 | 967 |
| 1095 const size_t omit_all_offsets[] = { | 968 const size_t omit_all_offsets[] = { |
| 1096 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, | 969 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, |
| 1097 0, 1, 2, 3, 4, 5, 6, 7 | 970 0, 1, 2, 3, 4, 5, 6, 7 |
| 1098 }; | 971 }; |
| 1099 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, | 972 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, |
| 1100 UnescapeRule::NORMAL, omit_all_offsets); | 973 net::UnescapeRule::NORMAL, omit_all_offsets); |
| 1101 } | 974 } |
| 1102 | 975 |
| 1103 } // namespace net | 976 } // namespace |
| 977 |
| 978 } // namespace url_formatter |
| OLD | NEW |