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

Side by Side Diff: net/base/net_util_unittest.cc

Issue 372017: Fix various problems with inline autocomplete and URLs that change length dur... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | « net/base/net_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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "googleurl/src/gurl.h" 10 #include "googleurl/src/gurl.h"
11 #include "net/base/escape.h" 11 #include "net/base/escape.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 true}}, 338 true}},
339 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn", 339 {"xn--fiqs8s.cn", L"\x4e2d\x56fd\x3002" L"cn",
340 {false, false, true, false, false, 340 {false, false, true, false, false,
341 false, false, false, false, false, 341 false, false, false, false, false,
342 false, false, false, false, false, 342 false, false, false, false, false,
343 false, false, true, false, false, 343 false, false, true, false, false,
344 true}}, 344 true}},
345 #endif 345 #endif
346 }; 346 };
347 347
348 struct AdjustOffsetCase {
349 size_t input_offset;
350 size_t output_offset;
351 };
352
348 struct CompliantHostCase { 353 struct CompliantHostCase {
349 const char* host; 354 const char* host;
350 bool expected_output; 355 bool expected_output;
351 }; 356 };
352 357
353 struct SuggestedFilenameCase { 358 struct SuggestedFilenameCase {
354 const char* url; 359 const char* url;
355 const char* content_disp_header; 360 const char* content_disp_header;
356 const char* referrer_charset; 361 const char* referrer_charset;
357 const wchar_t* default_filename; 362 const wchar_t* default_filename;
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 tests[i].referrer_charset))); 780 tests[i].referrer_charset)));
776 } 781 }
777 } 782 }
778 783
779 TEST(NetUtilTest, IDNToUnicodeFast) { 784 TEST(NetUtilTest, IDNToUnicodeFast) {
780 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) { 785 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) {
781 for (size_t j = 0; j < arraysize(kLanguages); j++) { 786 for (size_t j = 0; j < arraysize(kLanguages); j++) {
782 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow 787 // ja || zh-TW,en || ko,ja -> IDNToUnicodeSlow
783 if (j == 3 || j == 17 || j == 18) 788 if (j == 3 || j == 17 || j == 18)
784 continue; 789 continue;
785 std::wstring output; 790 std::wstring output(net::IDNToUnicode(idn_cases[i].input,
786 net::IDNToUnicode(idn_cases[i].input, 791 strlen(idn_cases[i].input), kLanguages[j], NULL));
787 static_cast<int>(strlen(idn_cases[i].input)),
788 kLanguages[j],
789 &output);
790 std::wstring expected(idn_cases[i].unicode_allowed[j] ? 792 std::wstring expected(idn_cases[i].unicode_allowed[j] ?
791 idn_cases[i].unicode_output : 793 idn_cases[i].unicode_output : ASCIIToWide(idn_cases[i].input));
792 ASCIIToWide(idn_cases[i].input));
793 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); 794 AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
794 EXPECT_EQ(expected, output); 795 EXPECT_EQ(expected, output);
795 } 796 }
796 } 797 }
797 } 798 }
798 799
799 TEST(NetUtilTest, IDNToUnicodeSlow) { 800 TEST(NetUtilTest, IDNToUnicodeSlow) {
800 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) { 801 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_cases); i++) {
801 for (size_t j = 0; j < arraysize(kLanguages); j++) { 802 for (size_t j = 0; j < arraysize(kLanguages); j++) {
802 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast 803 // !(ja || zh-TW,en || ko,ja) -> IDNToUnicodeFast
803 if (!(j == 3 || j == 17 || j == 18)) 804 if (!(j == 3 || j == 17 || j == 18))
804 continue; 805 continue;
805 std::wstring output; 806 std::wstring output(net::IDNToUnicode(idn_cases[i].input,
806 net::IDNToUnicode(idn_cases[i].input, 807 strlen(idn_cases[i].input), kLanguages[j], NULL));
807 static_cast<int>(strlen(idn_cases[i].input)),
808 kLanguages[j],
809 &output);
810 std::wstring expected(idn_cases[i].unicode_allowed[j] ? 808 std::wstring expected(idn_cases[i].unicode_allowed[j] ?
811 idn_cases[i].unicode_output : 809 idn_cases[i].unicode_output : ASCIIToWide(idn_cases[i].input));
812 ASCIIToWide(idn_cases[i].input));
813 AppendLanguagesToOutputs(kLanguages[j], &expected, &output); 810 AppendLanguagesToOutputs(kLanguages[j], &expected, &output);
814 EXPECT_EQ(expected, output); 811 EXPECT_EQ(expected, output);
815 } 812 }
816 } 813 }
817 } 814 }
818 815
816 TEST(NetUtilTest, IDNToUnicodeAdjustOffset) {
817 const AdjustOffsetCase adjust_cases[] = {
818 {0, 0},
819 {2, 2},
820 {4, 4},
821 {5, 5},
822 {6, std::wstring::npos},
823 {16, std::wstring::npos},
824 {17, 7},
825 {18, 8},
826 {19, std::wstring::npos},
827 {25, std::wstring::npos},
828 {34, 12},
829 {35, 13},
830 {38, 16},
831 {39, std::wstring::npos},
832 {std::wstring::npos, std::wstring::npos},
833 };
834 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(adjust_cases); ++i) {
835 size_t offset = adjust_cases[i].input_offset;
836 // "test.\x89c6\x9891.\x5317\x4eac\x5927\x5b78.test"
837 net::IDNToUnicode("test.xn--cy2a840a.xn--1lq90ic7f1rc.test", 39, L"zh-CN",
838 &offset);
839 EXPECT_EQ(adjust_cases[i].output_offset, offset);
840 }
841 }
842
819 TEST(NetUtilTest, CompliantHost) { 843 TEST(NetUtilTest, CompliantHost) {
820 const CompliantHostCase compliant_host_cases[] = { 844 const CompliantHostCase compliant_host_cases[] = {
821 {"", false}, 845 {"", false},
822 {"a", true}, 846 {"a", true},
823 {"-", false}, 847 {"-", false},
824 {".", false}, 848 {".", false},
825 {"a.", true}, 849 {"a.", true},
826 {"a.a", true}, 850 {"a.a", true},
827 {"9.a", true}, 851 {"9.a", true},
828 {"a.9", false}, 852 {"a.9", false},
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 {"view-source of view-source", 1345 {"view-source of view-source",
1322 "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja", true, 1346 "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja", true,
1323 UnescapeRule::NORMAL, 1347 UnescapeRule::NORMAL,
1324 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12}, 1348 L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
1325 }; 1349 };
1326 1350
1327 for (size_t i = 0; i < arraysize(tests); ++i) { 1351 for (size_t i = 0; i < arraysize(tests); ++i) {
1328 size_t prefix_len; 1352 size_t prefix_len;
1329 std::wstring formatted = net::FormatUrl( 1353 std::wstring formatted = net::FormatUrl(
1330 GURL(tests[i].input), tests[i].languages, tests[i].omit, 1354 GURL(tests[i].input), tests[i].languages, tests[i].omit,
1331 tests[i].escape_rules, NULL, &prefix_len); 1355 tests[i].escape_rules, NULL, &prefix_len, NULL);
1332 EXPECT_EQ(tests[i].output, formatted) << tests[i].description; 1356 EXPECT_EQ(tests[i].output, formatted) << tests[i].description;
1333 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 1357 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
1334 } 1358 }
1335 } 1359 }
1336 1360
1337 TEST(NetUtilTest, FormatUrlParsed) { 1361 TEST(NetUtilTest, FormatUrlParsed) {
1338 // No unescape case. 1362 // No unescape case.
1339 url_parse::Parsed parsed; 1363 url_parse::Parsed parsed;
1340 std::wstring formatted = net::FormatUrl( 1364 std::wstring formatted = net::FormatUrl(
1341 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1365 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
1342 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1366 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
1343 L"ja", false, UnescapeRule::NONE, &parsed, NULL); 1367 L"ja", false, UnescapeRule::NONE, &parsed, NULL, NULL);
1344 EXPECT_EQ(L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080" 1368 EXPECT_EQ(L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
1345 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0", formatted); 1369 L"/%E3%82%B0/?q=%E3%82%B0#\x30B0", formatted);
1346 EXPECT_EQ(L"%E3%82%B0", 1370 EXPECT_EQ(L"%E3%82%B0",
1347 formatted.substr(parsed.username.begin, parsed.username.len)); 1371 formatted.substr(parsed.username.begin, parsed.username.len));
1348 EXPECT_EQ(L"%E3%83%BC", 1372 EXPECT_EQ(L"%E3%83%BC",
1349 formatted.substr(parsed.password.begin, parsed.password.len)); 1373 formatted.substr(parsed.password.begin, parsed.password.len));
1350 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", 1374 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
1351 formatted.substr(parsed.host.begin, parsed.host.len)); 1375 formatted.substr(parsed.host.begin, parsed.host.len));
1352 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); 1376 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
1353 EXPECT_EQ(L"/%E3%82%B0/", 1377 EXPECT_EQ(L"/%E3%82%B0/",
1354 formatted.substr(parsed.path.begin, parsed.path.len)); 1378 formatted.substr(parsed.path.begin, parsed.path.len));
1355 EXPECT_EQ(L"q=%E3%82%B0", 1379 EXPECT_EQ(L"q=%E3%82%B0",
1356 formatted.substr(parsed.query.begin, parsed.query.len)); 1380 formatted.substr(parsed.query.begin, parsed.query.len));
1357 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); 1381 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
1358 1382
1359 // Unescape case. 1383 // Unescape case.
1360 formatted = net::FormatUrl( 1384 formatted = net::FormatUrl(
1361 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1385 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
1362 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1386 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
1363 L"ja", false, UnescapeRule::NORMAL, &parsed, NULL); 1387 L"ja", false, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1364 EXPECT_EQ(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080" 1388 EXPECT_EQ(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
1365 L"/\x30B0/?q=\x30B0#\x30B0", formatted); 1389 L"/\x30B0/?q=\x30B0#\x30B0", formatted);
1366 EXPECT_EQ(L"\x30B0", 1390 EXPECT_EQ(L"\x30B0",
1367 formatted.substr(parsed.username.begin, parsed.username.len)); 1391 formatted.substr(parsed.username.begin, parsed.username.len));
1368 EXPECT_EQ(L"\x30FC", 1392 EXPECT_EQ(L"\x30FC",
1369 formatted.substr(parsed.password.begin, parsed.password.len)); 1393 formatted.substr(parsed.password.begin, parsed.password.len));
1370 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", 1394 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
1371 formatted.substr(parsed.host.begin, parsed.host.len)); 1395 formatted.substr(parsed.host.begin, parsed.host.len));
1372 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); 1396 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
1373 EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len)); 1397 EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len));
1374 EXPECT_EQ(L"q=\x30B0", 1398 EXPECT_EQ(L"q=\x30B0",
1375 formatted.substr(parsed.query.begin, parsed.query.len)); 1399 formatted.substr(parsed.query.begin, parsed.query.len));
1376 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); 1400 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
1377 1401
1378 // Omit_username_password + unescape case. 1402 // Omit_username_password + unescape case.
1379 formatted = net::FormatUrl( 1403 formatted = net::FormatUrl(
1380 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/" 1404 GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
1381 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"), 1405 "%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
1382 L"ja", true, UnescapeRule::NORMAL, &parsed, NULL); 1406 L"ja", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1383 EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" 1407 EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
1384 L"/\x30B0/?q=\x30B0#\x30B0", formatted); 1408 L"/\x30B0/?q=\x30B0#\x30B0", formatted);
1385 EXPECT_FALSE(parsed.username.is_valid()); 1409 EXPECT_FALSE(parsed.username.is_valid());
1386 EXPECT_FALSE(parsed.password.is_valid()); 1410 EXPECT_FALSE(parsed.password.is_valid());
1387 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", 1411 EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp",
1388 formatted.substr(parsed.host.begin, parsed.host.len)); 1412 formatted.substr(parsed.host.begin, parsed.host.len));
1389 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); 1413 EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len));
1390 EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len)); 1414 EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len));
1391 EXPECT_EQ(L"q=\x30B0", 1415 EXPECT_EQ(L"q=\x30B0",
1392 formatted.substr(parsed.query.begin, parsed.query.len)); 1416 formatted.substr(parsed.query.begin, parsed.query.len));
1393 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); 1417 EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len));
1394 1418
1395 // View-source case. 1419 // View-source case.
1396 formatted = net::FormatUrl( 1420 formatted = net::FormatUrl(
1397 GURL("view-source:http://user:passwd@host:81/path?query#ref"), 1421 GURL("view-source:http://user:passwd@host:81/path?query#ref"),
1398 L"", true, UnescapeRule::NORMAL, &parsed, NULL); 1422 L"", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1399 EXPECT_EQ(L"view-source:http://host:81/path?query#ref", formatted); 1423 EXPECT_EQ(L"view-source:http://host:81/path?query#ref", formatted);
1400 EXPECT_EQ(L"view-source:http", 1424 EXPECT_EQ(L"view-source:http",
1401 formatted.substr(parsed.scheme.begin, parsed.scheme.len)); 1425 formatted.substr(parsed.scheme.begin, parsed.scheme.len));
1402 EXPECT_FALSE(parsed.username.is_valid()); 1426 EXPECT_FALSE(parsed.username.is_valid());
1403 EXPECT_FALSE(parsed.password.is_valid()); 1427 EXPECT_FALSE(parsed.password.is_valid());
1404 EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len)); 1428 EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
1405 EXPECT_EQ(L"81", formatted.substr(parsed.port.begin, parsed.port.len)); 1429 EXPECT_EQ(L"81", formatted.substr(parsed.port.begin, parsed.port.len));
1406 EXPECT_EQ(L"/path", formatted.substr(parsed.path.begin, parsed.path.len)); 1430 EXPECT_EQ(L"/path", formatted.substr(parsed.path.begin, parsed.path.len));
1407 EXPECT_EQ(L"query", formatted.substr(parsed.query.begin, parsed.query.len)); 1431 EXPECT_EQ(L"query", formatted.substr(parsed.query.begin, parsed.query.len));
1408 EXPECT_EQ(L"ref", formatted.substr(parsed.ref.begin, parsed.ref.len)); 1432 EXPECT_EQ(L"ref", formatted.substr(parsed.ref.begin, parsed.ref.len));
1409 } 1433 }
1410 1434
1435 TEST(NetUtilTest, FormatUrlAdjustOffset) {
1436 const AdjustOffsetCase basic_cases[] = {
1437 {0, 0},
1438 {3, 3},
1439 {5, 5},
1440 {6, 6},
1441 {13, 13},
1442 {21, 21},
1443 {22, 22},
1444 {23, 23},
1445 {25, 25},
1446 {26, std::wstring::npos},
1447 {500000, std::wstring::npos},
1448 {std::wstring::npos, std::wstring::npos},
1449 };
1450 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(basic_cases); ++i) {
1451 size_t offset = basic_cases[i].input_offset;
1452 net::FormatUrl(GURL("http://www.google.com/foo/"), L"en", true,
1453 UnescapeRule::NORMAL, NULL, NULL, &offset);
1454 EXPECT_EQ(basic_cases[i].output_offset, offset);
1455 }
1456
1457 const struct {
1458 const char* input_url;
1459 size_t input_offset;
1460 size_t output_offset;
1461 } omit_auth_cases[] = {
1462 {"http://foo:bar@www.google.com/", 6, 6},
1463 {"http://foo:bar@www.google.com/", 7, 7},
1464 {"http://foo:bar@www.google.com/", 8, std::wstring::npos},
1465 {"http://foo:bar@www.google.com/", 10, std::wstring::npos},
1466 {"http://foo:bar@www.google.com/", 11, std::wstring::npos},
1467 {"http://foo:bar@www.google.com/", 14, std::wstring::npos},
1468 {"http://foo:bar@www.google.com/", 15, 7},
1469 {"http://foo:bar@www.google.com/", 25, 17},
1470 {"http://foo@www.google.com/", 9, std::wstring::npos},
1471 {"http://foo@www.google.com/", 11, 7},
1472 };
1473 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_auth_cases); ++i) {
1474 size_t offset = omit_auth_cases[i].input_offset;
1475 net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en", true,
1476 UnescapeRule::NORMAL, NULL, NULL, &offset);
1477 EXPECT_EQ(omit_auth_cases[i].output_offset, offset);
1478 }
1479
1480 const AdjustOffsetCase view_source_cases[] = {
1481 {0, 0},
1482 {3, 3},
1483 {11, 11},
1484 {12, 12},
1485 {13, 13},
1486 {19, 19},
1487 {20, std::wstring::npos},
1488 {23, 19},
1489 {26, 22},
1490 {std::wstring::npos, std::wstring::npos},
1491 };
1492 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(view_source_cases); ++i) {
1493 size_t offset = view_source_cases[i].input_offset;
1494 net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en", true,
1495 UnescapeRule::NORMAL, NULL, NULL, &offset);
1496 EXPECT_EQ(view_source_cases[i].output_offset, offset);
1497 }
1498
1499 const AdjustOffsetCase idn_hostname_cases[] = {
1500 {8, std::wstring::npos},
1501 {16, std::wstring::npos},
1502 {24, std::wstring::npos},
1503 {25, 12},
1504 {30, 17},
1505 };
1506 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_hostname_cases); ++i) {
1507 size_t offset = idn_hostname_cases[i].input_offset;
1508 // "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/"
1509 net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja", true,
1510 UnescapeRule::NORMAL, NULL, NULL, &offset);
1511 EXPECT_EQ(idn_hostname_cases[i].output_offset, offset);
1512 }
1513
1514 const AdjustOffsetCase unescape_cases[] = {
1515 {25, 25},
1516 {26, std::wstring::npos},
1517 {27, std::wstring::npos},
1518 {28, 26},
1519 {35, std::wstring::npos},
1520 {41, 31},
1521 {59, 33},
1522 {60, std::wstring::npos},
1523 {67, std::wstring::npos},
1524 {68, std::wstring::npos},
1525 };
1526 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(unescape_cases); ++i) {
1527 size_t offset = unescape_cases[i].input_offset;
1528 // "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB"
1529 net::FormatUrl(GURL(
1530 "http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"),
1531 L"en", true, UnescapeRule::SPACES, NULL, NULL, &offset);
1532 EXPECT_EQ(unescape_cases[i].output_offset, offset);
1533 }
1534
1535 const AdjustOffsetCase ref_cases[] = {
1536 {30, 30},
1537 {31, 31},
1538 {32, std::wstring::npos},
1539 {34, 32},
1540 {37, 33},
1541 {38, std::wstring::npos},
1542 };
1543 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ref_cases); ++i) {
1544 size_t offset = ref_cases[i].input_offset;
1545 // "http://www.google.com/foo.html#\x30B0\x30B0z"
1546 net::FormatUrl(GURL(
1547 "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), L"en",
1548 true, UnescapeRule::NORMAL, NULL, NULL, &offset);
1549 EXPECT_EQ(ref_cases[i].output_offset, offset);
1550 }
1551 }
1552
1411 TEST(NetUtilTest, SimplifyUrlForRequest) { 1553 TEST(NetUtilTest, SimplifyUrlForRequest) {
1412 struct { 1554 struct {
1413 const char* input_url; 1555 const char* input_url;
1414 const char* expected_simplified_url; 1556 const char* expected_simplified_url;
1415 } tests[] = { 1557 } tests[] = {
1416 { 1558 {
1417 // Reference section should be stripped. 1559 // Reference section should be stripped.
1418 "http://www.google.com:78/foobar?query=1#hash", 1560 "http://www.google.com:78/foobar?query=1#hash",
1419 "http://www.google.com:78/foobar?query=1", 1561 "http://www.google.com:78/foobar?query=1",
1420 }, 1562 },
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) { 1601 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) {
1460 net::SetExplicitlyAllowedPorts(invalid[i]); 1602 net::SetExplicitlyAllowedPorts(invalid[i]);
1461 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); 1603 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size()));
1462 } 1604 }
1463 1605
1464 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { 1606 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) {
1465 net::SetExplicitlyAllowedPorts(valid[i]); 1607 net::SetExplicitlyAllowedPorts(valid[i]);
1466 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); 1608 EXPECT_EQ(i, net::explicitly_allowed_ports.size());
1467 } 1609 }
1468 } 1610 }
1469
OLDNEW
« no previous file with comments | « net/base/net_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698