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

Side by Side Diff: components/url_formatter/url_formatter_unittest.cc

Issue 1171333003: Move net::FormatUrl and friends outside of //net and into //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fixes following rebase Created 5 years, 6 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 // 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"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h"
16 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 15 #include "url/gurl.h"
18 16
19 using base::ASCIIToUTF16;
20 using base::WideToUTF16;
21 17
22 namespace net { 18 namespace url_formatter {
23 19
24 namespace { 20 namespace {
25 21
22 using base::WideToUTF16;
23 using base::ASCIIToUTF16;
24
26 const size_t kNpos = base::string16::npos; 25 const size_t kNpos = base::string16::npos;
27 26
28 const char* const kLanguages[] = { 27 const char* const kLanguages[] = {
29 "", "en", "zh-CN", "ja", "ko", 28 "", "en", "zh-CN", "ja", "ko",
30 "he", "ar", "ru", "el", "fr", 29 "he", "ar", "ru", "el", "fr",
31 "de", "pt", "sv", "th", "hi", 30 "de", "pt", "sv", "th", "hi",
32 "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en", 31 "de,en", "el,en", "zh-TW,en", "ko,ja", "he,ru,en",
33 "zh,ru,en" 32 "zh,ru,en"
34 }; 33 };
35 34
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 for (size_t i = 0; i < url_length; ++i) 416 for (size_t i = 0; i < url_length; ++i)
418 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url); 417 VerboseExpect(output_offsets[i], offsets[i], url_string, i, formatted_url);
419 VerboseExpect(formatted_url.length(), offsets[url_length], url_string, 418 VerboseExpect(formatted_url.length(), offsets[url_length], url_string,
420 url_length, formatted_url); 419 url_length, formatted_url);
421 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string, 420 VerboseExpect(base::string16::npos, offsets[url_length + 1], url_string,
422 500000, formatted_url); 421 500000, formatted_url);
423 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string, 422 VerboseExpect(base::string16::npos, offsets[url_length + 2], url_string,
424 std::string::npos, formatted_url); 423 std::string::npos, formatted_url);
425 } 424 }
426 425
427 } // anonymous namespace
428
429 TEST(NetUtilTest, IDNToUnicodeFast) { 426 TEST(NetUtilTest, IDNToUnicodeFast) {
430 for (size_t i = 0; i < arraysize(idn_cases); i++) { 427 for (size_t i = 0; i < arraysize(idn_cases); i++) {
431 for (size_t j = 0; j < arraysize(kLanguages); j++) { 428 for (size_t j = 0; j < arraysize(kLanguages); j++) {
432 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow 429 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
433 if (j == 3 || j == 17 || j == 18) 430 if (j == 3 || j == 17 || j == 18)
434 continue; 431 continue;
435 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j])); 432 base::string16 output(IDNToUnicode(idn_cases[i].input, kLanguages[j]));
436 base::string16 expected(idn_cases[i].unicode_allowed[j] ? 433 base::string16 expected(idn_cases[i].unicode_allowed[j] ?
437 WideToUTF16(idn_cases[i].unicode_output) : 434 WideToUTF16(idn_cases[i].unicode_output) :
438 ASCIIToUTF16(idn_cases[i].input)); 435 ASCIIToUTF16(idn_cases[i].input));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 471 }
475 } 472 }
476 473
477 TEST(NetUtilTest, StripWWW) { 474 TEST(NetUtilTest, StripWWW) {
478 EXPECT_EQ(base::string16(), StripWWW(base::string16())); 475 EXPECT_EQ(base::string16(), StripWWW(base::string16()));
479 EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www."))); 476 EXPECT_EQ(base::string16(), StripWWW(ASCIIToUTF16("www.")));
480 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah"))); 477 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("www.blah")));
481 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah"))); 478 EXPECT_EQ(ASCIIToUTF16("blah"), StripWWW(ASCIIToUTF16("blah")));
482 } 479 }
483 480
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) { 481 TEST(NetUtilTest, FormatUrl) {
555 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword; 482 FormatUrlTypes default_format_type = kFormatUrlOmitUsernamePassword;
556 const UrlTestData tests[] = { 483 const UrlTestData tests[] = {
557 {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0}, 484 {"Empty URL", "", "", default_format_type, UnescapeRule::NORMAL, L"", 0},
558 485
559 {"Simple URL", 486 {"Simple URL",
560 "http://www.google.com/", "", default_format_type, UnescapeRule::NORMAL, 487 "http://www.google.com/", "", default_format_type, UnescapeRule::NORMAL,
561 L"http://www.google.com/", 7}, 488 L"http://www.google.com/", 7},
562 489
563 {"With a port number and a reference", 490 {"With a port number and a reference",
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets); 1020 UnescapeRule::NORMAL, omit_http_start_with_ftp_offsets);
1094 1021
1095 const size_t omit_all_offsets[] = { 1022 const size_t omit_all_offsets[] = {
1096 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos, 1023 0, kNpos, kNpos, kNpos, kNpos, kNpos, kNpos, 0, kNpos, kNpos, kNpos, kNpos,
1097 0, 1, 2, 3, 4, 5, 6, 7 1024 0, 1, 2, 3, 4, 5, 6, 7
1098 }; 1025 };
1099 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll, 1026 CheckAdjustedOffsets("http://user@foo.com/", "en", kFormatUrlOmitAll,
1100 UnescapeRule::NORMAL, omit_all_offsets); 1027 UnescapeRule::NORMAL, omit_all_offsets);
1101 } 1028 }
1102 1029
1103 } // namespace net 1030 } // namespace
1031
1032 } // namespace url_formatter
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698