summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-22 00:03:07 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-22 00:03:07 +0000
commitc5b90374f3e454dbc5d5f2a4f23c49e7cba93147 (patch)
tree5d7980ec19bf794793fc31dcb1aa1245bc29f897 /net
parenta32abb551892ef6a9987a5372b3c9896adb7a55e (diff)
downloadchromium_src-c5b90374f3e454dbc5d5f2a4f23c49e7cba93147.zip
chromium_src-c5b90374f3e454dbc5d5f2a4f23c49e7cba93147.tar.gz
chromium_src-c5b90374f3e454dbc5d5f2a4f23c49e7cba93147.tar.bz2
Temporarily revert certain Omnibox, toolbar, tab animations, and other
UI changes for purposes of testing and merging into mstone-5. Also ++kThemePackVersion and regenerate the cached theme pak. Reverted 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=Eyjafjallajokull R=pkasting@chromium.org,beng@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45267 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/net_util.cc93
-rw-r--r--net/base/net_util.h42
-rw-r--r--net/base/net_util_unittest.cc207
3 files changed, 80 insertions, 262 deletions
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index b251ee1..a66d27a 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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,30 +707,10 @@ 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,
- net::FormatUrlTypes format_types,
+ bool omit_username_password,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -745,7 +725,8 @@ 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,
- format_types, unescape_rules, new_parsed, prefix_end, temp_offset_ptr);
+ omit_username_password, unescape_rules, new_parsed, prefix_end,
+ temp_offset_ptr);
result.insert(0, kWideViewSource);
// Adjust position values.
@@ -756,7 +737,20 @@ std::wstring FormatViewSourceUrl(const GURL& url,
new_parsed->scheme.begin = 0;
new_parsed->scheme.len = kViewSourceLengthPlus1 - 1;
}
- AdjustComponents(kViewSourceLengthPlus1, new_parsed);
+ 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;
if (prefix_end)
*prefix_end += kViewSourceLengthPlus1;
if (temp_offset_ptr) {
@@ -770,12 +764,6 @@ 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|,
@@ -1384,7 +1372,7 @@ void AppendFormattedComponent(const std::string& spec,
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- FormatUrlTypes format_types,
+ bool omit_username_password,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
@@ -1392,8 +1380,6 @@ std::wstring FormatUrl(const GURL& url,
url_parse::Parsed parsed_temp;
if (!new_parsed)
new_parsed = &parsed_temp;
- else
- *new_parsed = url_parse::Parsed();
size_t offset_temp = std::wstring::npos;
if (!offset_for_adjustment)
offset_for_adjustment = &offset_temp;
@@ -1415,7 +1401,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, format_types,
+ return FormatViewSourceUrl(url, languages, omit_username_password,
unescape_rules, new_parsed, prefix_end, offset_for_adjustment);
}
@@ -1432,26 +1418,9 @@ 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 char* const kFTP = "ftp.";
- const size_t kHTTPSize = std::wstring(kHTTP).size();
- // The omnibox treats ftp.foo.com as ftp://foo.com. This means that if we
- // trimmed http off a string that starts with http://ftp and the user tried to
- // reload the page the user would end up with a scheme of ftp://. For example,
- // 'http://ftp.foo.com' -> 'ftp.foo.com' -> 'ftp://foo.com'. For this reason
- // don't strip http off url's whose scheme is http and the host starts with
- // 'ftp.'.
- bool omit_http =
- ((format_types & kFormatUrlOmitHTTP) != 0 &&
- url_string == kHTTP && (!parsed.host.is_valid() ||
- (parsed.host.is_nonempty() &&
- spec.compare(parsed.host.begin,
- std::string(kFTP).size(), kFTP))));
-
new_parsed->scheme = parsed.scheme;
- if ((format_types & kFormatUrlOmitUsernamePassword) != 0) {
+ if (omit_username_password) {
// 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/"
@@ -1551,26 +1520,6 @@ 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 53314bf..f614eb6 100644
--- a/net/base/net_util.h
+++ b/net/base/net_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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,22 +36,6 @@ 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;
@@ -261,12 +245,13 @@ 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. |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.
+// 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.
//
// The last three parameters may be NULL.
// |new_parsed| will be set to the parsing parameters of the resultant URL.
@@ -282,17 +267,18 @@ void AppendFormattedHost(const GURL& url,
// std::wstring::npos.
std::wstring FormatUrl(const GURL& url,
const std::wstring& languages,
- FormatUrlTypes format_types,
+ bool omit_username_password,
UnescapeRule::Type unescape_rules,
url_parse::Parsed* new_parsed,
size_t* prefix_end,
size_t* offset_for_adjustment);
-// This is a convenience for FormatUrl with
-// format_types=kFormatUrlOmitUsernamePassword and unescape=SPACES.
+// 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.
inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) {
- return FormatUrl(url, languages, kFormatUrlOmitUsernamePassword,
- UnescapeRule::SPACES, NULL, NULL, NULL);
+ return FormatUrl(url, languages, true, 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 30ab0b99..833375c 100644
--- a/net/base/net_util_unittest.cc
+++ b/net/base/net_util_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 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;
- net::FormatUrlTypes format_types;
+ bool omit;
UnescapeRule::Type escape_rules;
const std::wstring output;
size_t prefix_len;
@@ -1267,78 +1267,74 @@ TEST(NetUtilTest, GetHostName) {
}
TEST(NetUtilTest, FormatUrl) {
- net::FormatUrlTypes default_format_type = net::kFormatUrlOmitUsernamePassword;
const UrlTestData tests[] = {
- {"Empty URL", "", L"", default_format_type, UnescapeRule::NORMAL, L"", 0},
+ {"Empty URL", "", L"", true, UnescapeRule::NORMAL, L"", 0},
{"Simple URL",
- "http://www.google.com/", L"", default_format_type, UnescapeRule::NORMAL,
+ "http://www.google.com/", L"", true, UnescapeRule::NORMAL,
L"http://www.google.com/", 7},
{"With a port number and a reference",
- "http://www.google.com:8080/#\xE3\x82\xB0", L"", default_format_type,
+ "http://www.google.com:8080/#\xE3\x82\xB0", L"", true,
UnescapeRule::NORMAL,
L"http://www.google.com:8080/#\x30B0", 7},
// -------- IDN tests --------
{"Japanese IDN with ja",
- "http://xn--l8jvb1ey91xtjb.jp", L"ja", default_format_type,
- UnescapeRule::NORMAL, L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"ja", true, UnescapeRule::NORMAL,
+ L"http://\x671d\x65e5\x3042\x3055\x3072.jp/", 7},
{"Japanese IDN with en",
- "http://xn--l8jvb1ey91xtjb.jp", L"en", default_format_type,
- UnescapeRule::NORMAL, L"http://xn--l8jvb1ey91xtjb.jp/", 7},
+ "http://xn--l8jvb1ey91xtjb.jp", L"en", true, UnescapeRule::NORMAL,
+ L"http://xn--l8jvb1ey91xtjb.jp/", 7},
{"Japanese IDN without any languages",
- "http://xn--l8jvb1ey91xtjb.jp", L"", default_format_type,
- UnescapeRule::NORMAL,
+ "http://xn--l8jvb1ey91xtjb.jp", L"", true, 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", default_format_type,
- UnescapeRule::NORMAL,
+ "mailto:foo@xn--l8jvb1ey91xtjb.jp", L"ja", true, 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", default_format_type,
+ "file://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
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", default_format_type,
+ "ftp://xn--l8jvb1ey91xtjb.jp/config.sys", L"ja", true,
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"",
- net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
+ "http://user:passwd@example.com/foo", L"", false, 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"", default_format_type,
- UnescapeRule::NORMAL, L"http://example.com/foo", 7},
+ "http://user:passwd@example.com/foo", L"", true, UnescapeRule::NORMAL,
+ L"http://example.com/foo", 7},
{"With username and no password",
- "http://user@example.com/foo", L"", default_format_type,
- UnescapeRule::NORMAL, L"http://example.com/foo", 7},
+ "http://user@example.com/foo", L"", true, UnescapeRule::NORMAL,
+ L"http://example.com/foo", 7},
{"Just '@' without username and password",
- "http://@example.com/foo", L"", default_format_type, UnescapeRule::NORMAL,
+ "http://@example.com/foo", L"", true, 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"", default_format_type, UnescapeRule::NORMAL,
+ "mailto:foo@example.com", L"", true, 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", default_format_type,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
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"
@@ -1347,59 +1343,38 @@ 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", default_format_type,
+ "?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", L"en", true,
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", default_format_type,
- UnescapeRule::SPACES, L"http://www.google.com/search?q=Hello World", 7},
+ "http://www.google.com/search?q=Hello%20World", L"en", true,
+ 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"",
- net::kFormatUrlOmitNothing, UnescapeRule::NORMAL,
+ "http://user%3A:%40passwd@example.com/foo%3Fbar?q=b%26z", L"", false, true,
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", default_format_type,
- UnescapeRule::NORMAL, L"view-source:http://\x30B0\x30FC\x30B0\x30EB.jp/",
- 12 + 7},
+ "view-source:http://xn--qcka1pmc.jp/", L"ja", true, 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",
- default_format_type, UnescapeRule::NORMAL,
+ "view-source:view-source:http://xn--qcka1pmc.jp/", L"ja", true,
+ 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].format_types,
+ GURL(tests[i].input), tests[i].languages, tests[i].omit,
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;
@@ -1412,8 +1387,7 @@ 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", net::kFormatUrlOmitNothing, UnescapeRule::NONE, &parsed, NULL,
- NULL);
+ L"ja", false, 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",
@@ -1433,8 +1407,7 @@ 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", net::kFormatUrlOmitNothing, UnescapeRule::NORMAL, &parsed, NULL,
- NULL);
+ L"ja", false, 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",
@@ -1453,8 +1426,7 @@ 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", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- &parsed, NULL, NULL);
+ L"ja", true, 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());
@@ -1470,8 +1442,7 @@ TEST(NetUtilTest, FormatUrlParsed) {
// View-source case.
formatted = net::FormatUrl(
GURL("view-source:http://user:passwd@host:81/path?query#ref"),
- L"", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed,
- NULL, NULL);
+ L"", true, 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));
@@ -1482,50 +1453,6 @@ 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) {
@@ -1545,9 +1472,8 @@ 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",
- net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://www.google.com/foo/"), L"en", true,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(basic_cases[i].output_offset, offset);
}
@@ -1569,9 +1495,8 @@ 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",
- net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- NULL, NULL, &offset);
+ net::FormatUrl(GURL(omit_auth_cases[i].input_url), L"en", true,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(omit_auth_cases[i].output_offset, offset);
}
@@ -1589,9 +1514,8 @@ 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",
- net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- NULL, NULL, &offset);
+ net::FormatUrl(GURL("view-source:http://foo@www.google.com/"), L"en", true,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(view_source_cases[i].output_offset, offset);
}
@@ -1605,9 +1529,8 @@ 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",
- net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL,
- NULL, NULL, &offset);
+ net::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), L"ja", true,
+ UnescapeRule::NORMAL, NULL, NULL, &offset);
EXPECT_EQ(idn_hostname_cases[i].output_offset, offset);
}
@@ -1628,8 +1551,7 @@ 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", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL,
- NULL, &offset);
+ L"en", true, UnescapeRule::SPACES, NULL, NULL, &offset);
EXPECT_EQ(unescape_cases[i].output_offset, offset);
}
@@ -1646,48 +1568,9 @@ 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",
- net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL,
- &offset);
+ true, 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) {