diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 06:14:17 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-31 06:14:17 +0000 |
commit | 9f284f13fd93a37bd8afa4840e91a953f4c9bc51 (patch) | |
tree | 4a5e7e73c5ed978b2e18569080a70c18a821da76 | |
parent | f33fdc5d17ae9e0439d2e68344da6d5f12dc26a5 (diff) | |
download | chromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.zip chromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.tar.gz chromium_src-9f284f13fd93a37bd8afa4840e91a953f4c9bc51.tar.bz2 |
Remove the wstring FormatUrl() functions (and convert remaining users to the string16 verison).
Still to do: Actually convert the code underlying FormatUrl().
BUG=23581
TEST=builds and passes tests
Review URL: http://codereview.chromium.org/3263005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57968 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 449 insertions, 617 deletions
diff --git a/app/text_elider.cc b/app/text_elider.cc index 995ac95..549e1c2 100644 --- a/app/text_elider.cc +++ b/app/text_elider.cc @@ -64,8 +64,9 @@ std::wstring ElideUrl(const GURL& url, const std::wstring& languages) { // Get a formatted string and corresponding parsing of the url. url_parse::Parsed parsed; - std::wstring url_string = net::FormatUrl(url, languages, - net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, NULL, NULL); + std::wstring url_string = UTF16ToWideHack(net::FormatUrl(url, + WideToUTF8(languages), net::kFormatUrlOmitAll, UnescapeRule::SPACES, + &parsed, NULL, NULL)); if (available_pixel_width <= 0) return url_string; @@ -377,6 +378,7 @@ std::wstring ElideText(const std::wstring& text, return CutString(text, lo, elide_in_middle, true); } +// TODO(viettrungluu): convert |languages| to an |std::string|. SortedDisplayURL::SortedDisplayURL(const GURL& url, const std::wstring& languages) { std::wstring host; @@ -384,9 +386,9 @@ SortedDisplayURL::SortedDisplayURL(const GURL& url, sort_host_ = WideToUTF16Hack(host); string16 host_minus_www = WideToUTF16Hack(net::StripWWW(host)); url_parse::Parsed parsed; - display_url_ = WideToUTF16Hack(net::FormatUrl(url, languages, + display_url_ = net::FormatUrl(url, WideToUTF8(languages), net::kFormatUrlOmitAll, UnescapeRule::SPACES, &parsed, &prefix_end_, - NULL)); + NULL); if (sort_host_.length() > host_minus_www.length()) { prefix_end_ += sort_host_.length() - host_minus_www.length(); sort_host_.swap(host_minus_www); diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index a66c84a..e69d413 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -648,14 +648,13 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() { std::wstring AutocompleteProvider::StringForURLDisplay(const GURL& url, bool check_accept_lang, bool trim_http) const { - std::wstring languages = (check_accept_lang && profile_) ? - UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)) : - std::wstring(); - return net::FormatUrl( + std::string languages = (check_accept_lang && profile_) ? + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string(); + return UTF16ToWideHack(net::FormatUrl( url, languages, net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP), - UnescapeRule::SPACES, NULL, NULL, NULL); + UnescapeRule::SPACES, NULL, NULL, NULL)); } // AutocompleteResult --------------------------------------------------------- diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index c2a2bca..20718f7 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -876,23 +876,24 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( DCHECK(match.destination_url.is_valid()); size_t inline_autocomplete_offset = history_match.input_location + params->input.text().length(); + std::string languages = (match_type == WHAT_YOU_TYPED) ? + std::string() : WideToUTF8(params->languages); const net::FormatUrlTypes format_types = net::kFormatUrlOmitAll & ~((params->trim_http && !history_match.match_in_scheme) ? 0 : net::kFormatUrlOmitHTTP); match.fill_into_edit = AutocompleteInput::FormattedStringWithEquivalentMeaning(info.url(), - net::FormatUrl(info.url(), match_type == WHAT_YOU_TYPED ? - std::wstring() : params->languages, format_types, UnescapeRule::SPACES, - NULL, NULL, &inline_autocomplete_offset)); + UTF16ToWideHack(net::FormatUrl(info.url(), languages, format_types, + UnescapeRule::SPACES, NULL, NULL, + &inline_autocomplete_offset))); if (!params->input.prevent_inline_autocomplete()) match.inline_autocomplete_offset = inline_autocomplete_offset; DCHECK((match.inline_autocomplete_offset == std::wstring::npos) || (match.inline_autocomplete_offset <= match.fill_into_edit.length())); size_t match_start = history_match.input_location; - match.contents = net::FormatUrl(info.url(), - match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages, - format_types, UnescapeRule::SPACES, NULL, NULL, &match_start); + match.contents = UTF16ToWideHack(net::FormatUrl(info.url(), languages, + format_types, UnescapeRule::SPACES, NULL, NULL, &match_start)); if ((match_start != std::wstring::npos) && (inline_autocomplete_offset != std::wstring::npos) && (inline_autocomplete_offset != match_start)) { diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 89b5ea0..ebcf1da 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1415,7 +1415,7 @@ void Browser::WriteCurrentURLToClipboard() { chrome_browser_net::WriteURLToClipboard( contents->GetURL(), - UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), g_browser_process->clipboard()); } diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc index 8183106..0434a99 100644 --- a/chrome/browser/geolocation/geolocation_permission_context.cc +++ b/chrome/browser/geolocation/geolocation_permission_context.cc @@ -92,7 +92,7 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { TabContents* tab_contents, GeolocationInfoBarQueueController* controller, int render_process_id, int render_view_id, int bridge_id, const GURL& requesting_frame_url, - const std::wstring& display_languages) + const std::string& display_languages) : ConfirmInfoBarDelegate(tab_contents), tab_contents_(tab_contents), controller_(controller), @@ -128,8 +128,7 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { virtual string16 GetMessageText() const { return l10n_util::GetStringFUTF16( IDS_GEOLOCATION_INFOBAR_QUESTION, - WideToUTF16Hack(net::FormatUrl(requesting_frame_url_.GetOrigin(), - display_languages_))); + net::FormatUrl(requesting_frame_url_.GetOrigin(), display_languages_)); } virtual SkBitmap* GetIcon() const { return ResourceBundle::GetSharedInstance().GetBitmapNamed( @@ -160,7 +159,7 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { int render_view_id_; int bridge_id_; GURL requesting_frame_url_; - std::wstring display_languages_; + std::string display_languages_; DISALLOW_IMPLICIT_CONSTRUCTORS(GeolocationConfirmInfoBarDelegate); }; @@ -298,7 +297,7 @@ void GeolocationInfoBarQueueController::ShowQueuedInfoBar( tab_contents, this, render_process_id, render_view_id, i->bridge_id, i->requesting_frame, - UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages))); + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); tab_contents->AddInfoBar(i->infobar_delegate); break; } diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc index d07f9a6..b3d5da9 100644 --- a/chrome/browser/history/in_memory_history_backend.cc +++ b/chrome/browser/history/in_memory_history_backend.cc @@ -42,7 +42,7 @@ bool InMemoryHistoryBackend::Init(const FilePath& history_filename, index_.reset(new InMemoryURLIndex()); base::TimeTicks beginning_time = base::TimeTicks::Now(); // TODO(mrossetti): Provide languages when profile is available. - index_->Init(db, NULL); + index_->Init(db, std::string()); UMA_HISTOGRAM_TIMES("Autocomplete.HistoryDatabaseIndexingTime", base::TimeTicks::Now() - beginning_time); } diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc index a9f55ab..5715d39 100644 --- a/chrome/browser/history/in_memory_url_index.cc +++ b/chrome/browser/history/in_memory_url_index.cc @@ -28,9 +28,9 @@ InMemoryURLIndex::~InMemoryURLIndex() {} // Indexing bool InMemoryURLIndex::Init(history::URLDatabase* history_db, - const string16* languages) { + const std::string& languages) { // TODO(mrossetti): Register for profile/language change notifications. - languages_ = *languages; + languages_ = languages; // Reset our indexes. char_word_map_.clear(); word_id_history_map_.clear(); @@ -56,10 +56,10 @@ bool InMemoryURLIndex::Init(history::URLDatabase* history_db, bool InMemoryURLIndex::IndexRow(URLRow row) { const GURL& gurl(row.url()); - string16 url(WideToUTF16(net::FormatUrl(gurl, UTF16ToWide(languages_), + string16 url(net::FormatUrl(gurl, languages_, net::kFormatUrlOmitUsernamePassword, - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, NULL, NULL, - NULL))); + UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, + NULL, NULL, NULL)); // TODO(mrossetti): Find or implement a ConvertPercentEncoding and use it // on the url. diff --git a/chrome/browser/history/in_memory_url_index.h b/chrome/browser/history/in_memory_url_index.h index 2b89d02..5f7ee3a 100644 --- a/chrome/browser/history/in_memory_url_index.h +++ b/chrome/browser/history/in_memory_url_index.h @@ -8,6 +8,7 @@ #include <map> #include <set> +#include <string> #include <vector> #include "app/sql/connection.h" @@ -55,7 +56,7 @@ class InMemoryURLIndex { typedef std::vector<string16> String16Vector; // Open and index the URL history database. - bool Init(URLDatabase* history_db, const string16* languages); + bool Init(URLDatabase* history_db, const std::string& languages); // Reset the history index. void Reset(); @@ -158,7 +159,7 @@ class InMemoryURLIndex { WordIDHistoryMap word_id_history_map_; TermCharWordSetVector term_char_word_set_cache_; HistoryInfoMap history_info_map_; - string16 languages_; + std::string languages_; DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); }; diff --git a/chrome/browser/history/in_memory_url_index_unittest.cc b/chrome/browser/history/in_memory_url_index_unittest.cc index 8c808f9..f399496 100644 --- a/chrome/browser/history/in_memory_url_index_unittest.cc +++ b/chrome/browser/history/in_memory_url_index_unittest.cc @@ -118,8 +118,7 @@ TEST_F(InMemoryURLIndexTest, Initialization) { while (statement.Step()) ++row_count; EXPECT_EQ(29U, row_count); url_index_.reset(new InMemoryURLIndex); - string16 languages = UTF8ToUTF16("en,ja,hi,zh"); - url_index_->Init(this, &languages); + url_index_->Init(this, "en,ja,hi,zh"); // There should have been 25 of the 29 urls accepted during filtering. EXPECT_EQ(25U, url_index_->history_item_count_); diff --git a/chrome/browser/net/browser_url_util.cc b/chrome/browser/net/browser_url_util.cc index 24747b2..786ab7d 100644 --- a/chrome/browser/net/browser_url_util.cc +++ b/chrome/browser/net/browser_url_util.cc @@ -14,7 +14,7 @@ namespace chrome_browser_net { void WriteURLToClipboard(const GURL& url, - const std::wstring& languages, + const std::string& languages, Clipboard *clipboard) { if (url.is_empty() || !url.is_valid() || !clipboard) return; @@ -23,8 +23,8 @@ void WriteURLToClipboard(const GURL& url, // may not encode non-ASCII characters in UTF-8. See crbug.com/2820. string16 text = url.SchemeIs(chrome::kMailToScheme) ? ASCIIToUTF16(url.path()) : - WideToUTF16(net::FormatUrl(url, languages, net::kFormatUrlOmitNothing, - UnescapeRule::NONE, NULL, NULL, NULL)); + net::FormatUrl(url, languages, net::kFormatUrlOmitNothing, + UnescapeRule::NONE, NULL, NULL, NULL); ScopedClipboardWriter scw(clipboard); scw.WriteURL(text); diff --git a/chrome/browser/net/browser_url_util.h b/chrome/browser/net/browser_url_util.h index 93c96c0..043725f7 100644 --- a/chrome/browser/net/browser_url_util.h +++ b/chrome/browser/net/browser_url_util.h @@ -15,7 +15,7 @@ namespace chrome_browser_net { // Writes a string representation of |url| to the system clipboard. void WriteURLToClipboard(const GURL& url, - const std::wstring& languages, + const std::string& languages, Clipboard *clipboard); } // namespace chrome_browser_net diff --git a/chrome/browser/net/url_fixer_upper.cc b/chrome/browser/net/url_fixer_upper.cc index 3aad8f2..ee8d00b 100644 --- a/chrome/browser/net/url_fixer_upper.cc +++ b/chrome/browser/net/url_fixer_upper.cc @@ -170,7 +170,7 @@ static std::string FixupPath(const std::string& text) { // Here, we know the input looks like a file. GURL file_url = net::FilePathToFileURL(FilePath(filename)); if (file_url.is_valid()) { - return WideToUTF8(net::FormatUrl(file_url, std::wstring(), + return UTF16ToUTF8(net::FormatUrl(file_url, std::string(), net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, NULL)); } @@ -568,7 +568,7 @@ GURL URLFixerUpper::FixupRelativeFile(const FilePath& base_dir, if (is_file) { GURL file_url = net::FilePathToFileURL(full_path); if (file_url.is_valid()) - return GURL(WideToUTF8(net::FormatUrl(file_url, std::wstring(), + return GURL(UTF16ToUTF8(net::FormatUrl(file_url, std::string(), net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, NULL))); // Invalid files fall through to regular processing. diff --git a/chrome/browser/tab_contents/navigation_controller.cc b/chrome/browser/tab_contents/navigation_controller.cc index e1667e2..a416bc9 100644 --- a/chrome/browser/tab_contents/navigation_controller.cc +++ b/chrome/browser/tab_contents/navigation_controller.cc @@ -250,9 +250,9 @@ NavigationEntry* NavigationController::CreateNavigationEntry( // Use the filename as the title, not the full path. // We need to call FormatUrl() to perform URL de-escaping; // it's a bit ugly to grab the filename out of the resulting string. - std::wstring languages = UTF8ToWide(profile->GetPrefs()->GetString( - prefs::kAcceptLanguages)); - std::wstring formatted = net::FormatUrl(url, languages); + std::string languages = + profile->GetPrefs()->GetString(prefs::kAcceptLanguages); + std::wstring formatted = UTF16ToWideHack(net::FormatUrl(url, languages)); std::wstring filename = FilePath::FromWStringHack(formatted).BaseName().ToWStringHack(); entry->set_title(WideToUTF16Hack(filename)); diff --git a/chrome/browser/tab_contents/navigation_entry.cc b/chrome/browser/tab_contents/navigation_entry.cc index 0933f1e..c345958 100644 --- a/chrome/browser/tab_contents/navigation_entry.cc +++ b/chrome/browser/tab_contents/navigation_entry.cc @@ -89,20 +89,20 @@ const string16& NavigationEntry::GetTitleForDisplay( return cached_display_title_; // Use the virtual URL first if any, and fall back on using the real URL. - std::wstring languages; + std::string languages; if (navigation_controller) { - languages = UTF8ToWide(navigation_controller->profile()->GetPrefs()-> - GetString(prefs::kAcceptLanguages)); + languages = navigation_controller->profile()->GetPrefs()-> + GetString(prefs::kAcceptLanguages); } - std::wstring title; + string16 title; std::wstring elided_title; if (!virtual_url_.is_empty()) { title = net::FormatUrl(virtual_url_, languages); } else if (!url_.is_empty()) { title = net::FormatUrl(url_, languages); } - ElideString(title, chrome::kMaxTitleChars, &elided_title); + ElideString(UTF16ToWideHack(title), chrome::kMaxTitleChars, &elided_title); cached_display_title_ = WideToUTF16Hack(elided_title); return cached_display_title_; } diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 5b8151d..84ba4c4 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -1454,7 +1454,7 @@ void RenderViewContextMenu::Inspect(int x, int y) { void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { chrome_browser_net::WriteURLToClipboard( url, - UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), g_browser_process->clipboard()); } diff --git a/chrome/browser/toolbar_model.cc b/chrome/browser/toolbar_model.cc index 5d6185b..e8cdaaf 100644 --- a/chrome/browser/toolbar_model.cc +++ b/chrome/browser/toolbar_model.cc @@ -33,13 +33,12 @@ ToolbarModel::~ToolbarModel() { // ToolbarModel Implementation. std::wstring ToolbarModel::GetText() const { GURL url(chrome::kAboutBlankURL); - std::wstring languages; // Empty if we don't have a |navigation_controller|. + std::string languages; // Empty if we don't have a |navigation_controller|. NavigationController* navigation_controller = GetNavigationController(); if (navigation_controller) { - languages = UTF8ToWide( - navigation_controller->profile()->GetPrefs()->GetString( - prefs::kAcceptLanguages)); + languages = navigation_controller->profile()->GetPrefs()->GetString( + prefs::kAcceptLanguages); NavigationEntry* entry = navigation_controller->GetActiveEntry(); if (!navigation_controller->tab_contents()->ShouldDisplayURL()) { // Explicitly hide the URL for this tab. @@ -54,8 +53,8 @@ std::wstring ToolbarModel::GetText() const { // and pastes it into another program, that program may think the URL ends at // the space. return AutocompleteInput::FormattedStringWithEquivalentMeaning(url, - net::FormatUrl(url, languages, net::kFormatUrlOmitAll, - UnescapeRule::NORMAL, NULL, NULL, NULL)); + UTF16ToWideHack(net::FormatUrl(url, languages, net::kFormatUrlOmitAll, + UnescapeRule::NORMAL, NULL, NULL, NULL))); } ToolbarModel::SecurityLevel ToolbarModel::GetSecurityLevel() const { diff --git a/chrome/browser/views/bookmark_editor_view.cc b/chrome/browser/views/bookmark_editor_view.cc index 9bf525c..6f892a3 100644 --- a/chrome/browser/views/bookmark_editor_view.cc +++ b/chrome/browser/views/bookmark_editor_view.cc @@ -275,11 +275,11 @@ void BookmarkEditorView::Init() { l10n_util::GetString(IDS_BOOMARK_EDITOR_NAME_LABEL)); title_tf_.SetAccessibleName(title_label_->GetText()); - std::wstring url_text; + string16 url_text; if (details_.type == EditDetails::EXISTING_NODE) { - std::wstring languages = profile_ - ? UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)) - : std::wstring(); + std::string languages = profile_ + ? profile_->GetPrefs()->GetString(prefs::kAcceptLanguages) + : std::string(); // Because this gets parsed by FixupURL(), it's safe to omit the scheme or // trailing slash, and unescape most characters, but we need to not drop any // username/password, or unescape anything that changes the meaning. @@ -287,7 +287,7 @@ void BookmarkEditorView::Init() { net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL, NULL, NULL); } - url_tf_.SetText(url_text); + url_tf_.SetText(UTF16ToWide(url_text)); url_tf_.SetController(this); url_label_ = new views::Label( diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index 9cdf889..1b21457 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -648,7 +648,8 @@ void StatusBubbleViews::SetURL(const GURL& url, const std::wstring& languages) { url_text_ = gfx::ElideUrl(url, view_->Label::font(), text_width, languages); - std::wstring original_url_text = net::FormatUrl(url, languages); + std::wstring original_url_text = + UTF16ToWideHack(net::FormatUrl(url, WideToUTF8(languages))); // An URL is always treated as a left-to-right string. On right-to-left UIs // we need to explicitly mark the URL as LTR to make sure it is displayed diff --git a/chrome/browser/views/url_picker.cc b/chrome/browser/views/url_picker.cc index 6663bd3..3b9ac40 100644 --- a/chrome/browser/views/url_picker.cc +++ b/chrome/browser/views/url_picker.cc @@ -9,6 +9,7 @@ #include "app/table_model.h" #include "base/keyboard_codes.h" #include "base/stl_util-inl.h" +#include "base/string16.h" #include "base/utf_string_conversions.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/possible_url_model.h" @@ -218,16 +219,16 @@ bool UrlPicker::AcceleratorPressed( void UrlPicker::OnSelectionChanged() { int selection = url_table_->FirstSelectedRow(); if (selection >= 0 && selection < url_table_model_->RowCount()) { - std::wstring languages = UTF8ToWide( - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); + std::string languages = + profile_->GetPrefs()->GetString(prefs::kAcceptLanguages); // Because this gets parsed by FixupURL(), it's safe to omit the scheme or // trailing slash, and unescape most characters, but we need to not drop any // username/password, or unescape anything that changes the meaning. - std::wstring formatted = net::FormatUrl(url_table_model_->GetURL(selection), + string16 formatted = net::FormatUrl(url_table_model_->GetURL(selection), languages, net::kFormatUrlOmitAll & ~net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL, NULL, NULL); - url_field_->SetText(formatted); + url_field_->SetText(UTF16ToWide(formatted)); GetDialogClientView()->UpdateDialogButtons(); } } diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 202f5fc..4dd357f 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -69,6 +69,8 @@ using base::Time; +namespace net { + namespace { // what we prepend to get a file URL @@ -746,7 +748,15 @@ void AdjustComponents(int delta, url_parse::Parsed* parsed) { AdjustComponent(delta, &(parsed->ref)); } -// Helper for FormatUrl(). +std::wstring FormatUrlInternal(const GURL& url, + const std::wstring& languages, + FormatUrlTypes format_types, + UnescapeRule::Type unescape_rules, + url_parse::Parsed* new_parsed, + size_t* prefix_end, + size_t* offset_for_adjustment); + +// Helper for FormatUrl()/FormatUrlInternal(). std::wstring FormatViewSourceUrl(const GURL& url, const std::wstring& languages, net::FormatUrlTypes format_types, @@ -763,8 +773,8 @@ std::wstring FormatViewSourceUrl(const GURL& url, std::wstring::npos : (*offset_for_adjustment - kViewSourceLengthPlus1); 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); + std::wstring result = FormatUrlInternal(real_url, languages, format_types, + unescape_rules, new_parsed, prefix_end, temp_offset_ptr); result.insert(0, kWideViewSource); // Adjust position values. @@ -785,19 +795,6 @@ std::wstring FormatViewSourceUrl(const GURL& url, return result; } -} // namespace - -namespace net { - -const FormatUrlType kFormatUrlOmitNothing = 0; -const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; -const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; -const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; -const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | - kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; - -std::set<int> explicitly_allowed_ports; - // Appends the substring |in_component| inside of the URL |spec| to |output|, // and the resulting range will be filled into |out_component|. |unescape_rules| // defines how to clean the URL for human readability. |offset_for_adjustment| @@ -808,12 +805,248 @@ std::set<int> explicitly_allowed_ports; // components. Otherwise it points into the component being converted, and is // adjusted to point to the same logical place in |output|. // |offset_for_adjustment| may not be NULL. -static void AppendFormattedComponent(const std::string& spec, - const url_parse::Component& in_component, - UnescapeRule::Type unescape_rules, - std::wstring* output, - url_parse::Component* out_component, - size_t* offset_for_adjustment); +void AppendFormattedComponent(const std::string& spec, + const url_parse::Component& in_component, + UnescapeRule::Type unescape_rules, + std::wstring* output, + url_parse::Component* out_component, + size_t* offset_for_adjustment) { + DCHECK(output); + DCHECK(offset_for_adjustment); + if (in_component.is_nonempty()) { + out_component->begin = static_cast<int>(output->length()); + size_t offset_past_current_output = + ((*offset_for_adjustment == std::wstring::npos) || + (*offset_for_adjustment < output->length())) ? + std::wstring::npos : (*offset_for_adjustment - output->length()); + size_t* offset_into_component = + (offset_past_current_output >= static_cast<size_t>(in_component.len)) ? + NULL : &offset_past_current_output; + if (unescape_rules == UnescapeRule::NONE) { + output->append(UTF8ToWideAndAdjustOffset( + spec.substr(in_component.begin, in_component.len), + offset_into_component)); + } else { + output->append(UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent( + spec.substr(in_component.begin, in_component.len), unescape_rules, + offset_into_component))); + } + out_component->len = + static_cast<int>(output->length()) - out_component->begin; + if (offset_into_component) { + *offset_for_adjustment = (*offset_into_component == std::wstring::npos) ? + std::wstring::npos : (out_component->begin + *offset_into_component); + } else if (offset_past_current_output != std::wstring::npos) { + *offset_for_adjustment += out_component->len - in_component.len; + } + } else { + out_component->reset(); + } +} + +// TODO(viettrungluu): This is really the old-fashioned version, made internal. +// I need to really convert |FormatUrl()|. +std::wstring FormatUrlInternal(const GURL& url, + const std::wstring& languages, + FormatUrlTypes format_types, + UnescapeRule::Type unescape_rules, + url_parse::Parsed* new_parsed, + size_t* prefix_end, + size_t* offset_for_adjustment) { + 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; + + std::wstring url_string; + + // Check for empty URLs or 0 available text width. + if (url.is_empty()) { + if (prefix_end) + *prefix_end = 0; + *offset_for_adjustment = std::wstring::npos; + return url_string; + } + + // Special handling for view-source:. Don't use chrome::kViewSourceScheme + // because this library shouldn't depend on chrome. + const char* const kViewSource = "view-source"; + // Reject "view-source:view-source:..." to avoid deep recursion. + const char* const kViewSourceTwice = "view-source:view-source:"; + if (url.SchemeIs(kViewSource) && + !StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) { + return FormatViewSourceUrl(url, languages, format_types, + unescape_rules, new_parsed, prefix_end, offset_for_adjustment); + } + + // We handle both valid and invalid URLs (this will give us the spec + // regardless of validity). + const std::string& spec = url.possibly_invalid_spec(); + const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); + if (*offset_for_adjustment >= spec.length()) + *offset_for_adjustment = std::wstring::npos; + + // Copy everything before the username (the scheme and the separators.) + // These are ASCII. + std::copy(spec.begin(), + spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME, + true), + std::back_inserter(url_string)); + + const wchar_t kHTTP[] = L"http://"; + const char kFTP[] = "ftp."; + // URLFixerUpper::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This + // means that if we trim "http://" off a URL whose host starts with "ftp." and + // the user inputs this into any field subject to fixup (which is basically + // all input fields), the meaning would be changed. (In fact, often the + // formatted URL is directly pre-filled into an input field.) For this reason + // we avoid stripping "http://" in this case. + bool omit_http = + (format_types & kFormatUrlOmitHTTP) && (url_string == kHTTP) && + (url.host().compare(0, arraysize(kFTP) - 1, kFTP) != 0); + + new_parsed->scheme = parsed.scheme; + + 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/" + new_parsed->username.reset(); + new_parsed->password.reset(); + if ((*offset_for_adjustment != std::wstring::npos) && + (parsed.username.is_nonempty() || parsed.password.is_nonempty())) { + if (parsed.username.is_nonempty() && parsed.password.is_nonempty()) { + // The seeming off-by-one and off-by-two in these first two lines are to + // account for the ':' after the username and '@' after the password. + if (*offset_for_adjustment > + static_cast<size_t>(parsed.password.end())) { + *offset_for_adjustment -= + (parsed.username.len + parsed.password.len + 2); + } else if (*offset_for_adjustment > + static_cast<size_t>(parsed.username.begin)) { + *offset_for_adjustment = std::wstring::npos; + } + } else { + const url_parse::Component* nonempty_component = + parsed.username.is_nonempty() ? &parsed.username : &parsed.password; + // The seeming off-by-one in these first two lines is to account for the + // '@' after the username/password. + if (*offset_for_adjustment > + static_cast<size_t>(nonempty_component->end())) { + *offset_for_adjustment -= (nonempty_component->len + 1); + } else if (*offset_for_adjustment > + static_cast<size_t>(nonempty_component->begin)) { + *offset_for_adjustment = std::wstring::npos; + } + } + } + } else { + AppendFormattedComponent(spec, parsed.username, unescape_rules, &url_string, + &new_parsed->username, offset_for_adjustment); + if (parsed.password.is_valid()) + url_string.push_back(':'); + AppendFormattedComponent(spec, parsed.password, unescape_rules, &url_string, + &new_parsed->password, offset_for_adjustment); + if (parsed.username.is_valid() || parsed.password.is_valid()) + url_string.push_back('@'); + } + if (prefix_end) + *prefix_end = static_cast<size_t>(url_string.length()); + + AppendFormattedHost(url, languages, &url_string, new_parsed, + offset_for_adjustment); + + // Port. + if (parsed.port.is_nonempty()) { + url_string.push_back(':'); + new_parsed->port.begin = url_string.length(); + std::copy(spec.begin() + parsed.port.begin, + spec.begin() + parsed.port.end(), std::back_inserter(url_string)); + new_parsed->port.len = url_string.length() - new_parsed->port.begin; + } else { + new_parsed->port.reset(); + } + + // Path and query both get the same general unescape & convert treatment. + if (!(format_types & kFormatUrlOmitTrailingSlashOnBareHostname) || + !CanStripTrailingSlash(url)) { + AppendFormattedComponent(spec, parsed.path, unescape_rules, &url_string, + &new_parsed->path, offset_for_adjustment); + } + if (parsed.query.is_valid()) + url_string.push_back('?'); + AppendFormattedComponent(spec, parsed.query, unescape_rules, &url_string, + &new_parsed->query, offset_for_adjustment); + + // Reference is stored in valid, unescaped UTF-8, so we can just convert. + if (parsed.ref.is_valid()) { + url_string.push_back('#'); + new_parsed->ref.begin = url_string.length(); + size_t offset_past_current_output = + ((*offset_for_adjustment == std::wstring::npos) || + (*offset_for_adjustment < url_string.length())) ? + std::wstring::npos : (*offset_for_adjustment - url_string.length()); + size_t* offset_into_ref = + (offset_past_current_output >= static_cast<size_t>(parsed.ref.len)) ? + NULL : &offset_past_current_output; + if (parsed.ref.len > 0) { + url_string.append(UTF8ToWideAndAdjustOffset(spec.substr(parsed.ref.begin, + parsed.ref.len), + offset_into_ref)); + } + new_parsed->ref.len = url_string.length() - new_parsed->ref.begin; + if (offset_into_ref) { + *offset_for_adjustment = (*offset_into_ref == std::wstring::npos) ? + std::wstring::npos : (new_parsed->ref.begin + *offset_into_ref); + } else if (offset_past_current_output != std::wstring::npos) { + // We clamped the offset near the beginning of this function to ensure it + // was within the input URL. If we reach here, the input was something + // invalid and non-parseable such that the offset was past any component + // we could figure out. In this case it won't be represented in the + // output string, so reset it. + *offset_for_adjustment = std::wstring::npos; + } + } + + // 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. + const size_t kHTTPSize = arraysize(kHTTP) - 1; + 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; +} + +} // namespace + +const FormatUrlType kFormatUrlOmitNothing = 0; +const FormatUrlType kFormatUrlOmitUsernamePassword = 1 << 0; +const FormatUrlType kFormatUrlOmitHTTP = 1 << 1; +const FormatUrlType kFormatUrlOmitTrailingSlashOnBareHostname = 1 << 2; +const FormatUrlType kFormatUrlOmitAll = kFormatUrlOmitUsernamePassword | + kFormatUrlOmitHTTP | kFormatUrlOmitTrailingSlashOnBareHostname; + +// TODO(viettrungluu): We don't want non-POD globals; change this. +std::set<int> explicitly_allowed_ports; GURL FilePathToFileURL(const FilePath& path) { // Produce a URL like "file:///C:/foo" for a regular file, or @@ -1391,237 +1624,7 @@ void AppendFormattedHost(const GURL& url, } } -/* static */ -void AppendFormattedComponent(const std::string& spec, - const url_parse::Component& in_component, - UnescapeRule::Type unescape_rules, - std::wstring* output, - url_parse::Component* out_component, - size_t* offset_for_adjustment) { - DCHECK(output); - DCHECK(offset_for_adjustment); - if (in_component.is_nonempty()) { - out_component->begin = static_cast<int>(output->length()); - size_t offset_past_current_output = - ((*offset_for_adjustment == std::wstring::npos) || - (*offset_for_adjustment < output->length())) ? - std::wstring::npos : (*offset_for_adjustment - output->length()); - size_t* offset_into_component = - (offset_past_current_output >= static_cast<size_t>(in_component.len)) ? - NULL : &offset_past_current_output; - if (unescape_rules == UnescapeRule::NONE) { - output->append(UTF8ToWideAndAdjustOffset( - spec.substr(in_component.begin, in_component.len), - offset_into_component)); - } else { - output->append(UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent( - spec.substr(in_component.begin, in_component.len), unescape_rules, - offset_into_component))); - } - out_component->len = - static_cast<int>(output->length()) - out_component->begin; - if (offset_into_component) { - *offset_for_adjustment = (*offset_into_component == std::wstring::npos) ? - std::wstring::npos : (out_component->begin + *offset_into_component); - } else if (offset_past_current_output != std::wstring::npos) { - *offset_for_adjustment += out_component->len - in_component.len; - } - } else { - out_component->reset(); - } -} - -std::wstring FormatUrl(const GURL& url, - const std::wstring& languages, - FormatUrlTypes format_types, - UnescapeRule::Type unescape_rules, - url_parse::Parsed* new_parsed, - size_t* prefix_end, - size_t* offset_for_adjustment) { - 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; - - std::wstring url_string; - - // Check for empty URLs or 0 available text width. - if (url.is_empty()) { - if (prefix_end) - *prefix_end = 0; - *offset_for_adjustment = std::wstring::npos; - return url_string; - } - - // Special handling for view-source:. Don't use chrome::kViewSourceScheme - // because this library shouldn't depend on chrome. - const char* const kViewSource = "view-source"; - // Reject "view-source:view-source:..." to avoid deep recursion. - const char* const kViewSourceTwice = "view-source:view-source:"; - if (url.SchemeIs(kViewSource) && - !StartsWithASCII(url.possibly_invalid_spec(), kViewSourceTwice, false)) { - return FormatViewSourceUrl(url, languages, format_types, - unescape_rules, new_parsed, prefix_end, offset_for_adjustment); - } - - // We handle both valid and invalid URLs (this will give us the spec - // regardless of validity). - const std::string& spec = url.possibly_invalid_spec(); - const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); - if (*offset_for_adjustment >= spec.length()) - *offset_for_adjustment = std::wstring::npos; - - // Copy everything before the username (the scheme and the separators.) - // These are ASCII. - std::copy(spec.begin(), - spec.begin() + parsed.CountCharactersBefore(url_parse::Parsed::USERNAME, - true), - std::back_inserter(url_string)); - - const wchar_t kHTTP[] = L"http://"; - const char kFTP[] = "ftp."; - // URLFixerUpper::FixupURL() treats "ftp.foo.com" as ftp://ftp.foo.com. This - // means that if we trim "http://" off a URL whose host starts with "ftp." and - // the user inputs this into any field subject to fixup (which is basically - // all input fields), the meaning would be changed. (In fact, often the - // formatted URL is directly pre-filled into an input field.) For this reason - // we avoid stripping "http://" in this case. - bool omit_http = - (format_types & kFormatUrlOmitHTTP) && (url_string == kHTTP) && - (url.host().compare(0, arraysize(kFTP) - 1, kFTP) != 0); - - new_parsed->scheme = parsed.scheme; - - 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/" - new_parsed->username.reset(); - new_parsed->password.reset(); - if ((*offset_for_adjustment != std::wstring::npos) && - (parsed.username.is_nonempty() || parsed.password.is_nonempty())) { - if (parsed.username.is_nonempty() && parsed.password.is_nonempty()) { - // The seeming off-by-one and off-by-two in these first two lines are to - // account for the ':' after the username and '@' after the password. - if (*offset_for_adjustment > - static_cast<size_t>(parsed.password.end())) { - *offset_for_adjustment -= - (parsed.username.len + parsed.password.len + 2); - } else if (*offset_for_adjustment > - static_cast<size_t>(parsed.username.begin)) { - *offset_for_adjustment = std::wstring::npos; - } - } else { - const url_parse::Component* nonempty_component = - parsed.username.is_nonempty() ? &parsed.username : &parsed.password; - // The seeming off-by-one in these first two lines is to account for the - // '@' after the username/password. - if (*offset_for_adjustment > - static_cast<size_t>(nonempty_component->end())) { - *offset_for_adjustment -= (nonempty_component->len + 1); - } else if (*offset_for_adjustment > - static_cast<size_t>(nonempty_component->begin)) { - *offset_for_adjustment = std::wstring::npos; - } - } - } - } else { - AppendFormattedComponent(spec, parsed.username, unescape_rules, &url_string, - &new_parsed->username, offset_for_adjustment); - if (parsed.password.is_valid()) - url_string.push_back(':'); - AppendFormattedComponent(spec, parsed.password, unescape_rules, &url_string, - &new_parsed->password, offset_for_adjustment); - if (parsed.username.is_valid() || parsed.password.is_valid()) - url_string.push_back('@'); - } - if (prefix_end) - *prefix_end = static_cast<size_t>(url_string.length()); - - AppendFormattedHost(url, languages, &url_string, new_parsed, - offset_for_adjustment); - - // Port. - if (parsed.port.is_nonempty()) { - url_string.push_back(':'); - new_parsed->port.begin = url_string.length(); - std::copy(spec.begin() + parsed.port.begin, - spec.begin() + parsed.port.end(), std::back_inserter(url_string)); - new_parsed->port.len = url_string.length() - new_parsed->port.begin; - } else { - new_parsed->port.reset(); - } - - // Path and query both get the same general unescape & convert treatment. - if (!(format_types & kFormatUrlOmitTrailingSlashOnBareHostname) || - !CanStripTrailingSlash(url)) { - AppendFormattedComponent(spec, parsed.path, unescape_rules, &url_string, - &new_parsed->path, offset_for_adjustment); - } - if (parsed.query.is_valid()) - url_string.push_back('?'); - AppendFormattedComponent(spec, parsed.query, unescape_rules, &url_string, - &new_parsed->query, offset_for_adjustment); - - // Reference is stored in valid, unescaped UTF-8, so we can just convert. - if (parsed.ref.is_valid()) { - url_string.push_back('#'); - new_parsed->ref.begin = url_string.length(); - size_t offset_past_current_output = - ((*offset_for_adjustment == std::wstring::npos) || - (*offset_for_adjustment < url_string.length())) ? - std::wstring::npos : (*offset_for_adjustment - url_string.length()); - size_t* offset_into_ref = - (offset_past_current_output >= static_cast<size_t>(parsed.ref.len)) ? - NULL : &offset_past_current_output; - if (parsed.ref.len > 0) { - url_string.append(UTF8ToWideAndAdjustOffset(spec.substr(parsed.ref.begin, - parsed.ref.len), - offset_into_ref)); - } - new_parsed->ref.len = url_string.length() - new_parsed->ref.begin; - if (offset_into_ref) { - *offset_for_adjustment = (*offset_into_ref == std::wstring::npos) ? - std::wstring::npos : (new_parsed->ref.begin + *offset_into_ref); - } else if (offset_past_current_output != std::wstring::npos) { - // We clamped the offset near the beginning of this function to ensure it - // was within the input URL. If we reach here, the input was something - // invalid and non-parseable such that the offset was past any component - // we could figure out. In this case it won't be represented in the - // output string, so reset it. - *offset_for_adjustment = std::wstring::npos; - } - } - - // 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. - const size_t kHTTPSize = arraysize(kHTTP) - 1; - 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; -} - -// TODO(viettrungluu): convert the code in wstring version to this form. +// TODO(viettrungluu): convert the wstring |FormatUrlInternal()|. string16 FormatUrl(const GURL& url, const std::string& languages, FormatUrlTypes format_types, @@ -1630,8 +1633,9 @@ string16 FormatUrl(const GURL& url, size_t* prefix_end, size_t* offset_for_adjustment) { return WideToUTF16Hack( - FormatUrl(url, ASCIIToWide(languages), format_types, unescape_rules, - new_parsed, prefix_end, offset_for_adjustment)); + FormatUrlInternal(url, ASCIIToWide(languages), format_types, + unescape_rules, new_parsed, prefix_end, + offset_for_adjustment)); } bool CanStripTrailingSlash(const GURL& url) { diff --git a/net/base/net_util.h b/net/base/net_util.h index a3bea0d..af3bd0a 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -294,15 +294,7 @@ void AppendFormattedHost(const GURL& url, // 8. If the offset cannot be successfully adjusted (e.g. because it points // into the middle of a component that was entirely removed, past the end of the // string, or into the middle of an encoding sequence), it will be set to -// std::wstring::npos. -// TODO(viettrungluu): remove wstring version. -std::wstring FormatUrl(const GURL& url, - const std::wstring& languages, - FormatUrlTypes format_types, - UnescapeRule::Type unescape_rules, - url_parse::Parsed* new_parsed, - size_t* prefix_end, - size_t* offset_for_adjustment); +// string16::npos. string16 FormatUrl(const GURL& url, const std::string& languages, FormatUrlTypes format_types, @@ -315,11 +307,6 @@ string16 FormatUrl(const GURL& url, // format_types = kFormatUrlOmitAll and unescape = SPACES. This is the typical // set of flags for "URLs to display to the user". You should be cautious about // using this for URLs which will be parsed or sent to other applications. -// TODO(viettrungluu): remove wstring version. -inline std::wstring FormatUrl(const GURL& url, const std::wstring& languages) { - return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, - NULL, NULL, NULL); -} inline string16 FormatUrl(const GURL& url, const std::string& languages) { return FormatUrl(url, languages, kFormatUrlOmitAll, UnescapeRule::SPACES, NULL, NULL, NULL); diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index a3b3afb..4975a68 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -395,16 +395,6 @@ struct UrlTestData { size_t prefix_len; }; -struct UrlTestDataDeprecated { - const char* description; - const char* input; - const std::wstring languages; - net::FormatUrlTypes format_types; - UnescapeRule::Type escape_rules; - const std::wstring output; - size_t prefix_len; -}; - // Returns an addrinfo for the given 32-bit address (IPv4.) // The result lives in static storage, so don't delete it. // |bytes| should be an array of length 4. @@ -866,17 +856,17 @@ TEST(NetUtilTest, IDNToUnicodeAdjustOffset) { {2, 2}, {4, 4}, {5, 5}, - {6, std::wstring::npos}, - {16, std::wstring::npos}, + {6, string16::npos}, + {16, string16::npos}, {17, 7}, {18, 8}, - {19, std::wstring::npos}, - {25, std::wstring::npos}, + {19, string16::npos}, + {25, string16::npos}, {34, 12}, {35, 13}, {38, 16}, - {39, std::wstring::npos}, - {std::wstring::npos, std::wstring::npos}, + {39, string16::npos}, + {string16::npos, string16::npos}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(adjust_cases); ++i) { size_t offset = adjust_cases[i].input_offset; @@ -1527,296 +1517,143 @@ TEST(NetUtilTest, FormatUrl) { } } -TEST(NetUtilTest, FormatUrlDeprecated) { - net::FormatUrlTypes default_format_type = net::kFormatUrlOmitUsernamePassword; - const UrlTestDataDeprecated tests[] = { - {"Empty URL", "", L"", default_format_type, UnescapeRule::NORMAL, L"", 0}, - - {"Simple URL", - "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"", 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", default_format_type, - 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}, - - {"Japanese IDN without any languages", - "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", 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", 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", 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"", - 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"", default_format_type, - 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}, - - {"Just '@' without username and password", - "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"", 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", 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" - L"?q=%E3%82%B0%E3%83%BC%E3%82%B0%E3%83%AB", 7}, - - {"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, - 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}, - - /* - {"unescape=true with some special characters", - "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...". - - // -------- 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}, - - // -------- omit trailing slash on bare hostname -------- - {"omit slash when it's the entire path", - "http://www.google.com/", L"en", - net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, - L"http://www.google.com", 7}, - {"omit slash when there's a ref", - "http://www.google.com/#ref", L"en", - net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, - L"http://www.google.com/#ref", 7}, - {"omit slash when there's a query", - "http://www.google.com/?", L"en", - net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, - L"http://www.google.com/?", 7}, - {"omit slash when it's not the entire path", - "http://www.google.com/foo", L"en", - net::kFormatUrlOmitTrailingSlashOnBareHostname, UnescapeRule::NORMAL, - L"http://www.google.com/foo", 7}, - {"omit slash for nonstandard URLs", - "data:/", L"en", net::kFormatUrlOmitTrailingSlashOnBareHostname, - UnescapeRule::NORMAL, L"data:/", 5}, - {"omit slash for file URLs", - "file:///", L"en", net::kFormatUrlOmitTrailingSlashOnBareHostname, - UnescapeRule::NORMAL, L"file:///", 7}, - - // -------- 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/", - 19}, - - {"view-source of view-source", - "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}, - - // view-source should omit http and trailing slash where non-view-source - // would. - {"view-source omit http", - "view-source:http://a.b/c", L"en", net::kFormatUrlOmitAll, - UnescapeRule::NORMAL, L"view-source:a.b/c", - 12}, - {"view-source omit http starts with ftp.", - "view-source:http://ftp.b/c", L"en", net::kFormatUrlOmitAll, - UnescapeRule::NORMAL, L"view-source:http://ftp.b/c", - 19}, - {"view-source omit slash when it's the entire path", - "view-source:http://a.b/", L"en", net::kFormatUrlOmitAll, - UnescapeRule::NORMAL, L"view-source:a.b", - 12}, - }; - - 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, - 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; - } -} - TEST(NetUtilTest, FormatUrlParsed) { // No unescape case. url_parse::Parsed parsed; - std::wstring formatted = net::FormatUrl( + string16 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, + "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", + EXPECT_EQ(WideToUTF16( + 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(WideToUTF16(L"%E3%82%B0"), formatted.substr(parsed.username.begin, parsed.username.len)); - EXPECT_EQ(L"%E3%83%BC", + EXPECT_EQ(WideToUTF16(L"%E3%83%BC"), formatted.substr(parsed.password.begin, parsed.password.len)); - EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", + EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), formatted.substr(parsed.host.begin, parsed.host.len)); - EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); - EXPECT_EQ(L"/%E3%82%B0/", + EXPECT_EQ(WideToUTF16(L"8080"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/%E3%82%B0/"), formatted.substr(parsed.path.begin, parsed.path.len)); - EXPECT_EQ(L"q=%E3%82%B0", + EXPECT_EQ(WideToUTF16(L"q=%E3%82%B0"), formatted.substr(parsed.query.begin, parsed.query.len)); - EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); + EXPECT_EQ(WideToUTF16(L"\x30B0"), + formatted.substr(parsed.ref.begin, parsed.ref.len)); // Unescape case. 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, + "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", + EXPECT_EQ(WideToUTF16(L"http://\x30B0:\x30FC@\x30B0\x30FC\x30B0\x30EB.jp:8080" + L"/\x30B0/?q=\x30B0#\x30B0"), formatted); + EXPECT_EQ(WideToUTF16(L"\x30B0"), formatted.substr(parsed.username.begin, parsed.username.len)); - EXPECT_EQ(L"\x30FC", + EXPECT_EQ(WideToUTF16(L"\x30FC"), formatted.substr(parsed.password.begin, parsed.password.len)); - EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", + EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), formatted.substr(parsed.host.begin, parsed.host.len)); - EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); - EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len)); - EXPECT_EQ(L"q=\x30B0", + EXPECT_EQ(WideToUTF16(L"8080"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/\x30B0/"), + formatted.substr(parsed.path.begin, parsed.path.len)); + EXPECT_EQ(WideToUTF16(L"q=\x30B0"), formatted.substr(parsed.query.begin, parsed.query.len)); - EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); + EXPECT_EQ(WideToUTF16(L"\x30B0"), + formatted.substr(parsed.ref.begin, parsed.ref.len)); // Omit_username_password + unescape case. 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); - EXPECT_EQ(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" - L"/\x30B0/?q=\x30B0#\x30B0", formatted); + "ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed, + NULL, NULL); + EXPECT_EQ(WideToUTF16(L"http://\x30B0\x30FC\x30B0\x30EB.jp:8080" + L"/\x30B0/?q=\x30B0#\x30B0"), formatted); EXPECT_FALSE(parsed.username.is_valid()); EXPECT_FALSE(parsed.password.is_valid()); - EXPECT_EQ(L"\x30B0\x30FC\x30B0\x30EB.jp", + EXPECT_EQ(WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB.jp"), formatted.substr(parsed.host.begin, parsed.host.len)); - EXPECT_EQ(L"8080", formatted.substr(parsed.port.begin, parsed.port.len)); - EXPECT_EQ(L"/\x30B0/", formatted.substr(parsed.path.begin, parsed.path.len)); - EXPECT_EQ(L"q=\x30B0", + EXPECT_EQ(WideToUTF16(L"8080"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/\x30B0/"), + formatted.substr(parsed.path.begin, parsed.path.len)); + EXPECT_EQ(WideToUTF16(L"q=\x30B0"), formatted.substr(parsed.query.begin, parsed.query.len)); - EXPECT_EQ(L"\x30B0", formatted.substr(parsed.ref.begin, parsed.ref.len)); + EXPECT_EQ(WideToUTF16(L"\x30B0"), + formatted.substr(parsed.ref.begin, parsed.ref.len)); // View-source case. formatted = net::FormatUrl( GURL("view-source:http://user:passwd@host:81/path?query#ref"), - L"", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, &parsed, + "", 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", + EXPECT_EQ(WideToUTF16(L"view-source:http://host:81/path?query#ref"), + formatted); + EXPECT_EQ(WideToUTF16(L"view-source:http"), formatted.substr(parsed.scheme.begin, parsed.scheme.len)); 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"81", formatted.substr(parsed.port.begin, parsed.port.len)); - 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)); + EXPECT_EQ(WideToUTF16(L"host"), + formatted.substr(parsed.host.begin, parsed.host.len)); + EXPECT_EQ(WideToUTF16(L"81"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/path"), + formatted.substr(parsed.path.begin, parsed.path.len)); + EXPECT_EQ(WideToUTF16(L"query"), + formatted.substr(parsed.query.begin, parsed.query.len)); + EXPECT_EQ(WideToUTF16(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); + "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL); + EXPECT_EQ(WideToUTF16(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)); + EXPECT_EQ(WideToUTF16(L"host"), + formatted.substr(parsed.host.begin, parsed.host.len)); + EXPECT_EQ(WideToUTF16(L"8000"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/a"), + formatted.substr(parsed.path.begin, parsed.path.len)); + EXPECT_EQ(WideToUTF16(L"b=c"), + formatted.substr(parsed.query.begin, parsed.query.len)); + EXPECT_EQ(WideToUTF16(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); + "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL); + EXPECT_EQ(WideToUTF16(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)); + EXPECT_EQ(WideToUTF16(L"http"), + formatted.substr(parsed.scheme.begin, parsed.scheme.len)); + EXPECT_EQ(WideToUTF16(L"ftp.host"), + formatted.substr(parsed.host.begin, parsed.host.len)); + EXPECT_EQ(WideToUTF16(L"8000"), + formatted.substr(parsed.port.begin, parsed.port.len)); + EXPECT_EQ(WideToUTF16(L"/a"), + formatted.substr(parsed.path.begin, parsed.path.len)); + EXPECT_EQ(WideToUTF16(L"b=c"), + formatted.substr(parsed.query.begin, parsed.query.len)); + EXPECT_EQ(WideToUTF16(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); + "", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, &parsed, NULL, NULL); + EXPECT_EQ(WideToUTF16(L"f/"), formatted); EXPECT_FALSE(parsed.scheme.is_valid()); EXPECT_FALSE(parsed.username.is_valid()); EXPECT_FALSE(parsed.password.is_valid()); @@ -1824,8 +1661,10 @@ TEST(NetUtilTest, FormatUrlParsed) { 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)); + EXPECT_EQ(WideToUTF16(L"f"), + formatted.substr(parsed.host.begin, parsed.host.len)); + EXPECT_EQ(WideToUTF16(L"/"), + formatted.substr(parsed.path.begin, parsed.path.len)); } TEST(NetUtilTest, FormatUrlAdjustOffset) { @@ -1839,13 +1678,13 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { {22, 22}, {23, 23}, {25, 25}, - {26, std::wstring::npos}, - {500000, std::wstring::npos}, - {std::wstring::npos, std::wstring::npos}, + {26, string16::npos}, + {500000, string16::npos}, + {string16::npos, string16::npos}, }; 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::FormatUrl(GURL("http://www.google.com/foo/"), "en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(basic_cases[i].output_offset, offset); @@ -1858,18 +1697,18 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { } omit_auth_cases[] = { {"http://foo:bar@www.google.com/", 6, 6}, {"http://foo:bar@www.google.com/", 7, 7}, - {"http://foo:bar@www.google.com/", 8, std::wstring::npos}, - {"http://foo:bar@www.google.com/", 10, std::wstring::npos}, - {"http://foo:bar@www.google.com/", 11, std::wstring::npos}, - {"http://foo:bar@www.google.com/", 14, std::wstring::npos}, + {"http://foo:bar@www.google.com/", 8, string16::npos}, + {"http://foo:bar@www.google.com/", 10, string16::npos}, + {"http://foo:bar@www.google.com/", 11, string16::npos}, + {"http://foo:bar@www.google.com/", 14, string16::npos}, {"http://foo:bar@www.google.com/", 15, 7}, {"http://foo:bar@www.google.com/", 25, 17}, - {"http://foo@www.google.com/", 9, std::wstring::npos}, + {"http://foo@www.google.com/", 9, string16::npos}, {"http://foo@www.google.com/", 11, 7}, }; 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::FormatUrl(GURL(omit_auth_cases[i].input_url), "en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(omit_auth_cases[i].output_offset, offset); @@ -1882,30 +1721,30 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { {12, 12}, {13, 13}, {19, 19}, - {20, std::wstring::npos}, + {20, string16::npos}, {23, 19}, {26, 22}, - {std::wstring::npos, std::wstring::npos}, + {string16::npos, string16::npos}, }; 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::FormatUrl(GURL("view-source:http://foo@www.google.com/"), "en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(view_source_cases[i].output_offset, offset); } const AdjustOffsetCase idn_hostname_cases[] = { - {8, std::wstring::npos}, - {16, std::wstring::npos}, - {24, std::wstring::npos}, + {8, string16::npos}, + {16, string16::npos}, + {24, string16::npos}, {25, 12}, {30, 17}, }; 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::FormatUrl(GURL("http://xn--l8jvb1ey91xtjb.jp/foo/"), "ja", net::kFormatUrlOmitUsernamePassword, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(idn_hostname_cases[i].output_offset, offset); @@ -1913,22 +1752,22 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { const AdjustOffsetCase unescape_cases[] = { {25, 25}, - {26, std::wstring::npos}, - {27, std::wstring::npos}, + {26, string16::npos}, + {27, string16::npos}, {28, 26}, - {35, std::wstring::npos}, + {35, string16::npos}, {41, 31}, {59, 33}, - {60, std::wstring::npos}, - {67, std::wstring::npos}, - {68, std::wstring::npos}, + {60, string16::npos}, + {67, string16::npos}, + {68, string16::npos}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(unescape_cases); ++i) { size_t offset = unescape_cases[i].input_offset; // "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, + "en", net::kFormatUrlOmitUsernamePassword, UnescapeRule::SPACES, NULL, NULL, &offset); EXPECT_EQ(unescape_cases[i].output_offset, offset); } @@ -1936,30 +1775,30 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { const AdjustOffsetCase ref_cases[] = { {30, 30}, {31, 31}, - {32, std::wstring::npos}, + {32, string16::npos}, {34, 32}, {37, 33}, - {38, std::wstring::npos}, + {38, string16::npos}, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ref_cases); ++i) { size_t offset = ref_cases[i].input_offset; // "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", + "http://www.google.com/foo.html#\xE3\x82\xB0\xE3\x82\xB0z"), "en", 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}, + {0, string16::npos}, + {3, string16::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::FormatUrl(GURL("http://www.google.com"), "en", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(omit_http_cases[i].output_offset, offset); } @@ -1971,7 +1810,7 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { }; 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::FormatUrl(GURL("http://ftp.google.com"), "en", net::kFormatUrlOmitHTTP, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(omit_http_start_with_ftp[i].output_offset, offset); } @@ -1979,12 +1818,12 @@ TEST(NetUtilTest, FormatUrlAdjustOffset) { const AdjustOffsetCase omit_all_cases[] = { {12, 0}, {13, 1}, - {0, std::wstring::npos}, - {3, std::wstring::npos}, + {0, string16::npos}, + {3, string16::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, + net::FormatUrl(GURL("http://user@foo.com/"), "en", net::kFormatUrlOmitAll, UnescapeRule::NORMAL, NULL, NULL, &offset); EXPECT_EQ(omit_all_cases[i].output_offset, offset); } |