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

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

Issue 1574034: Changes FormatURL to not strip http if the host starts with ftp or https[!a-z]. This... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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 | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "net/base/net_util.h"
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 1382
1383 {"omit http", 1383 {"omit http",
1384 "http://www.google.com/", L"en", net::kFormatUrlOmitHTTP, 1384 "http://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
1385 UnescapeRule::NORMAL, L"www.google.com/", 1385 UnescapeRule::NORMAL, L"www.google.com/",
1386 0}, 1386 0},
1387 1387
1388 {"omit http with https", 1388 {"omit http with https",
1389 "https://www.google.com/", L"en", net::kFormatUrlOmitHTTP, 1389 "https://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
1390 UnescapeRule::NORMAL, L"https://www.google.com/", 1390 UnescapeRule::NORMAL, L"https://www.google.com/",
1391 8}, 1391 8},
1392
1393 {"omit http starts with ftp.",
1394 "http://ftp.google.com/", L"en", net::kFormatUrlOmitHTTP,
1395 UnescapeRule::NORMAL, L"http://ftp.google.com/",
1396 7},
1392 }; 1397 };
1393 1398
1394 for (size_t i = 0; i < arraysize(tests); ++i) { 1399 for (size_t i = 0; i < arraysize(tests); ++i) {
1395 size_t prefix_len; 1400 size_t prefix_len;
1396 std::wstring formatted = net::FormatUrl( 1401 std::wstring formatted = net::FormatUrl(
1397 GURL(tests[i].input), tests[i].languages, tests[i].format_types, 1402 GURL(tests[i].input), tests[i].languages, tests[i].format_types,
1398 tests[i].escape_rules, NULL, &prefix_len, NULL); 1403 tests[i].escape_rules, NULL, &prefix_len, NULL);
1399 EXPECT_EQ(tests[i].output, formatted) << tests[i].description; 1404 EXPECT_EQ(tests[i].output, formatted) << tests[i].description;
1400 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description; 1405 EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
1401 } 1406 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL); 1489 L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1485 EXPECT_EQ(L"host:8000/a?b=c#d", formatted); 1490 EXPECT_EQ(L"host:8000/a?b=c#d", formatted);
1486 EXPECT_FALSE(parsed.scheme.is_valid()); 1491 EXPECT_FALSE(parsed.scheme.is_valid());
1487 EXPECT_FALSE(parsed.username.is_valid()); 1492 EXPECT_FALSE(parsed.username.is_valid());
1488 EXPECT_FALSE(parsed.password.is_valid()); 1493 EXPECT_FALSE(parsed.password.is_valid());
1489 EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len)); 1494 EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
1490 EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len)); 1495 EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
1491 EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len)); 1496 EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
1492 EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len)); 1497 EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
1493 EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len)); 1498 EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
1499
1500 // omit http starts with ftp case.
1501 formatted = net::FormatUrl(
1502 GURL("http://ftp.host:8000/a?b=c#d"),
1503 L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1504 EXPECT_EQ(L"http://ftp.host:8000/a?b=c#d", formatted);
1505 EXPECT_TRUE(parsed.scheme.is_valid());
1506 EXPECT_FALSE(parsed.username.is_valid());
1507 EXPECT_FALSE(parsed.password.is_valid());
1508 EXPECT_EQ(L"http", formatted.substr(parsed.scheme.begin, parsed.scheme.len));
1509 EXPECT_EQ(L"ftp.host", formatted.substr(parsed.host.begin, parsed.host.len));
1510 EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
1511 EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
1512 EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
1513 EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
1514
1515 // omit http starts with 'f' case.
1516 formatted = net::FormatUrl(
1517 GURL("http://f/"),
1518 L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
1519 EXPECT_EQ(L"f/", formatted);
1520 EXPECT_FALSE(parsed.scheme.is_valid());
1521 EXPECT_FALSE(parsed.username.is_valid());
1522 EXPECT_FALSE(parsed.password.is_valid());
1523 EXPECT_FALSE(parsed.port.is_valid());
1524 EXPECT_TRUE(parsed.path.is_valid());
1525 EXPECT_FALSE(parsed.query.is_valid());
1526 EXPECT_FALSE(parsed.ref.is_valid());
1527 EXPECT_EQ(L"f", formatted.substr(parsed.host.begin, parsed.host.len));
1528 EXPECT_EQ(L"/", formatted.substr(parsed.path.begin, parsed.path.len));
1494 } 1529 }
1495 1530
1496 TEST(NetUtilTest, FormatUrlAdjustOffset) { 1531 TEST(NetUtilTest, FormatUrlAdjustOffset) {
1497 const AdjustOffsetCase basic_cases[] = { 1532 const AdjustOffsetCase basic_cases[] = {
1498 {0, 0}, 1533 {0, 0},
1499 {3, 3}, 1534 {3, 3},
1500 {5, 5}, 1535 {5, 5},
1501 {6, 6}, 1536 {6, 6},
1502 {13, 13}, 1537 {13, 13},
1503 {21, 21}, 1538 {21, 21},
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 {7, 0}, 1657 {7, 0},
1623 {8, 1}, 1658 {8, 1},
1624 }; 1659 };
1625 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_cases); ++i) { 1660 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_cases); ++i) {
1626 size_t offset = omit_http_cases[i].input_offset; 1661 size_t offset = omit_http_cases[i].input_offset;
1627 net::FormatUrl(GURL("http://www.google.com"), L"en", 1662 net::FormatUrl(GURL("http://www.google.com"), L"en",
1628 net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset); 1663 net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
1629 EXPECT_EQ(omit_http_cases[i].output_offset, offset); 1664 EXPECT_EQ(omit_http_cases[i].output_offset, offset);
1630 } 1665 }
1631 1666
1667 const AdjustOffsetCase omit_http_start_with_ftp[] = {
1668 {0, 0},
1669 {3, 3},
1670 {8, 8},
1671 };
1672 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_start_with_ftp); ++i) {
1673 size_t offset = omit_http_start_with_ftp[i].input_offset;
1674 net::FormatUrl(GURL("http://ftp.google.com"), L"en",
1675 net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
1676 EXPECT_EQ(omit_http_start_with_ftp[i].output_offset, offset);
1677 }
1678
1632 const AdjustOffsetCase omit_all_cases[] = { 1679 const AdjustOffsetCase omit_all_cases[] = {
1633 {12, 0}, 1680 {12, 0},
1634 {13, 1}, 1681 {13, 1},
1635 {0, std::wstring::npos}, 1682 {0, std::wstring::npos},
1636 {3, std::wstring::npos}, 1683 {3, std::wstring::npos},
1637 }; 1684 };
1638 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_all_cases); ++i) { 1685 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_all_cases); ++i) {
1639 size_t offset = omit_all_cases[i].input_offset; 1686 size_t offset = omit_all_cases[i].input_offset;
1640 net::FormatUrl(GURL("http://user@foo.com/"), L"en", net::kFormatUrlOmitAll, 1687 net::FormatUrl(GURL("http://user@foo.com/"), L"en", net::kFormatUrlOmitAll,
1641 UnescapeRule::NORMAL, NULL, NULL, &offset); 1688 UnescapeRule::NORMAL, NULL, NULL, &offset);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) { 1741 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) {
1695 net::SetExplicitlyAllowedPorts(invalid[i]); 1742 net::SetExplicitlyAllowedPorts(invalid[i]);
1696 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size())); 1743 EXPECT_EQ(0, static_cast<int>(net::explicitly_allowed_ports.size()));
1697 } 1744 }
1698 1745
1699 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) { 1746 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(valid); ++i) {
1700 net::SetExplicitlyAllowedPorts(valid[i]); 1747 net::SetExplicitlyAllowedPorts(valid[i]);
1701 EXPECT_EQ(i, net::explicitly_allowed_ports.size()); 1748 EXPECT_EQ(i, net::explicitly_allowed_ports.size());
1702 } 1749 }
1703 } 1750 }
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