summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc80
-rw-r--r--net/base/net_util.h42
-rw-r--r--net/base/net_util_unittest.cc160
3 files changed, 202 insertions, 80 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index a66d27a..099746b 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -707,10 +707,30 @@ bool IDNToUnicodeOneComponent(const char16* comp,
return false;
}
+// If |component| is valid, its begin is incremented by |delta|.
+void AdjustComponent(int delta, url_parse::Component* component) {
+ if (!component->is_valid())
+ return;
+
+ DCHECK(delta >= 0 || component->begin >= -delta);
+ component->begin += delta;
+}
+
+// Adjusts all the components of |parsed| by |delta|, except for the scheme.
+void AdjustComponents(int delta, url_parse::Parsed* parsed) {
+ AdjustComponent(delta, &(parsed->username));
+ AdjustComponent(delta, &(parsed->password));
+ AdjustComponent(delta, &(parsed->host));
+ AdjustComponent(delta, &(parsed->port));
+ AdjustComponent(delta, &(parsed->path));
+ AdjustComponent(delta, &(parsed->query));
+ AdjustComponent(delta, &(parsed->ref));
+}
+
// Helper for FormatUrl().
std::wstring FormatViewSourceUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ net::FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -725,8 +745,7 @@ std::wstring FormatViewSourceUrl(const GURL& url,
size_t* temp_offset_ptr = (*offset_for_adjustment < kViewSourceLengthPlus1) ?
NULL : &temp_offset;
std::wstring result = net::FormatUrl(real_url, languages,
- omit_username_password, unescape_rules, new_parsed, prefix_end,
- temp_offset_ptr);
+ format_types, unescape_rules, new_parsed, prefix_end, temp_offset_ptr);
result.insert(0, kWideViewSource);
// Adjust position values.
@@ -737,20 +756,7 @@ std::wstring FormatViewSourceUrl(const GURL& url,
new_parsed->scheme.begin = 0;
new_parsed->scheme.len = kViewSourceLengthPlus1 - 1;
}
- if (new_parsed->username.is_nonempty())
- new_parsed->username.begin += kViewSourceLengthPlus1;
- if (new_parsed->password.is_nonempty())
- new_parsed->password.begin += kViewSourceLengthPlus1;
- if (new_parsed->host.is_nonempty())
- new_parsed->host.begin += kViewSourceLengthPlus1;
- if (new_parsed->port.is_nonempty())
- new_parsed->port.begin += kViewSourceLengthPlus1;
- if (new_parsed->path.is_nonempty())
- new_parsed->path.begin += kViewSourceLengthPlus1;
- if (new_parsed->query.is_nonempty())
- new_parsed->query.begin += kViewSourceLengthPlus1;
- if (new_parsed->ref.is_nonempty())
- new_parsed->ref.begin += kViewSourceLengthPlus1;
+ AdjustComponents(kViewSourceLengthPlus1, new_parsed);
if (prefix_end)
*prefix_end += kViewSourceLengthPlus1;
if (temp_offset_ptr) {
@@ -764,6 +770,12 @@ std::wstring FormatViewSourceUrl(const GURL& url,
namespace net {
+const FormatUrlType kFormatUrlOmitNothing = 0;
+const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0;
+const FormatUrlType kFormatUrlOmitHTTP = 1 << 1;
+const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword |
+ kFormatUrlOmitHTTP;
+
std::set<int> explicitly_allowed_ports;
// Appends the substring |in_component| inside of the URL |spec| to |output|,
@@ -1372,7 +1384,7 @@ void AppendFormattedComponent(const std::string& spec,
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -1401,7 +1413,7 @@ std::wstring FormatUrl(const GURL& url,
// Rejects view-source:view-source:... to avoid deep recursive call.
if (url.SchemeIs(kViewSource) &&
!StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) {
- return FormatViewSourceUrl(url, languages, omit_username_password,
+ return FormatViewSourceUrl(url, languages, format_types,
unescape_rules, new_parsed, prefix_end, offset_for_adjustment);
}
@@ -1418,9 +1430,15 @@ std::wstring FormatUrl(const GURL& url,
spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME,
true),
std::back_inserter(url_string));
+
+ const wchar_t* const kHTTP = L"http://";
+ const size_t kHTTPSize = std::wstring(kHTTP).size();
+ bool omit_http = ((format_types & kFormatUrlOmitHTTP) != 0 &&
+ url_string == kHTTP);
+
new_parsed->scheme = parsed.scheme;
- if (omit_username_password) {
+ if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
// Remove the username and password fields. We don't want to display those
// to the user since they can be used for attacks,
// e.g. "http://google.com:search@evil.ru/"
@@ -1520,6 +1538,26 @@ std::wstring FormatUrl(const GURL& url,
}
}
+ // If we need to strip out http do it after the fact. This way we don't need
+ // to worry about how offset_for_adjustment is interpreted.
+ if (omit_http && !url_string.compare(0, kHTTPSize, kHTTP)) {
+ url_string = url_string.substr(kHTTPSize);
+ if (*offset_for_adjustment != std::wstring::npos) {
+ if (*offset_for_adjustment < kHTTPSize)
+ *offset_for_adjustment = std::wstring::npos;
+ else
+ *offset_for_adjustment -= kHTTPSize;
+ }
+ if (prefix_end)
+ *prefix_end -= kHTTPSize;
+
+ // Adjust new_parsed.
+ DCHECK(new_parsed->scheme.is_valid());
+ int delta = -(new_parsed->scheme.len + 3); // +3 for ://.
+ new_parsed->scheme.reset();
+ AdjustComponents(delta, new_parsed);
+ }
+
return url_string;
}
diff --git a/net/base/net_util.h b/net/base/net_util.h
index f614eb6..53314bf 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,6 +36,22 @@ struct Parsed;
namespace net {
+// Used by FormatUrl to specify handling of certain parts of the url.
+typedef uint32 FormatUrlType;
+typedef uint32 FormatUrlTypes;
+
+// Nothing is ommitted.
+extern const FormatUrlType kFormatUrlOmitNothing;
+
+// If set, any username and password are removed.
+extern const FormatUrlType kFormatUrlOmitUsernamePassword;
+
+// If the scheme is 'http://', it's removed.
+extern const FormatUrlType kFormatUrlOmitHTTP;
+
+// Convenience for omitting all unecessary types.
+extern const FormatUrlType kFormatUrlOmitAll;
+
// Holds a list of ports that should be accepted despite bans.
extern std::set<int> explicitly_allowed_ports;
@@ -245,13 +261,12 @@ void AppendFormattedHost(const GURL& url,
size_t* offset_for_adjustment);
// Creates a string representation of |url|. The IDN host name may be in Unicode
-// if |languages| accepts the Unicode representation. If
-// |omit_username_password| is true, any username and password are removed.
-// |unescape_rules| defines how to clean the URL for human readability.
-// You will generally want |UnescapeRule::SPACES| for display to the user if you
-// can handle spaces, or |UnescapeRule::NORMAL| if not. If the path part and the
-// query part seem to be encoded in %-encoded UTF-8, decodes %-encoding and
-// UTF-8.
+// if |languages| accepts the Unicode representation. |format_type| is a bitmask
+// of FormatUrlTypes, see it for details. |unescape_rules| defines how to clean
+// the URL for human readability. You will generally want |UnescapeRule::SPACES|
+// for display to the user if you can handle spaces, or |UnescapeRule::NORMAL|
+// if not. If the path part and the query part seem to be encoded in %-encoded
+// UTF-8, decodes %-encoding and UTF-8.
//
// The last three parameters may be NULL.
// |new_parsed| will be set to the parsing parameters of the resultant URL.
@@ -267,18 +282,17 @@ void AppendFormattedHost(const GURL& url,
// std::wstring::npos.
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- bool omit_username_password,
+ FormatUrlTypes format_types,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
size_t* offset_for_adjustment);
-// Creates a string representation of |url| for display to the user.
-// This is a shorthand of the above function with omit_username_password=true,
-// unescape=SPACES, new_parsed=NULL, and prefix_end=NULL.
+// This is a convenience for FormatUrl with
+// format_types=kFormatUrlOmitUsernamePassword and unescape=SPACES.
inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) {
- return FormatUrl(url, languages, true, UnescapeRule::SPACES, NULL, NULL,
- NULL);
+ return FormatUrl(url, languages, kFormatUrlOmitUsernamePassword,
+ UnescapeRule::SPACES, NULL, NULL, NULL);
}
// Strip the portions of |url| that aren't core to the network request.
diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc
index 833375c..4c1ae52 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -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,54 @@ 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},
};
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 +1407,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 +1428,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 +1448,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 +1465,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 +1477,20 @@ 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));
}
TEST(NetUtilTest, FormatUrlAdjustOffset) {
@@ -1472,8 +1510,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 +1534,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 +1554,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 +1570,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 +1593,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 +1611,36 @@ 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_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) {