summaryrefslogtreecommitdiffstats
path: root/net/base/net_util_unittest.cc
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 20:01:00 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-23 20:01:00 +0000
commit69c579e522c4493c15c93ebf33b28a35b1e7213b (patch)
tree5dde3cc78e0de04bb87613c09be12b47b80d8307 /net/base/net_util_unittest.cc
parent12f144239468f206dc82c3f3481fef477f636798 (diff)
downloadchromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.zip
chromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.tar.gz
chromium_src-69c579e522c4493c15c93ebf33b28a35b1e7213b.tar.bz2
Re-instate the temporary revert from r45267. That reverted certain
Omnibox, toolbar, tab animations, and other UI changes for purposes of testing and merging into mstone-5. Additionally reverts these CLs to fix the earlier revert: r45271: [Mac] Image references missing from Omnibox revert. r45268: GTK fix merge failure in uber-revert. Additional revert which fixed a bug for the branch: r45381: [Mac] Omnibox popup icons and text lined up under toolbar. Slight merge conflict which should be good: r45322: GTK: Implement OnDragCanceled() for autocomplete... Also ++kThemePackVersion and regenerate the cached theme pak. Re-instated changes: r45213: GTK: Override cursor colors in chrome-theme mode. r45103: Support drawing nano tabs in the tabstrip. r45084: GTK: Position the EV certificate stuff inside a green bubble. r44979: Subclassing the InfoBubble to handle anchoring bubbles basedon... r44957: GTK: Tint the geolocation icons in gtk mode. r44943: Changes FormatURL to not strip http if the host starts with ft... r44930: Remove an icon that is no longer used. r44929: SSL UI changes, Windows, code side (images are separate). r44859: SSL UI changes (icons). TBRed since trybots hate binary patches. r44822: GTK: Select better greens in the native omnibox popup. r44814: GTK: navigate to URL on PRIMARY when middle-clicking the locat... r44789: [Mac] Bookmark star missing on NTP and BMM. r44775: [Mac] Centralize hack to make tests work with AutocompleteClas... r44678: Display the SECURITY_WARNING status in the location bar for the r44648: [Mac] Add an arrow cursor rect for the location image. r44615: Revert r44611 because it may have broken "unit_tests" on "Vist... r44611: Display the SECURITY_WARNING status in the location bar for the r44577: Revert 44572 - [Mac] Update locationbar icon as user types. r44572: [Mac] Update location-bar icon as user types. r44555: GTK: Use correct button mask on reload button. r44545: [Mac] Omnibox text drag drag URL when select-all. r44523: GTK: Prevent inappropriate drag of location bar location icon. r44519: GTK: make the primary selection include the url's scheme when ... r44492: [Mac] Fix search icon in keyword search to be right-side-up. r44415: GTK: Update top padding on icons in the autocomplete popup. r44401: GTK: Tint omnibox icons in GTK mode differently. r44380: GTK: Move reload in gtk mode and fix omnibox popup location. r44282: Fixes crash in autocomplete when typing some URLs. The problem r44273: [Mac] PDF icons for omnibox nits. r44269: Fix build break due to bad merge resolve r44268: Shift omnibox dropdown in and up on Windows, and square off th... r44178: GTK: fix TTS padding. r44177: Round the top left and right edges of the toolbar. r44171: Images only checkin for try server goodness. r44163: GTK: fix padding of autocomplete popup. r44152: [Mac] PDF icons for omnibox. r44145: GTK: Theme the icons in the location bar and use GTK colors fo... r44140: Strips http from the omnibox r44131: Fixes bugs in new tab strip animations where they weren't doin... r44116: Change the default theme colors. r44117: Add newline to EOF to fix CrOS builder. r44115: Make the bottom edges of the opaque frame rounded. r44091: [Mac] No star icon or page actions in omnibox on popups. r44087: Don't allow drag or click on location icon when editing in omn... r44021: [GTK] Add TTS lens graphic to linux TTS box. r44008: [Mac] Tweak location icon spacing in omnibox. r43977: GTK: don't show the star or page actions in ShouldOnlyShowLoca... r43972: Make the firstrun bubble point at a better spot now that the l... r43971: [Mac] Location icon in omnibox as drag source. r43970: Make the star and page action icons not appear on popup windows. r43954: Fixes bug in TabStrip where dragging tab out then back in rapidly r43864: Tweaks to BoundsAnimator/SlideAnimation and TabStrip: r43787: Allow location icon to be dragged & dropped. This also fixes ... r43759: Changes end cap of tab-to-search images. r43740: Change bookmark bar toggle to ctrl-shift-b. r43723: Show Page Info dialog on mouse up, not mouse down. r43677: Fix Mac build failure. r43676: Replace omnibox icons with new set that are all the same size ... r43596: Fix browser test TestStarButtonAccObj. r43593: Disables TestStarButtonAccObj. r43582: Changes tab strip to use BoundsAnimator for tab strip animatio... r43563: GTK: don't show reload button for popup/app windows. r43562: Star/reload shuffle, Windows version. r43540: [Mac] Magnifying glass in keyword-search bubble. r43482: Adds images needed for new tab animation. I'm separating this ... r43422: Add reload mask resource. r43392: GTK: make the location icon a drag source. r43376: [Mac] Move star button into page-actions area of omnibox. r43357: [Mac] Line up omnibox popup under field. r43290: gtk: fix display of icons in omnibox popup r43269: GTK: fix reload button. r43249: [Mac] Rearrange SSL status icon/label in omnibox. r43248: BrowserThemePack: Adds persistant ids for the reload endcaps. r43241: GTK: more location bar updates. r43191: Fix memory leak in BrowserThemePack. r43154: GTK: set the new star button's ID r43151: Fix bad conflict resolution for r43146. r43146: GTK: toolbar reload/star shuffle. r43025: Show the location bar icon (almost) all the time, and have its... r43023: Add new images for new reload button. No code change. r42782: Remove this icon, now that it's no longer used (due to my secu... r42502: Omnibox M5 work, part 1: Security changes r42245: Check in new icons for omnibox security changes alone, so that... BUG=none TEST=People go back to complaining about missing http://. R=pkasting@chromium.org,beng@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/net_util_unittest.cc')
-rw-r--r--net/base/net_util_unittest.cc205
1 files changed, 161 insertions, 44 deletions
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 0d10bb1..47fe251 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -364,7 +364,7 @@ struct UrlTestData {
const char* description;
const char* input;
const std::wstring languages;
- bool omit;
+ net::FormatUrlTypes format_types;
UnescapeRule::Type escape_rules;
const std::wstring output;
size_t prefix_len;
@@ -1267,74 +1267,78 @@ TEST(NetUtilTest, GetHostName) {
}
TEST(NetUtilTest, FormatUrl) {
+ net::FormatUrlTypes default_format_type = net::kFormatUrlOmitUsernamePassword;
const UrlTestData tests[] = {
- {"Empty URL", "", L"", true, UnescapeRule::NORMAL, L"", 0},
+ {"Empty URL", "", L"", default_format_type, UnescapeRule::NORMAL, L"", 0},
{"Simple URL",
- "http://www.google.com/", L"", true, UnescapeRule::NORMAL,
+ "http://www.google.com/", L"", default_format_type, UnescapeRule::NORMAL,
L"http://www.google.com/", 7},
{"With a port number and a reference",
- "http://www.google.com:8080/#\xE3\x82\xB0", L"", true,
+ "http://www.google.com:8080/#\xE3\x82\xB0", L"", default_format_type,
UnescapeRule::NORMAL,
L"http://www.google.com:8080/#\x30B0", 7},
// -------- IDN tests --------
{"Japanese IDN with ja",
- "http://xn--l8jvb1ey91xtjb.jp", L"ja", true, UnescapeRule::NORMAL,
- L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
+ UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
{"Japanese IDN with en",
- "http://xn--l8jvb1ey91xtjb.jp", L"en", true, UnescapeRule::NORMAL,
- L"http://xn--l8jvb1ey91xtjb.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"en", default_format_type,
+ UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7},
{"Japanese IDN without any languages",
- "http://xn--l8jvb1ey91xtjb.jp", L"", true, UnescapeRule::NORMAL,
+ "http://xn--l8jvb1ey91xtjb.jp", L"", default_format_type,
+ UnescapeRule::NORMAL,
// Single script is safe for empty languages.
L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
{"mailto: with Japanese IDN",
- "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", true, UnescapeRule::NORMAL,
+ "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
+ UnescapeRule::NORMAL,
// GURL doesn't assume an email address's domain part as a host name.
L"mailto:foo@xn--l8jvb1ey91xtjb.jp", 7},
{"file: with Japanese IDN",
- "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
+ "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
UnescapeRule::NORMAL,
L"file://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 7},
{"ftp: with Japanese IDN",
- "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
+ "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", default_format_type,
UnescapeRule::NORMAL,
L"ftp://\x671d\x65e5\x3042\x3055\x3072.jp/config.sys", 6},
// -------- omit_username_password flag tests --------
{"With username and password, omit_username_password=false",
- "http://user:passwd@example.com/foo", L"", false, UnescapeRule::NORMAL,
+ "http://user:passwd@example.com/foo", L"",
+ net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
L"http://user:passwd@example.com/foo", 19},
{"With username and password, omit_username_password=true",
- "http://user:passwd@example.com/foo", L"", true, UnescapeRule::NORMAL,
- L"http://example.com/foo", 7},
+ "http://user:passwd@example.com/foo", L"", default_format_type,
+ UnescapeRule::NORMAL, L"http://example.com/foo", 7},
{"With username and no password",
- "http://user@example.com/foo", L"", true, UnescapeRule::NORMAL,
- L"http://example.com/foo", 7},
+ "http://user@example.com/foo", L"", default_format_type,
+ UnescapeRule::NORMAL, L"http://example.com/foo", 7},
{"Just '@' without username and password",
- "http://@example.com/foo", L"", true, UnescapeRule::NORMAL,
+ "http://@example.com/foo", L"", default_format_type, UnescapeRule::NORMAL,
L"http://example.com/foo", 7},
// GURL doesn't think local-part of an email address is username for URL.
{"mailto:, omit_username_password=true",
- "mailto:foo@example.com", L"", true, UnescapeRule::NORMAL,
+ "mailto:foo@example.com", L"", default_format_type, UnescapeRule::NORMAL,
L"mailto:foo@example.com", 7},
// -------- unescape flag tests --------
{"Do not unescape",
"http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
"%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
UnescapeRule::NONE,
// GURL parses %-encoded hostnames into Punycode.
L"http://xn--qcka1pmc.jp/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
@@ -1343,38 +1347,59 @@ TEST(NetUtilTest, FormatUrl) {
{"Unescape normally",
"http://%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB.jp/"
"%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"
- "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", default_format_type,
UnescapeRule::NORMAL,
L"http://xn--qcka1pmc.jp/\x30B0\x30FC\x30B0\x30EB"
L"?q=\x30B0\x30FC\x30B0\x30EB", 7},
{"Unescape normally including unescape spaces",
- "http://www.google.com/search?q=Hello%20World", L"en", true,
- UnescapeRule::SPACES,
- L"http://www.google.com/search?q=Hello World", 7},
+ "http://www.google.com/search?q=Hello%20World", L"en", default_format_type,
+ UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7},
/*
{"unescape=true with some special characters",
- "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"", false, true,
+ "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"",
+ net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
L"http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", 25},
*/
// Disabled: the resultant URL becomes "...user%253A:%2540passwd...".
// -------- view-source: --------
{"view-source",
- "view-source:http://xn--qcka1pmc.jp/", L"ja", true, UnescapeRule::NORMAL,
- L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/", 12 + 7},
+ "view-source:http://xn--qcka1pmc.jp/", L"ja", default_format_type,
+ UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
+ 12 + 7},
{"view-source of view-source",
- "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja", true,
- UnescapeRule::NORMAL,
+ "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja",
+ default_format_type, UnescapeRule::NORMAL,
L"view-source:view-source:http://xn--qcka1pmc.jp/", 12},
+
+ // -------- omit http: --------
+ {"omit http with user name",
+ "http://user@example.com/foo", L"", net::kFormatUrlOmitAll,
+ UnescapeRule::NORMAL, L"example.com/foo", 0},
+
+ {"omit http",
+ "http://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
+ UnescapeRule::NORMAL, L"www.google.com/",
+ 0},
+
+ {"omit http with https",
+ "https://www.google.com/", L"en", net::kFormatUrlOmitHTTP,
+ UnescapeRule::NORMAL, L"https://www.google.com/",
+ 8},
+
+ {"omit http starts with ftp.",
+ "http://ftp.google.com/", L"en", net::kFormatUrlOmitHTTP,
+ UnescapeRule::NORMAL, L"http://ftp.google.com/",
+ 7},
};
for (size_t i = 0; i < arraysize(tests); ++i) {
size_t prefix_len;
std::wstring formatted = net::FormatUrl(
- GURL(tests[i].input), tests[i].languages, tests[i].omit,
+ GURL(tests[i].input), tests[i].languages, tests[i].format_types,
tests[i].escape_rules, NULL, &prefix_len, NULL);
EXPECT_EQ(tests[i].output, formatted) << tests[i].description;
EXPECT_EQ(tests[i].prefix_len, prefix_len) << tests[i].description;
@@ -1387,7 +1412,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
std::wstring formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", false, UnescapeRule::NONE, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
+ NULL);
EXPECT_EQ(L"http://%E3%82%B0:%E3%83%BC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/%E3%82%B0/?q=%E3%82%B0#\x30B0", formatted);
EXPECT_EQ(L"%E3%82%B0",
@@ -1407,7 +1433,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", false, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
+ NULL);
EXPECT_EQ(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/\x30B0/?q=\x30B0#\x30B0", formatted);
EXPECT_EQ(L"\x30B0",
@@ -1426,7 +1453,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
formatted = net::FormatUrl(
GURL("http://\xE3\x82\xB0:\xE3\x83\xBC@xn--qcka1pmc.jp:8080/"
"%E3%82%B0/?q=%E3%82%B0#\xE3\x82\xB0"),
- L"ja", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ &parsed, NULL, NULL);
EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080"
L"/\x30B0/?q=\x30B0#\x30B0", formatted);
EXPECT_FALSE(parsed.username.is_valid());
@@ -1442,7 +1470,8 @@ TEST(NetUtilTest, FormatUrlParsed) {
// View-source case.
formatted = net::FormatUrl(
GURL("view-source:http://user:passwd@host:81/path?query#ref"),
- L"", true, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ L"", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
+ NULL, NULL);
EXPECT_EQ(L"view-source:http://host:81/path?query#ref", formatted);
EXPECT_EQ(L"view-source:http",
formatted.substr(parsed.scheme.begin, parsed.scheme.len));
@@ -1453,6 +1482,50 @@ TEST(NetUtilTest, FormatUrlParsed) {
EXPECT_EQ(L"/path", formatted.substr(parsed.path.begin, parsed.path.len));
EXPECT_EQ(L"query", formatted.substr(parsed.query.begin, parsed.query.len));
EXPECT_EQ(L"ref", formatted.substr(parsed.ref.begin, parsed.ref.len));
+
+ // omit http case.
+ formatted = net::FormatUrl(
+ GURL("http://host:8000/a?b=c#d"),
+ L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(L"host:8000/a?b=c#d", formatted);
+ EXPECT_FALSE(parsed.scheme.is_valid());
+ EXPECT_FALSE(parsed.username.is_valid());
+ EXPECT_FALSE(parsed.password.is_valid());
+ EXPECT_EQ(L"host", formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
+
+ // omit http starts with ftp case.
+ formatted = net::FormatUrl(
+ GURL("http://ftp.host:8000/a?b=c#d"),
+ L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(L"http://ftp.host:8000/a?b=c#d", formatted);
+ EXPECT_TRUE(parsed.scheme.is_valid());
+ EXPECT_FALSE(parsed.username.is_valid());
+ EXPECT_FALSE(parsed.password.is_valid());
+ EXPECT_EQ(L"http", formatted.substr(parsed.scheme.begin, parsed.scheme.len));
+ EXPECT_EQ(L"ftp.host", formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(L"8000", formatted.substr(parsed.port.begin, parsed.port.len));
+ EXPECT_EQ(L"/a", formatted.substr(parsed.path.begin, parsed.path.len));
+ EXPECT_EQ(L"b=c", formatted.substr(parsed.query.begin, parsed.query.len));
+ EXPECT_EQ(L"d", formatted.substr(parsed.ref.begin, parsed.ref.len));
+
+ // omit http starts with 'f' case.
+ formatted = net::FormatUrl(
+ GURL("http://f/"),
+ L"", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL);
+ EXPECT_EQ(L"f/", formatted);
+ EXPECT_FALSE(parsed.scheme.is_valid());
+ EXPECT_FALSE(parsed.username.is_valid());
+ EXPECT_FALSE(parsed.password.is_valid());
+ EXPECT_FALSE(parsed.port.is_valid());
+ EXPECT_TRUE(parsed.path.is_valid());
+ EXPECT_FALSE(parsed.query.is_valid());
+ EXPECT_FALSE(parsed.ref.is_valid());
+ EXPECT_EQ(L"f", formatted.substr(parsed.host.begin, parsed.host.len));
+ EXPECT_EQ(L"/", formatted.substr(parsed.path.begin, parsed.path.len));
}
TEST(NetUtilTest, FormatUrlAdjustOffset) {
@@ -1472,8 +1545,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(basic_cases); ++i) {
size_t offset = basic_cases[i].input_offset;
- net::FormatUrl(GURL("http://www.google.com/foo/"), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://www.google.com/foo/"), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(basic_cases[i].output_offset, offset);
}
@@ -1495,8 +1569,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_auth_cases); ++i) {
size_t offset = omit_auth_cases[i].input_offset;
- net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(omit_auth_cases[i].output_offset, offset);
}
@@ -1514,8 +1589,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(view_source_cases); ++i) {
size_t offset = view_source_cases[i].input_offset;
- net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(view_source_cases[i].output_offset, offset);
}
@@ -1529,8 +1605,9 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(idn_hostname_cases); ++i) {
size_t offset = idn_hostname_cases[i].input_offset;
// "http://\x671d\x65e5\x3042\x3055\x3072.jp/foo/"
- net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja", true,
- UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja",
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
+ NULL, NULL, &offset);
EXPECT_EQ(idn_hostname_cases[i].output_offset, offset);
}
@@ -1551,7 +1628,8 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
// "http://www.google.com/foo bar/\x30B0\x30FC\x30B0\x30EB"
net::FormatUrl(GURL(
"http://www.google.com/foo%20bar/%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB"),
- L"en", true, UnescapeRule::SPACES, NULL, NULL, &offset);
+ L"en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL,
+ NULL, &offset);
EXPECT_EQ(unescape_cases[i].output_offset, offset);
}
@@ -1568,9 +1646,48 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) {
// "http://www.google.com/foo.html#\x30B0\x30B0z"
net::FormatUrl(GURL(
"http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), L"en",
- true, UnescapeRule::NORMAL, NULL, NULL, &offset);
+ net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL,
+ &offset);
EXPECT_EQ(ref_cases[i].output_offset, offset);
}
+
+ const AdjustOffsetCase omit_http_cases[] = {
+ {0, std::wstring::npos},
+ {3, std::wstring::npos},
+ {7, 0},
+ {8, 1},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_cases); ++i) {
+ size_t offset = omit_http_cases[i].input_offset;
+ net::FormatUrl(GURL("http://www.google.com"), L"en",
+ net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
+ EXPECT_EQ(omit_http_cases[i].output_offset, offset);
+ }
+
+ const AdjustOffsetCase omit_http_start_with_ftp[] = {
+ {0, 0},
+ {3, 3},
+ {8, 8},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_http_start_with_ftp); ++i) {
+ size_t offset = omit_http_start_with_ftp[i].input_offset;
+ net::FormatUrl(GURL("http://ftp.google.com"), L"en",
+ net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset);
+ EXPECT_EQ(omit_http_start_with_ftp[i].output_offset, offset);
+ }
+
+ const AdjustOffsetCase omit_all_cases[] = {
+ {12, 0},
+ {13, 1},
+ {0, std::wstring::npos},
+ {3, std::wstring::npos},
+ };
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(omit_all_cases); ++i) {
+ size_t offset = omit_all_cases[i].input_offset;
+ net::FormatUrl(GURL("http://user@foo.com/"), L"en", net::kFormatUrlOmitAll,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
+ EXPECT_EQ(omit_all_cases[i].output_offset, offset);
+ }
}
TEST(NetUtilTest, SimplifyUrlForRequest) {