diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:18:25 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:18:25 +0000 |
commit | 6235541680600aecf07e7e85a63dc0843f1b7084 (patch) | |
tree | 76304d95b2638e9aa3eebfd5db6b2f2198e4da5d /chrome/browser/search_engines | |
parent | fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707 (diff) | |
download | chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.zip chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.tar.gz chromium_src-6235541680600aecf07e7e85a63dc0843f1b7084.tar.bz2 |
Revert 71485 - Remove wstring from TemplateURL and friends.
BUG=23581
TEST=no visible changes; all tests pass
Review URL: http://codereview.chromium.org/6322001
TBR=avi@chromium.org
Review URL: http://codereview.chromium.org/6291003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71500 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
24 files changed, 435 insertions, 455 deletions
diff --git a/chrome/browser/search_engines/edit_search_engine_controller.cc b/chrome/browser/search_engines/edit_search_engine_controller.cc index 10c02ef..b2b6a6d 100644 --- a/chrome/browser/search_engines/edit_search_engine_controller.cc +++ b/chrome/browser/search_engines/edit_search_engine_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 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. @@ -51,8 +51,8 @@ bool EditSearchEngineController::IsURLValid( // If the url has a search term, replace it with a random string and make // sure the resulting URL is valid. We don't check the validity of the url // with the search term as that is not necessarily valid. - return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), ASCIIToUTF16("a"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())).is_valid(); + return GURL(template_ref.ReplaceSearchTerms(TemplateURL(), L"a", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())).is_valid(); } bool EditSearchEngineController::IsKeywordValid( @@ -62,7 +62,7 @@ bool EditSearchEngineController::IsKeywordValid( return false; // Do not allow empty keyword. const TemplateURL* turl_with_keyword = profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - keyword_input_trimmed); + UTF16ToWideHack(keyword_input_trimmed)); return (turl_with_keyword == NULL || turl_with_keyword == template_url_); } @@ -75,7 +75,7 @@ void EditSearchEngineController::AcceptAddOrEdit( const TemplateURL* existing = profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( - keyword_input); + UTF16ToWideHack(keyword_input)); if (existing && (!edit_keyword_delegate_ || existing != template_url_)) { // An entry may have been added with the same keyword string while the @@ -96,8 +96,8 @@ void EditSearchEngineController::AcceptAddOrEdit( // does in a similar situation (updating an existing TemplateURL with // data from a new one). TemplateURL* modifiable_url = const_cast<TemplateURL*>(template_url_); - modifiable_url->set_short_name(title_input); - modifiable_url->set_keyword(keyword_input); + modifiable_url->set_short_name(UTF16ToWideHack(title_input)); + modifiable_url->set_keyword(UTF16ToWideHack(keyword_input)); modifiable_url->SetURL(url_string, 0, 0); // TemplateURLModel takes ownership of template_url_. profile_->GetTemplateURLModel()->Add(modifiable_url); @@ -124,7 +124,7 @@ void EditSearchEngineController::CleanUpCancelledAdd() { std::string EditSearchEngineController::GetFixedUpURL( const std::string& url_input) const { std::string url; - TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url_input)), + TrimWhitespace(TemplateURLRef::DisplayURLToURLRef(UTF8ToWide(url_input)), TRIM_ALL, &url); if (url.empty()) return url; @@ -135,7 +135,7 @@ std::string EditSearchEngineController::GetFixedUpURL( TemplateURL t_url; t_url.SetURL(url, 0, 0); std::string expanded_url = - t_url.url()->ReplaceSearchTerms(t_url, ASCIIToUTF16("x"), 0, string16()); + t_url.url()->ReplaceSearchTerms(t_url, L"x", 0, std::wstring()); url_parse::Parsed parts; std::string scheme( URLFixerUpper::SegmentURL(expanded_url, &parts)); diff --git a/chrome/browser/search_engines/keyword_editor_controller.cc b/chrome/browser/search_engines/keyword_editor_controller.cc index 349d469..b7d2c5e 100644 --- a/chrome/browser/search_engines/keyword_editor_controller.cc +++ b/chrome/browser/search_engines/keyword_editor_controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 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. @@ -37,8 +37,8 @@ int KeywordEditorController::AddTemplateURL(const string16& title, profile_); TemplateURL* template_url = new TemplateURL(); - template_url->set_short_name(title); - template_url->set_keyword(keyword); + template_url->set_short_name(UTF16ToWideHack(title)); + template_url->set_keyword(UTF16ToWideHack(keyword)); template_url->SetURL(url, 0, 0); // There's a bug (1090726) in TableView with groups enabled such that newly @@ -64,8 +64,8 @@ void KeywordEditorController::ModifyTemplateURL(const TemplateURL* template_url, } // Don't do anything if the entry didn't change. - if (template_url->short_name() == title && - template_url->keyword() == keyword && + if (template_url->short_name() == UTF16ToWideHack(title) && + template_url->keyword() == UTF16ToWideHack(keyword) && ((url.empty() && !template_url->url()) || (!url.empty() && template_url->url() && template_url->url()->url() == url))) { diff --git a/chrome/browser/search_engines/keyword_editor_controller_unittest.cc b/chrome/browser/search_engines/keyword_editor_controller_unittest.cc index 9ea48ac..e59af22 100644 --- a/chrome/browser/search_engines/keyword_editor_controller_unittest.cc +++ b/chrome/browser/search_engines/keyword_editor_controller_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -137,8 +137,8 @@ TEST_F(KeywordEditorControllerTest, Add) { // Verify the entry is what we added. const TemplateURL* turl = model_->GetTemplateURLs()[0]; - EXPECT_EQ(ASCIIToUTF16("a"), turl->short_name()); - EXPECT_EQ(ASCIIToUTF16("b"), turl->keyword()); + EXPECT_EQ(L"a", turl->short_name()); + EXPECT_EQ(L"b", turl->keyword()); ASSERT_TRUE(turl->url() != NULL); EXPECT_EQ("http://c", turl->url()->url()); } @@ -154,8 +154,8 @@ TEST_F(KeywordEditorControllerTest, Modify) { // Make sure it was updated appropriately. VerifyChangeCount(0, 1, 0, 0); - EXPECT_EQ(ASCIIToUTF16("a1"), turl->short_name()); - EXPECT_EQ(ASCIIToUTF16("b1"), turl->keyword()); + EXPECT_EQ(L"a1", turl->short_name()); + EXPECT_EQ(L"b1", turl->keyword()); ASSERT_TRUE(turl->url() != NULL); EXPECT_EQ("http://c1", turl->url()->url()); } @@ -186,11 +186,9 @@ TEST_F(KeywordEditorControllerTest, CannotSetDefaultWhileManaged) { controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); ClearChangeCount(); - const TemplateURL* turl1 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(turl1 != NULL); - const TemplateURL* turl2 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); + const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); ASSERT_TRUE(turl2 != NULL); EXPECT_TRUE(controller_->CanMakeDefault(turl1)); @@ -210,11 +208,9 @@ TEST_F(KeywordEditorControllerTest, EditManagedDefault) { controller_->AddTemplateURL(kA1, kB1, "http://d{searchTerms}"); ClearChangeCount(); - const TemplateURL* turl1 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + const TemplateURL* turl1 = model_->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(turl1 != NULL); - const TemplateURL* turl2 = - model_->GetTemplateURLForKeyword(ASCIIToUTF16("b1")); + const TemplateURL* turl2 = model_->GetTemplateURLForKeyword(L"b1"); ASSERT_TRUE(turl2 != NULL); EXPECT_TRUE(controller_->CanEdit(turl1)); @@ -245,8 +241,8 @@ TEST_F(KeywordEditorControllerTest, MakeDefaultNoWebData) { // appropriately. TEST_F(KeywordEditorControllerTest, MutateTemplateURLModel) { TemplateURL* turl = new TemplateURL(); - turl->set_keyword(ASCIIToUTF16("a")); - turl->set_short_name(ASCIIToUTF16("b")); + turl->set_keyword(L"a"); + turl->set_short_name(L"b"); model_->Add(turl); // Table model should have updated. diff --git a/chrome/browser/search_engines/search_provider_install_data.cc b/chrome/browser/search_engines/search_provider_install_data.cc index f0ef037..2a32c92 100644 --- a/chrome/browser/search_engines/search_provider_install_data.cc +++ b/chrome/browser/search_engines/search_provider_install_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,9 +36,9 @@ class IOThreadSearchTermsData : public SearchTermsData { virtual std::string GoogleBaseURLValue() const; virtual std::string GetApplicationLocale() const; #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - virtual string16 GetRlzParameterValue() const { + virtual std::wstring GetRlzParameterValue() const { // This value doesn't matter for our purposes. - return string16(); + return std::wstring(); } #endif diff --git a/chrome/browser/search_engines/search_provider_install_data_unittest.cc b/chrome/browser/search_engines/search_provider_install_data_unittest.cc index f132032..28bcd47 100644 --- a/chrome/browser/search_engines/search_provider_install_data_unittest.cc +++ b/chrome/browser/search_engines/search_provider_install_data_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/task.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/search_provider_install_data.h" #include "chrome/browser/search_engines/template_url.h" @@ -24,11 +23,11 @@ // Create a TemplateURL. The caller owns the returned TemplateURL*. static TemplateURL* CreateTemplateURL(const std::string& url, - const std::string& keyword) { + const std::wstring& keyword) { TemplateURL* t_url = new TemplateURL(); t_url->SetURL(url, 0, 0); - t_url->set_keyword(UTF8ToUTF16(keyword)); - t_url->set_short_name(UTF8ToUTF16(keyword)); + t_url->set_keyword(keyword); + t_url->set_short_name(keyword); return t_url; } @@ -226,7 +225,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { util_.ChangeModelToLoadState(); std::string host = "www.unittest.com"; TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", - "unittest"); + L"unittest"); util_.model()->Add(t_url); // Wait for the changes to be saved. @@ -241,7 +240,7 @@ TEST_F(SearchProviderInstallDataTest, GetInstallState) { // Set-up a default and try it all one more time. std::string default_host = "www.mmm.com"; TemplateURL* default_url = CreateTemplateURL("http://" + default_host + "/", - "mmm"); + L"mmm"); util_.model()->Add(default_url); util_.model()->SetDefaultSearchProvider(default_url); test_get_install_state->set_default_search_provider_host(default_host); @@ -254,7 +253,7 @@ TEST_F(SearchProviderInstallDataTest, ManagedDefaultSearch) { util_.ChangeModelToLoadState(); std::string host = "www.unittest.com"; TemplateURL* t_url = CreateTemplateURL("http://" + host + "/path", - "unittest"); + L"unittest"); util_.model()->Add(t_url); // Set a managed preference that establishes a default search provider. @@ -288,10 +287,10 @@ TEST_F(SearchProviderInstallDataTest, GoogleBaseUrlChange) { TemplateURLModelTestUtil::BlockTillIOThreadProcessesRequests(); TemplateURL* t_url = CreateTemplateURL("{google:baseURL}?q={searchTerms}", - "t"); + L"t"); util_.model()->Add(t_url); TemplateURL* default_url = CreateTemplateURL("http://d.com/", - "d"); + L"d"); util_.model()->Add(default_url); util_.model()->SetDefaultSearchProvider(default_url); diff --git a/chrome/browser/search_engines/search_terms_data.cc b/chrome/browser/search_engines/search_terms_data.cc index 7b09df2..7e5b9ff 100644 --- a/chrome/browser/search_engines/search_terms_data.cc +++ b/chrome/browser/search_engines/search_terms_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,14 +73,14 @@ std::string UIThreadSearchTermsData::GetApplicationLocale() const { } #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) -string16 UIThreadSearchTermsData::GetRlzParameterValue() const { +std::wstring UIThreadSearchTermsData::GetRlzParameterValue() const { DCHECK(!BrowserThread::IsWellKnownThread(BrowserThread::UI) || BrowserThread::CurrentlyOn(BrowserThread::UI)); - string16 rlz_string; + std::wstring rlz_string; // For organic brandcodes do not use rlz at all. Empty brandcode usually // means a chromium install. This is ok. - string16 brand; - // See http://crbug.com/62337 . + std::wstring brand; + // See http://crbug.com/62337. base::ThreadRestrictions::ScopedAllowIO allow_io; if (GoogleUpdateSettings::GetBrand(&brand) && !brand.empty() && !GoogleUpdateSettings::IsOrganic(brand)) diff --git a/chrome/browser/search_engines/search_terms_data.h b/chrome/browser/search_engines/search_terms_data.h index c830ade..41807c3 100644 --- a/chrome/browser/search_engines/search_terms_data.h +++ b/chrome/browser/search_engines/search_terms_data.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,7 +28,7 @@ class SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const = 0; + virtual std::wstring GetRlzParameterValue() const = 0; #endif private: @@ -44,7 +44,7 @@ class UIThreadSearchTermsData : public SearchTermsData { virtual std::string GoogleBaseURLValue() const; virtual std::string GetApplicationLocale() const; #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - virtual string16 GetRlzParameterValue() const; + virtual std::wstring GetRlzParameterValue() const; #endif // Used by tests to set the value for the Google base url. This takes diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc index b9cbac8..c1ebf517 100644 --- a/chrome/browser/search_engines/template_url.cc +++ b/chrome/browser/search_engines/template_url.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -262,9 +262,9 @@ void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) { std::string TemplateURLRef::ReplaceSearchTerms( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion) const { + const std::wstring& original_query_for_suggestion) const { UIThreadSearchTermsData search_terms_data; return ReplaceSearchTermsUsingTermsData(host, terms, @@ -275,9 +275,9 @@ std::string TemplateURLRef::ReplaceSearchTerms( std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion, + const std::wstring& original_query_for_suggestion, const SearchTermsData& search_terms_data) const { ParseIfNecessaryUsingTermsData(search_terms_data); if (!valid_) @@ -292,9 +292,9 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( for (Replacements::iterator i = replacements_.begin(); i != replacements_.end(); ++i) { if (i->type == SEARCH_TERMS) { - string16::size_type query_start = parsed_url_.find('?'); - is_in_query = query_start != string16::npos && - (static_cast<string16::size_type>(i->index) > query_start); + std::wstring::size_type query_start = parsed_url_.find('?'); + is_in_query = query_start != std::wstring::npos && + (static_cast<std::wstring::size_type>(i->index) > query_start); break; } } @@ -307,11 +307,11 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( // Encode the search terms so that we know the encoding. const std::vector<std::string>& encodings = host.input_encodings(); for (size_t i = 0; i < encodings.size(); ++i) { - if (EscapeQueryParamValue(terms, + if (EscapeQueryParamValue(WideToUTF16Hack(terms), encodings[i].c_str(), true, &encoded_terms)) { if (!original_query_for_suggestion.empty()) { - EscapeQueryParamValue(original_query_for_suggestion, + EscapeQueryParamValue(WideToUTF16Hack(original_query_for_suggestion), encodings[i].c_str(), true, &encoded_original_query); @@ -321,15 +321,17 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( } } if (input_encoding.empty()) { - encoded_terms = EscapeQueryParamValueUTF8(terms, true); + encoded_terms = WideToUTF16Hack( + EscapeQueryParamValueUTF8(terms, true)); if (!original_query_for_suggestion.empty()) { encoded_original_query = - EscapeQueryParamValueUTF8(original_query_for_suggestion, true); + WideToUTF16Hack(EscapeQueryParamValueUTF8( + original_query_for_suggestion, true)); } input_encoding = "UTF-8"; } } else { - encoded_terms = UTF8ToUTF16(EscapePath(UTF16ToUTF8(terms))); + encoded_terms = WideToUTF16Hack(UTF8ToWide(EscapePath(WideToUTF8(terms)))); input_encoding = "UTF-8"; } @@ -371,10 +373,10 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( // empty string. (If we don't handle this case, we hit a // NOTREACHED below.) #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) - string16 rlz_string = search_terms_data.GetRlzParameterValue(); + std::wstring rlz_string = search_terms_data.GetRlzParameterValue(); if (!rlz_string.empty()) { rlz_string = L"rlz=" + rlz_string + L"&"; - url.insert(i->index, UTF16ToUTF8(rlz_string)); + url.insert(i->index, WideToUTF8(rlz_string)); } #endif break; @@ -382,9 +384,9 @@ std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( case GOOGLE_UNESCAPED_SEARCH_TERMS: { std::string unescaped_terms; - base::UTF16ToCodepage(terms, input_encoding.c_str(), - base::OnStringConversionError::SKIP, - &unescaped_terms); + base::WideToCodepage(terms, input_encoding.c_str(), + base::OnStringConversionError::SKIP, + &unescaped_terms); url.insert(i->index, std::string(unescaped_terms.begin(), unescaped_terms.end())); break; @@ -429,10 +431,10 @@ bool TemplateURLRef::IsValidUsingTermsData( return valid_; } -string16 TemplateURLRef::DisplayURL() const { +std::wstring TemplateURLRef::DisplayURL() const { ParseIfNecessary(); if (!valid_ || replacements_.empty()) - return UTF8ToUTF16(url_); + return UTF8ToWide(url_); string16 result = UTF8ToUTF16(url_); ReplaceSubstringsAfterOffset(&result, 0, @@ -444,13 +446,13 @@ string16 TemplateURLRef::DisplayURL() const { ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull), ASCIIToUTF16(kDisplayUnescapedSearchTerms)); - return result; + return UTF16ToWideHack(result); } // static std::string TemplateURLRef::DisplayURLToURLRef( - const string16& display_url) { - string16 result = display_url; + const std::wstring& display_url) { + string16 result = WideToUTF16Hack(display_url); ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16(kDisplaySearchTerms), ASCIIToUTF16(kSearchTermsParameterFull)); ReplaceSubstringsAfterOffset( @@ -475,29 +477,29 @@ const std::string& TemplateURLRef::GetSearchTermKey() const { return search_term_key_; } -string16 TemplateURLRef::SearchTermToString16(const TemplateURL& host, +std::wstring TemplateURLRef::SearchTermToWide(const TemplateURL& host, const std::string& term) const { const std::vector<std::string>& encodings = host.input_encodings(); - string16 result; + std::wstring result; std::string unescaped = UnescapeURLComponent(term, UnescapeRule::REPLACE_PLUS_WITH_SPACE | UnescapeRule::URL_SPECIAL_CHARS); for (size_t i = 0; i < encodings.size(); ++i) { - if (base::CodepageToUTF16(unescaped, encodings[i].c_str(), - base::OnStringConversionError::FAIL, &result)) + if (base::CodepageToWide(unescaped, encodings[i].c_str(), + base::OnStringConversionError::FAIL, &result)) return result; } // Always fall back on UTF-8 if it works. - if (base::CodepageToUTF16(unescaped, base::kCodepageUTF8, - base::OnStringConversionError::FAIL, &result)) + if (base::CodepageToWide(unescaped, base::kCodepageUTF8, + base::OnStringConversionError::FAIL, &result)) return result; // When nothing worked, just use the escaped text. We have no idea what the // encoding is. We need to substitute spaces for pluses ourselves since we're // not sending it through an unescaper. - result = UTF8ToUTF16(term); + result = UTF8ToWide(term); std::replace(result.begin(), result.end(), '+', ' '); return result; } @@ -575,8 +577,8 @@ TemplateURL::TemplateURL() TemplateURL::~TemplateURL() { } -string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { - string16 bidi_safe_short_name = short_name_; +std::wstring TemplateURL::AdjustedShortNameForLocaleDirection() const { + std::wstring bidi_safe_short_name = short_name_; base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); return bidi_safe_short_name; } @@ -599,14 +601,14 @@ void TemplateURL::SetInstantURL(const std::string& url, instant_url_.Set(url, index_offset, page_offset); } -void TemplateURL::set_keyword(const string16& keyword) { +void TemplateURL::set_keyword(const std::wstring& keyword) { // Case sensitive keyword matching is confusing. As such, we force all // keywords to be lower case. - keyword_ = l10n_util::ToLower(keyword); + keyword_ = UTF16ToWide(l10n_util::ToLower(WideToUTF16(keyword))); autogenerate_keyword_ = false; } -string16 TemplateURL::keyword() const { +const std::wstring& TemplateURL::keyword() const { EnsureKeyword(); return keyword_; } @@ -627,7 +629,7 @@ bool TemplateURL::ShowInDefaultList() const { void TemplateURL::SetFavIconURL(const GURL& url) { for (std::vector<ImageRef>::iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { - if (i->type == "image/x-icon" && + if (i->type == L"image/x-icon" && i->width == kFavIconSize && i->height == kFavIconSize) { if (!url.is_valid()) image_refs_.erase(i); @@ -639,15 +641,15 @@ void TemplateURL::SetFavIconURL(const GURL& url) { // Don't have one yet, add it. if (url.is_valid()) { add_image_ref( - TemplateURL::ImageRef("image/x-icon", kFavIconSize, - kFavIconSize, url)); + TemplateURL::ImageRef(L"image/x-icon", kFavIconSize, kFavIconSize, + url)); } } GURL TemplateURL::GetFavIconURL() const { for (std::vector<ImageRef>::const_iterator i = image_refs_.begin(); i != image_refs_.end(); ++i) { - if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") + if ((i->type == L"image/x-icon" || i->type == L"image/vnd.microsoft.icon") && i->width == kFavIconSize && i->height == kFavIconSize) { return i->url; } diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index 44cdeec..ba2a96e 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -72,18 +72,18 @@ class TemplateURLRef { // The TemplateURL is used to determine the input encoding for the term. std::string ReplaceSearchTerms( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion) const; + const std::wstring& original_query_for_suggestion) const; // Just like ReplaceSearchTerms except that it takes SearchTermsData to supply // the data for some search terms. Most of the time ReplaceSearchTerms should // be called. std::string ReplaceSearchTermsUsingTermsData( const TemplateURL& host, - const string16& terms, + const std::wstring& terms, int accepted_suggestion, - const string16& original_query_for_suggestion, + const std::wstring& original_query_for_suggestion, const SearchTermsData& search_terms_data) const; // Returns the raw URL. None of the parameters will have been replaced. @@ -104,11 +104,11 @@ class TemplateURLRef { // Returns a string representation of this TemplateURLRef suitable for // display. The display format is the same as the format used by Firefox. - string16 DisplayURL() const; + std::wstring DisplayURL() const; // Converts a string as returned by DisplayURL back into a string as // understood by TemplateURLRef. - static std::string DisplayURLToURLRef(const string16& display_url); + static std::string DisplayURLToURLRef(const std::wstring& display_url); // If this TemplateURLRef is valid and contains one search term, this returns // the host/path of the URL, otherwise this returns an empty string. @@ -120,8 +120,8 @@ class TemplateURLRef { const std::string& GetSearchTermKey() const; // Converts the specified term in the encoding of the host TemplateURL to a - // string16. - string16 SearchTermToString16(const TemplateURL& host, + // wide string. + std::wstring SearchTermToWide(const TemplateURL& host, const std::string& term) const; // Returns true if this TemplateURLRef has a replacement term of @@ -259,17 +259,17 @@ class TemplateURL { // If a TemplateURL has no images, the favicon for the generated URL // should be used. struct ImageRef { - ImageRef(const std::string& type, int width, int height) + ImageRef(const std::wstring& type, int width, int height) : type(type), width(width), height(height) { } - ImageRef(const std::string& type, int width, int height, const GURL& url) + ImageRef(const std::wstring& type, int width, int height, const GURL& url) : type(type), width(width), height(height), url(url) { } // Mime type for the image. // ICO image will have the format: image/x-icon or image/vnd.microsoft.icon - std::string type; + std::wstring type; // Size of the image int width; @@ -297,20 +297,20 @@ class TemplateURL { // A short description of the template. This is the name we show to the user // in various places that use keywords. For example, the location bar shows // this when the user selects the keyword. - void set_short_name(const string16& short_name) { + void set_short_name(const std::wstring& short_name) { short_name_ = short_name; } - string16 short_name() const { return short_name_; } + const std::wstring& short_name() const { return short_name_; } // An accessor for the short_name, but adjusted so it can be appropriately // displayed even if it is LTR and the UI is RTL. - string16 AdjustedShortNameForLocaleDirection() const; + std::wstring AdjustedShortNameForLocaleDirection() const; // A description of the template; this may be empty. - void set_description(const string16& description) { + void set_description(const std::wstring& description) { description_ = description; } - string16 description() const { return description_; } + const std::wstring& description() const { return description_; } // URL providing JSON results. This is typically used to provide suggestions // as your type. If NULL, this url does not support suggestions. @@ -350,8 +350,8 @@ class TemplateURL { const GURL& originating_url() const { return originating_url_; } // The shortcut for this template url. May be empty. - void set_keyword(const string16& keyword); - string16 keyword() const; + void set_keyword(const std::wstring& keyword); + const std::wstring& keyword() const; // Whether to autogenerate a keyword from the url() in GetKeyword(). Most // consumers should not need this. @@ -410,10 +410,10 @@ class TemplateURL { GURL GetFavIconURL() const; // Set of languages supported. This may be empty. - void add_language(const string16& language) { + void add_language(const std::wstring& language) { languages_.push_back(language); } - std::vector<string16> languages() const { return languages_; } + const std::vector<std::wstring>& languages() const { return languages_; } // Date this keyword was created. // @@ -487,13 +487,13 @@ class TemplateURL { // Unique identifier, used when archived to the database. void set_id(TemplateURLID id) { id_ = id;} - string16 short_name_; - string16 description_; + std::wstring short_name_; + std::wstring description_; TemplateURLRef suggestions_url_; TemplateURLRef url_; TemplateURLRef instant_url_; GURL originating_url_; - mutable string16 keyword_; + mutable std::wstring keyword_; bool autogenerate_keyword_; // If this is set, |keyword_| holds the cached // generated keyword if available. mutable bool keyword_generated_; // True if the keyword was generated. This @@ -502,7 +502,7 @@ class TemplateURL { bool show_in_default_list_; bool safe_for_autoreplace_; std::vector<ImageRef> image_refs_; - std::vector<string16> languages_; + std::vector<std::wstring> languages_; // List of supported input encodings. std::vector<std::string> input_encodings_; TemplateURLID id_; diff --git a/chrome/browser/search_engines/template_url_fetcher.cc b/chrome/browser/search_engines/template_url_fetcher.cc index a86c5c1..293f59b 100644 --- a/chrome/browser/search_engines/template_url_fetcher.cc +++ b/chrome/browser/search_engines/template_url_fetcher.cc @@ -26,7 +26,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, public: // Takes ownership of |callbacks|. RequestDelegate(TemplateURLFetcher* fetcher, - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, @@ -48,10 +48,10 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, const std::string& data); // URL of the OSDD. - GURL url() const { return osdd_url_; } + const GURL& url() const { return osdd_url_; } // Keyword to use. - string16 keyword() const { return keyword_; } + const std::wstring keyword() const { return keyword_; } // The type of search provider being fetched. ProviderType provider_type() const { return provider_type_; } @@ -62,7 +62,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, URLFetcher url_fetcher_; TemplateURLFetcher* fetcher_; scoped_ptr<TemplateURL> template_url_; - string16 keyword_; + std::wstring keyword_; const GURL osdd_url_; const GURL favicon_url_; const ProviderType provider_type_; @@ -76,7 +76,7 @@ class TemplateURLFetcher::RequestDelegate : public URLFetcher::Delegate, TemplateURLFetcher::RequestDelegate::RequestDelegate( TemplateURLFetcher* fetcher, - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, @@ -160,7 +160,7 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { // it gives wrong result when OSDD is located on third party site that // has nothing in common with search engine in OSDD. GURL keyword_url(template_url_->url()->url()); - string16 new_keyword = TemplateURLModel::GenerateKeyword( + std::wstring new_keyword = TemplateURLModel::GenerateKeyword( keyword_url, false); if (!new_keyword.empty()) keyword_ = new_keyword; @@ -183,13 +183,13 @@ void TemplateURLFetcher::RequestDelegate::AddSearchProvider() { // provider. The keyword isn't as important in this case. if (provider_type_ == EXPLICIT_DEFAULT_PROVIDER) { // The loop numbers are arbitrary and are simply a strong effort. - string16 new_keyword; + std::wstring new_keyword; for (int i = 0; i < 100; ++i) { // Concatenate a number at end of the keyword and try that. new_keyword = keyword_; // Try the keyword alone the first time if (i > 0) - new_keyword.append(base::IntToString16(i)); + new_keyword.append(UTF16ToWide(base::IntToString16(i))); if (!model->GetTemplateURLForKeyword(new_keyword) || model->CanReplaceKeyword(new_keyword, GURL(template_url_->url()->url()), @@ -268,7 +268,7 @@ TemplateURLFetcher::~TemplateURLFetcher() { } void TemplateURLFetcher::ScheduleDownload( - const string16& keyword, + const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, diff --git a/chrome/browser/search_engines/template_url_fetcher.h b/chrome/browser/search_engines/template_url_fetcher.h index 444f396..b1e15cc 100644 --- a/chrome/browser/search_engines/template_url_fetcher.h +++ b/chrome/browser/search_engines/template_url_fetcher.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2008 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. @@ -7,7 +7,6 @@ #pragma once #include "base/scoped_vector.h" -#include "base/string16.h" #include "gfx/native_widget_types.h" class GURL; @@ -34,7 +33,7 @@ class TemplateURLFetcher { // If TemplateURLFetcher is not already downloading the OSDD for osdd_url, // it is downloaded. If successful and the result can be parsed, a TemplateURL // is added to the TemplateURLModel. Takes ownership of |callbacks|. - void ScheduleDownload(const string16& keyword, + void ScheduleDownload(const std::wstring& keyword, const GURL& osdd_url, const GURL& favicon_url, TemplateURLFetcherCallbacks* callbacks, diff --git a/chrome/browser/search_engines/template_url_fetcher_unittest.cc b/chrome/browser/search_engines/template_url_fetcher_unittest.cc index ec20c66..737a349 100644 --- a/chrome/browser/search_engines/template_url_fetcher_unittest.cc +++ b/chrome/browser/search_engines/template_url_fetcher_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,7 +6,6 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/scoped_ptr.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_fetcher.h" #include "chrome/browser/search_engines/template_url_fetcher_callbacks.h" @@ -77,7 +76,7 @@ class TemplateURLFetcherTest : public testing::Test { protected: // Schedules the download of the url. - void StartDownload(const string16& keyword, + void StartDownload(const std::wstring& keyword, const std::string& osdd_file_name, TemplateURLFetcher::ProviderType provider_type, bool check_that_file_exists); @@ -155,7 +154,7 @@ void TemplateURLFetcherTest::ConfirmAddSearchProvider( } void TemplateURLFetcherTest::StartDownload( - const string16& keyword, + const std::wstring& keyword, const std::string& osdd_file_name, TemplateURLFetcher::ProviderType provider_type, bool check_that_file_exists) { @@ -184,7 +183,7 @@ void TemplateURLFetcherTest::WaitForDownloadToFinish() { } TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -204,13 +203,13 @@ TEST_F(TemplateURLFetcherTest, BasicAutodetectedTest) { const TemplateURL* t_url = test_util_.model()->GetTemplateURLForKeyword( keyword); ASSERT_TRUE(t_url); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - t_url->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + t_url->url()->DisplayURL().c_str()); EXPECT_TRUE(t_url->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -225,7 +224,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { struct { std::string description; std::string osdd_file_name; - string16 keyword; + std::wstring keyword; TemplateURLFetcher::ProviderType provider_type; } test_cases[] = { { "Duplicate keyword and osdd url with autodetected provider.", @@ -233,8 +232,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { { "Duplicate keyword and osdd url with explicit provider.", osdd_file_name, keyword, TemplateURLFetcher::EXPLICIT_PROVIDER }, { "Duplicate osdd url with explicit provider.", - osdd_file_name, keyword + ASCIIToUTF16("1"), - TemplateURLFetcher::EXPLICIT_PROVIDER }, + osdd_file_name, keyword + L"1", TemplateURLFetcher::EXPLICIT_PROVIDER }, { "Duplicate keyword with explicit provider.", osdd_file_name + "1", keyword, TemplateURLFetcher::EXPLICIT_PROVIDER } }; @@ -257,7 +255,7 @@ TEST_F(TemplateURLFetcherTest, DuplicatesThrownAway) { } TEST_F(TemplateURLFetcherTest, BasicExplicitTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -275,13 +273,13 @@ TEST_F(TemplateURLFetcherTest, BasicExplicitTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, BasicExplicitDefaultTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); test_util_.ChangeModelToLoadState(); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); @@ -299,13 +297,13 @@ TEST_F(TemplateURLFetcherTest, BasicExplicitDefaultTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -317,7 +315,7 @@ TEST_F(TemplateURLFetcherTest, AutodetectedBeforeLoadTest) { } TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -329,7 +327,7 @@ TEST_F(TemplateURLFetcherTest, ExplicitBeforeLoadTest) { } TEST_F(TemplateURLFetcherTest, ExplicitDefaultBeforeLoadTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); ASSERT_FALSE(test_util_.model()->GetTemplateURLForKeyword(keyword)); std::string osdd_file_name("simple_open_search.xml"); @@ -345,13 +343,13 @@ TEST_F(TemplateURLFetcherTest, ExplicitDefaultBeforeLoadTest) { ASSERT_EQ(1, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - EXPECT_EQ(ASCIIToUTF16("http://example.com/%s/other_stuff"), - last_callback_template_url_->url()->DisplayURL()); + EXPECT_STREQ(L"http://example.com/%s/other_stuff", + last_callback_template_url_->url()->DisplayURL().c_str()); EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); } TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { - string16 keyword(ASCIIToUTF16("test")); + std::wstring keyword(L"test"); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://example.com/", 0, 0); @@ -386,5 +384,5 @@ TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { ASSERT_EQ(0, add_provider_called_); ASSERT_EQ(3, callbacks_destroyed_); ASSERT_TRUE(last_callback_template_url_.get()); - ASSERT_NE(keyword, last_callback_template_url_->keyword()); + ASSERT_STRNE(keyword.c_str(), last_callback_template_url_->keyword().c_str()); } diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 5894932..7372262 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -46,7 +46,7 @@ static const char kTemplateParameter[] = "%s"; // Term used when generating a search url. Use something obscure so that on // the rare case the term replaces the URL it's unlikely another keyword would // have the same url. -static const char kReplacementTerm[] = "blah.blah.blah.blah.blah"; +static const wchar_t kReplacementTerm[] = L"blah.blah.blah.blah.blah"; // Removes from the vector any template URL that was created because of @@ -129,8 +129,8 @@ TemplateURLModel::~TemplateURLModel() { } // static -string16 TemplateURLModel::GenerateKeyword(const GURL& url, - bool autodetected) { +std::wstring TemplateURLModel::GenerateKeyword(const GURL& url, + bool autodetected) { // Don't autogenerate keywords for referrers that are the result of a form // submission (TODO: right now we approximate this by checking for the URL // having a query, but we should replace this with a call to WebCore to see if @@ -143,43 +143,44 @@ string16 TemplateURLModel::GenerateKeyword(const GURL& url, if (!url.is_valid() || (autodetected && (url.has_query() || !url.SchemeIs(chrome::kHttpScheme) || ((url.path() != "") && (url.path() != "/"))))) - return string16(); + return std::wstring(); // Strip "www." off the front of the keyword; otherwise the keyword won't work // properly. See http://code.google.com/p/chromium/issues/detail?id=6984 . - return net::StripWWW(UTF8ToUTF16(url.host())); + return UTF16ToWideHack(net::StripWWW(UTF8ToUTF16(url.host()))); } // static -string16 TemplateURLModel::CleanUserInputKeyword(const string16& keyword) { +std::wstring TemplateURLModel::CleanUserInputKeyword( + const std::wstring& keyword) { // Remove the scheme. - string16 result(l10n_util::ToLower(keyword)); + std::wstring result(UTF16ToWide(l10n_util::ToLower(WideToUTF16(keyword)))); url_parse::Component scheme_component; - if (url_parse::ExtractScheme(UTF16ToUTF8(keyword).c_str(), + if (url_parse::ExtractScheme(WideToUTF8(keyword).c_str(), static_cast<int>(keyword.length()), &scheme_component)) { // If the scheme isn't "http" or "https", bail. The user isn't trying to // type a web address, but rather an FTP, file:, or other scheme URL, or a // search query with some sort of initial operator (e.g. "site:"). if (result.compare(0, scheme_component.end(), - ASCIIToUTF16(chrome::kHttpScheme)) && + ASCIIToWide(chrome::kHttpScheme)) && result.compare(0, scheme_component.end(), - ASCIIToUTF16(chrome::kHttpsScheme))) - return string16(); + ASCIIToWide(chrome::kHttpsScheme))) + return std::wstring(); // Include trailing ':'. result.erase(0, scheme_component.end() + 1); // Many schemes usually have "//" after them, so strip it too. - const string16 after_scheme(ASCIIToUTF16("//")); + const std::wstring after_scheme(L"//"); if (result.compare(0, after_scheme.length(), after_scheme) == 0) result.erase(0, after_scheme.length()); } // Remove leading "www.". - result = net::StripWWW(result); + result = UTF16ToWideHack(net::StripWWW(WideToUTF16(result))); // Remove trailing "/". - return (result.length() > 0 && result[result.length() - 1] == '/') ? + return (result.length() > 0 && result[result.length() - 1] == L'/') ? result.substr(0, result.length() - 1) : result; } @@ -205,13 +206,12 @@ GURL TemplateURLModel::GenerateSearchURLUsingTermsData( return GURL(search_ref->url()); return GURL(search_ref->ReplaceSearchTermsUsingTermsData( - *t_url, ASCIIToUTF16(kReplacementTerm), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - string16(), search_terms_data)); + *t_url, kReplacementTerm, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, + std::wstring(), search_terms_data)); } bool TemplateURLModel::CanReplaceKeyword( - const string16& keyword, + const std::wstring& keyword, const GURL& url, const TemplateURL** template_url_to_replace) { DCHECK(!keyword.empty()); // This should only be called for non-empty @@ -237,9 +237,9 @@ bool TemplateURLModel::CanReplaceKeyword( } void TemplateURLModel::FindMatchingKeywords( - const string16& prefix, + const std::wstring& prefix, bool support_replacement_only, - std::vector<string16>* matches) const { + std::vector<std::wstring>* matches) const { // Sanity check args. if (prefix.empty()) return; @@ -265,7 +265,7 @@ void TemplateURLModel::FindMatchingKeywords( } const TemplateURL* TemplateURLModel::GetTemplateURLForKeyword( - const string16& keyword) const { + const std::wstring& keyword) const { KeywordToTemplateMap::const_iterator elem( keyword_to_template_map_.find(keyword)); return (elem == keyword_to_template_map_.end()) ? NULL : elem->second; @@ -320,10 +320,10 @@ void TemplateURLModel::RegisterExtensionKeyword(const Extension* extension) { } const TemplateURL* existing_url = GetTemplateURLForExtension(extension); - string16 keyword = UTF8ToUTF16(extension->omnibox_keyword()); + std::wstring keyword = UTF8ToWide(extension->omnibox_keyword()); scoped_ptr<TemplateURL> template_url(new TemplateURL); - template_url->set_short_name(UTF8ToUTF16(extension->name())); + template_url->set_short_name(UTF8ToWide(extension->name())); template_url->set_keyword(keyword); // This URL is not actually used for navigation. It holds the extension's // ID, as well as forcing the TemplateURL to be treated as a search keyword. @@ -372,8 +372,8 @@ void TemplateURLModel::IncrementUsageCount(const TemplateURL* url) { } void TemplateURLModel::ResetTemplateURL(const TemplateURL* url, - const string16& title, - const string16& keyword, + const std::wstring& title, + const std::wstring& keyword, const std::string& search_url) { TemplateURL new_url(*url); new_url.set_short_name(title); @@ -538,8 +538,8 @@ void TemplateURLModel::OnWebDataServiceRequestDone( NotifyLoaded(); } -string16 TemplateURLModel::GetKeywordShortName(const string16& keyword, - bool* is_extension_keyword) { +std::wstring TemplateURLModel::GetKeywordShortName(const std::wstring& keyword, + bool* is_extension_keyword) { const TemplateURL* template_url = GetTemplateURLForKeyword(keyword); // TODO(sky): Once LocationBarView adds a listener to the TemplateURLModel @@ -549,7 +549,7 @@ string16 TemplateURLModel::GetKeywordShortName(const string16& keyword, return template_url->AdjustedShortNameForLocaleDirection(); } *is_extension_keyword = false; - return string16(); + return std::wstring(); } void TemplateURLModel::Observe(NotificationType type, @@ -602,12 +602,12 @@ void TemplateURLModel::RegisterUserPrefs(PrefService* prefs) { void TemplateURLModel::SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term) { + const std::wstring& term) { HistoryService* history = profile_ ? profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; if (!history) return; - history->SetKeywordSearchTermsForURL(url, t_url->id(), term); + history->SetKeywordSearchTermsForURL(url, t_url->id(), WideToUTF16Hack(term)); } void TemplateURLModel::Init(const Initializer* initializers, @@ -640,15 +640,15 @@ void TemplateURLModel::Init(const Initializer* initializers, size_t template_position = std::string(initializers[i].url).find(kTemplateParameter); - DCHECK(template_position != std::string::npos); + DCHECK(template_position != std::wstring::npos); std::string osd_url(initializers[i].url); osd_url.replace(template_position, arraysize(kTemplateParameter) - 1, kSearchTermParameter); // TemplateURLModel ends up owning the TemplateURL, don't try and free it. TemplateURL* template_url = new TemplateURL(); - template_url->set_keyword(UTF8ToUTF16(initializers[i].keyword)); - template_url->set_short_name(UTF8ToUTF16(initializers[i].content)); + template_url->set_keyword(initializers[i].keyword); + template_url->set_short_name(initializers[i].content); template_url->SetURL(osd_url, 0, 0); AddNoNotify(template_url); } @@ -777,8 +777,8 @@ void TemplateURLModel::SaveDefaultSearchProviderToPrefs( if (!icon_gurl.is_empty()) icon_url = icon_gurl.spec(); encodings = JoinString(t_url->input_encodings(), ';'); - short_name = UTF16ToUTF8(t_url->short_name()); - keyword = UTF16ToUTF8(t_url->keyword()); + short_name = WideToUTF8(t_url->short_name()); + keyword = WideToUTF8(t_url->keyword()); id_string = base::Int64ToString(t_url->id()); prepopulate_id = base::Int64ToString(t_url->prepopulate_id()); } @@ -822,10 +822,10 @@ bool TemplateURLModel::LoadDefaultSearchProviderFromPrefs( return true; } - string16 name = - UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderName)); - string16 keyword = - UTF8ToUTF16(prefs->GetString(prefs::kDefaultSearchProviderKeyword)); + std::wstring name = + UTF8ToWide(prefs->GetString(prefs::kDefaultSearchProviderName)); + std::wstring keyword = + UTF8ToWide(prefs->GetString(prefs::kDefaultSearchProviderKeyword)); std::string icon_url = prefs->GetString(prefs::kDefaultSearchProviderIconURL); std::string encodings = @@ -983,7 +983,7 @@ void TemplateURLModel::UpdateKeywordSearchTermsForURL( if (terms_iterator != query_terms.end() && !terms_iterator->second.empty()) { SetKeywordSearchTermsForURL( - *i, row.url(), search_ref->SearchTermToString16(*(*i), + *i, row.url(), search_ref->SearchTermToWide(*(*i), terms_iterator->second)); } } @@ -1006,8 +1006,7 @@ void TemplateURLModel::AddTabToSearchVisit(const TemplateURL& t_url) { if (!history) return; - GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(t_url.keyword()), - std::string())); + GURL url(URLFixerUpper::FixupURL(WideToUTF8(t_url.keyword()), std::string())); if (!url.is_valid()) return; diff --git a/chrome/browser/search_engines/template_url_model.h b/chrome/browser/search_engines/template_url_model.h index 504e79f..a16bad7 100644 --- a/chrome/browser/search_engines/template_url_model.h +++ b/chrome/browser/search_engines/template_url_model.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -45,7 +45,7 @@ struct URLVisitedDetails; // // There is a TemplateURLModel per Profile. // -// TemplateURLModel does not load the vector of TemplateURLs in its +// TemplateURLModel does not load the vector of TemplateURLs in it's // constructor (except for testing). Use the Load method to trigger a load. // When TemplateURLModel has completed loading, observers are notified via // OnTemplateURLModelChanged as well as the TEMPLATE_URL_MODEL_LOADED @@ -63,9 +63,9 @@ class TemplateURLModel : public WebDataServiceConsumer, // Struct used for initializing the data store with fake data. // Each initializer is mapped to a TemplateURL. struct Initializer { - const char* const keyword; + const wchar_t* const keyword; const char* const url; - const char* const content; + const wchar_t* const content; }; explicit TemplateURLModel(Profile* profile); @@ -78,11 +78,11 @@ class TemplateURLModel : public WebDataServiceConsumer, // don't generate keywords for a variety of situations where we would probably // not want to auto-add keywords, such as keywords for searches on pages that // themselves come from form submissions. - static string16 GenerateKeyword(const GURL& url, bool autodetected); + static std::wstring GenerateKeyword(const GURL& url, bool autodetected); // Removes any unnecessary characters from a user input keyword. // This removes the leading scheme, "www." and any trailing slash. - static string16 CleanUserInputKeyword(const string16& keyword); + static std::wstring CleanUserInputKeyword(const std::wstring& keyword); // Returns the search url for t_url. Returns an empty GURL if t_url has no // url(). @@ -102,22 +102,23 @@ class TemplateURLModel : public WebDataServiceConsumer, // // url gives the url of the search query. The url is used to avoid generating // a TemplateURL for an existing TemplateURL that shares the same host. - bool CanReplaceKeyword(const string16& keyword, + bool CanReplaceKeyword(const std::wstring& keyword, const GURL& url, const TemplateURL** template_url_to_replace); // Returns (in |matches|) all keywords beginning with |prefix|, sorted // shortest-first. If support_replacement_only is true, only keywords that // support replacement are returned. - void FindMatchingKeywords(const string16& prefix, + void FindMatchingKeywords(const std::wstring& prefix, bool support_replacement_only, - std::vector<string16>* matches) const; + std::vector<std::wstring>* matches) const; // Looks up |keyword| and returns the element it maps to. Returns NULL if // the keyword was not found. // The caller should not try to delete the returned pointer; the data store // retains ownership of it. - const TemplateURL* GetTemplateURLForKeyword(const string16& keyword) const; + const TemplateURL* GetTemplateURLForKeyword( + const std::wstring& keyword) const; // Returns the first TemplateURL found with a URL using the specified |host|, // or NULL if there are no such TemplateURLs @@ -166,8 +167,8 @@ class TemplateURLModel : public WebDataServiceConsumer, // Resets the title, keyword and search url of the specified TemplateURL. // The TemplateURL is marked as not replaceable. void ResetTemplateURL(const TemplateURL* url, - const string16& title, - const string16& keyword, + const std::wstring& title, + const std::wstring& keyword, const std::string& search_url); // Return true if the given |url| can be made the default. @@ -210,8 +211,8 @@ class TemplateURLModel : public WebDataServiceConsumer, // Returns the locale-direction-adjusted short name for the given keyword. // Also sets the out param to indicate whether the keyword belongs to an // extension. - string16 GetKeywordShortName(const string16& keyword, - bool* is_extension_keyword); + std::wstring GetKeywordShortName(const std::wstring& keyword, + bool* is_extension_keyword); // NotificationObserver method. TemplateURLModel listens for three // notification types: @@ -244,7 +245,7 @@ class TemplateURLModel : public WebDataServiceConsumer, // This exists and is virtual for testing. virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term); + const std::wstring& term); private: FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, BuildQueryTerms); @@ -257,7 +258,7 @@ class TemplateURLModel : public WebDataServiceConsumer, FRIEND_TEST_ALL_PREFIXES(TemplateURLModelTest, MergeDeletesUnusedProviders); friend class TemplateURLModelTestUtil; - typedef std::map<string16, const TemplateURL*> KeywordToTemplateMap; + typedef std::map<std::wstring, const TemplateURL*> KeywordToTemplateMap; typedef std::vector<const TemplateURL*> TemplateURLVector; // Helper functor for FindMatchingKeywords(), for finding the range of diff --git a/chrome/browser/search_engines/template_url_model_test_util.cc b/chrome/browser/search_engines/template_url_model_test_util.cc index 477999c..7803b12 100644 --- a/chrome/browser/search_engines/template_url_model_test_util.cc +++ b/chrome/browser/search_engines/template_url_model_test_util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -85,8 +85,8 @@ class TestingTemplateURLModel : public TemplateURLModel { : TemplateURLModel(profile) { } - string16 GetAndClearSearchTerm() { - string16 search_term; + std::wstring GetAndClearSearchTerm() { + std::wstring search_term; search_term.swap(search_term_); return search_term; } @@ -94,12 +94,12 @@ class TestingTemplateURLModel : public TemplateURLModel { protected: virtual void SetKeywordSearchTermsForURL(const TemplateURL* t_url, const GURL& url, - const string16& term) { + const std::wstring& term) { search_term_ = term; } private: - string16 search_term_; + std::wstring search_term_; DISALLOW_COPY_AND_ASSIGN(TestingTemplateURLModel); }; @@ -210,7 +210,7 @@ void TemplateURLModelTestUtil::ResetModel(bool verify_load) { VerifyLoad(); } -string16 TemplateURLModelTestUtil::GetAndClearSearchTerm() { +std::wstring TemplateURLModelTestUtil::GetAndClearSearchTerm() { return static_cast<TestingTemplateURLModel*>(model())->GetAndClearSearchTerm(); } diff --git a/chrome/browser/search_engines/template_url_model_test_util.h b/chrome/browser/search_engines/template_url_model_test_util.h index 18cfb58..058b64b 100644 --- a/chrome/browser/search_engines/template_url_model_test_util.h +++ b/chrome/browser/search_engines/template_url_model_test_util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,7 +12,6 @@ #include "base/message_loop.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "base/string16.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/template_url_model_observer.h" @@ -71,7 +70,7 @@ class TemplateURLModelTestUtil : public TemplateURLModelObserver { // Returns the search term from the last invocation of // TemplateURLModel::SetKeywordSearchTermsForURL and clears the search term. - string16 GetAndClearSearchTerm(); + std::wstring GetAndClearSearchTerm(); // Set the google base url. void SetGoogleBaseURL(const std::string& base_url) const; diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc index ab64c2a..9e5477c 100644 --- a/chrome/browser/search_engines/template_url_model_unittest.cc +++ b/chrome/browser/search_engines/template_url_model_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,6 @@ #include "base/string_util.h" #include "base/ref_counted.h" #include "base/threading/thread.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_notifications.h" @@ -78,8 +77,8 @@ class TestSearchTermsData : public SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const { - return string16(); + virtual std::wstring GetRlzParameterValue() const { + return std::wstring(); } #endif @@ -94,8 +93,8 @@ class TestSearchTermsData : public SearchTermsData { static TemplateURL* CreatePreloadedTemplateURL() { TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.unittest.com/", 0, 0); - t_url->set_keyword(ASCIIToUTF16("unittest")); - t_url->set_short_name(ASCIIToUTF16("unittest")); + t_url->set_keyword(L"unittest"); + t_url->set_short_name(L"unittest"); t_url->set_safe_for_autoreplace(true); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); @@ -116,22 +115,22 @@ class TemplateURLModelTest : public testing::Test { test_util_.TearDown(); } - TemplateURL* AddKeywordWithDate(const std::string& keyword, + TemplateURL* AddKeywordWithDate(const std::wstring& keyword, bool autogenerate_keyword, const std::string& url, const std::string& suggest_url, const std::string& fav_icon_url, const std::string& encodings, - const std::string& short_name, + const std::wstring& short_name, bool safe_for_autoreplace, Time created_date) { TemplateURL* template_url = new TemplateURL(); template_url->SetURL(url, 0, 0); template_url->SetSuggestionsURL(suggest_url, 0, 0); template_url->SetFavIconURL(GURL(fav_icon_url)); - template_url->set_keyword(UTF8ToUTF16(keyword)); + template_url->set_keyword(keyword); template_url->set_autogenerate_keyword(autogenerate_keyword); - template_url->set_short_name(UTF8ToUTF16(short_name)); + template_url->set_short_name(short_name); std::vector<std::string> encodings_vector; base::SplitString(encodings, ';', &encodings_vector); template_url->set_input_encodings(encodings_vector); @@ -241,12 +240,12 @@ class TemplateURLModelTest : public testing::Test { prefs::kDefaultSearchProviderPrepopulateID); } - // Creates a TemplateURL with the same prepopulated id as a real prepopulated + // Creates a TemplateURL with the same prepopluated id as a real prepopulated // item. The input number determines which prepopulated item. The caller is // responsible for owning the returned TemplateURL*. TemplateURL* CreateReplaceablePreloadedTemplateURL( size_t index_offset_from_default, - string16* prepopulated_display_url); + std::wstring* prepopulated_display_url); // Verifies the behavior of when a preloaded url later gets changed. // Since the input is the offset from the default, when one passes in @@ -270,7 +269,7 @@ class TemplateURLModelTest : public testing::Test { void VerifyLoad() { test_util_.VerifyLoad(); } void ChangeModelToLoadState() { test_util_.ChangeModelToLoadState(); } void ResetModel(bool verify_load) { test_util_.ResetModel(verify_load); } - string16 GetAndClearSearchTerm() { + std::wstring GetAndClearSearchTerm() { return test_util_.GetAndClearSearchTerm(); } void SetGoogleBaseURL(const std::string& base_url) const { @@ -324,7 +323,7 @@ void TestGenerateSearchURL::RunTest() { TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( size_t index_offset_from_default, - string16* prepopulated_display_url) { + std::wstring* prepopulated_display_url) { TemplateURL* t_url = CreatePreloadedTemplateURL(); ScopedVector<TemplateURL> prepopulated_urls; size_t default_search_provider_index = 0; @@ -345,37 +344,39 @@ TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL( void TemplateURLModelTest::TestLoadUpdatingPreloadedURL( size_t index_offset_from_default) { - string16 prepopulated_url; + std::wstring prepopulated_url; TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( index_offset_from_default, &prepopulated_url); t_url->set_safe_for_autoreplace(false); - string16 original_url = t_url->url()->DisplayURL(); - ASSERT_NE(prepopulated_url, original_url); + std::wstring original_url = t_url->url()->DisplayURL(); + ASSERT_STRNE(prepopulated_url.c_str(), original_url.c_str()); // Then add it to the model and save it all. ChangeModelToLoadState(); model()->Add(t_url); const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_EQ(t_url, keyword_url); - ASSERT_EQ(original_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(original_url.c_str(), keyword_url->url()->DisplayURL().c_str()); BlockTillServiceProcessesRequests(); // Now reload the model and verify that the merge updates the url. ResetModel(true); - keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); - ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(prepopulated_url.c_str(), + keyword_url->url()->DisplayURL().c_str()); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); // Reload the model to verify that change was saved correctly. ResetModel(true); - keyword_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + keyword_url = model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); - ASSERT_EQ(prepopulated_url, keyword_url->url()->DisplayURL()); + ASSERT_STREQ(prepopulated_url.c_str(), + keyword_url->url()->DisplayURL().c_str()); } TEST_F(TemplateURLModelTest, MAYBE_Load) { @@ -389,15 +390,14 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword")); - t_url->set_short_name(ASCIIToUTF16("google")); + t_url->set_keyword(L"keyword"); + t_url->set_short_name(L"google"); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); t_url->set_safe_for_autoreplace(true); model()->Add(t_url); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); VerifyObserverCount(1); BlockTillServiceProcessesRequests(); // We need to clone as model takes ownership of TemplateURL and will @@ -410,28 +410,24 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { // Reload the model to verify it was actually saved to the database. ResetModel(true); ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); - const TemplateURL* loaded_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")); + const TemplateURL* loaded_url = model()->GetTemplateURLForKeyword(L"keyword"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); // Mutate an element and verify it succeeded. - model()->ResetTemplateURL(loaded_url, ASCIIToUTF16("a"), - ASCIIToUTF16("b"), "c"); - ASSERT_EQ(ASCIIToUTF16("a"), loaded_url->short_name()); - ASSERT_EQ(ASCIIToUTF16("b"), loaded_url->keyword()); + model()->ResetTemplateURL(loaded_url, L"a", L"b", "c"); + ASSERT_EQ(L"a", loaded_url->short_name()); + ASSERT_EQ(L"b", loaded_url->keyword()); ASSERT_EQ("c", loaded_url->url()->url()); ASSERT_FALSE(loaded_url->safe_for_autoreplace()); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("keyword"), - GURL(), NULL)); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("b"), GURL(), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"keyword", GURL(), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"b", GURL(), NULL)); cloned_url = *loaded_url; BlockTillServiceProcessesRequests(); ResetModel(true); ASSERT_EQ(1 + initial_count, model()->GetTemplateURLs().size()); - loaded_url = model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")); + loaded_url = model()->GetTemplateURLForKeyword(L"b"); ASSERT_TRUE(loaded_url != NULL); AssertEquals(cloned_url, *loaded_url); @@ -440,30 +436,28 @@ TEST_F(TemplateURLModelTest, AddUpdateRemove) { VerifyObserverCount(1); ResetModel(true); ASSERT_EQ(initial_count, model()->GetTemplateURLs().size()); - EXPECT_TRUE(model()->GetTemplateURLForKeyword(ASCIIToUTF16("b")) == NULL); + EXPECT_TRUE(model()->GetTemplateURLForKeyword(L"b") == NULL); } TEST_F(TemplateURLModelTest, GenerateKeyword) { - ASSERT_EQ(string16(), TemplateURLModel::GenerateKeyword(GURL(), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL(), true)); // Shouldn't generate keywords for https. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); - ASSERT_EQ(ASCIIToUTF16("foo"), - TemplateURLModel::GenerateKeyword(GURL("http://foo"), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("https://blah"), true)); + ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://foo"), + true)); // www. should be stripped. - ASSERT_EQ(ASCIIToUTF16("foo"), - TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), true)); + ASSERT_EQ(L"foo", TemplateURLModel::GenerateKeyword(GURL("http://www.foo"), + true)); // Shouldn't generate keywords with paths, if autodetected. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), true)); - ASSERT_EQ(ASCIIToUTF16("blah"), - TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), false)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), + true)); + ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/foo"), + false)); // FTP shouldn't generate a keyword. - ASSERT_EQ(string16(), - TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); + ASSERT_EQ(L"", TemplateURLModel::GenerateKeyword(GURL("ftp://blah/"), true)); // Make sure we don't get a trailing / - ASSERT_EQ(ASCIIToUTF16("blah"), - TemplateURLModel::GenerateKeyword(GURL("http://blah/"), true)); + ASSERT_EQ(L"blah", TemplateURLModel::GenerateKeyword(GURL("http://blah/"), + true)); } TEST_F(TemplateURLModelTest, GenerateSearchURL) { @@ -498,21 +492,21 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { EXPECT_EQ(0U, model()->GetTemplateURLs().size()); // Create one with a 0 time. - AddKeywordWithDate("key1", false, "http://foo1", "http://suggest1", - "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + AddKeywordWithDate(L"key1", false, "http://foo1", "http://suggest1", + "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Create one for now and +/- 1 day. - AddKeywordWithDate("key2", false, "http://foo2", "http://suggest2", - "http://icon2", "UTF-8;UTF-16", "name2", true, + AddKeywordWithDate(L"key2", false, "http://foo2", "http://suggest2", + "http://icon2", "UTF-8;UTF-16", L"name2", true, now - one_day); - AddKeywordWithDate("key3", false, "http://foo3", "", "", "", "name3", + AddKeywordWithDate(L"key3", false, "http://foo3", "", "", "", L"name3", true, now); - AddKeywordWithDate("key4", false, "http://foo4", "", "", "", "name4", + AddKeywordWithDate(L"key4", false, "http://foo4", "", "", "", L"name4", true, now + one_day); // Try the other three states. - AddKeywordWithDate("key5", false, "http://foo5", "http://suggest5", - "http://icon5", "UTF-8;UTF-16", "name5", false, now); - AddKeywordWithDate("key6", false, "http://foo6", "http://suggest6", - "http://icon6", "UTF-8;UTF-16", "name6", false, + AddKeywordWithDate(L"key5", false, "http://foo5", "http://suggest5", + "http://icon5", "UTF-8;UTF-16", L"name5", false, now); + AddKeywordWithDate(L"key6", false, "http://foo6", "http://suggest6", + "http://icon6", "UTF-8;UTF-16", L"name6", false, month_ago); // We just added a few items, validate them. @@ -529,17 +523,17 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { EXPECT_EQ(3U, model()->GetTemplateURLs().size()); // Make sure the right values remain. - EXPECT_EQ(ASCIIToUTF16("key1"), model()->GetTemplateURLs()[0]->keyword()); + EXPECT_EQ(L"key1", model()->GetTemplateURLs()[0]->keyword()); EXPECT_TRUE(model()->GetTemplateURLs()[0]->safe_for_autoreplace()); EXPECT_EQ(0U, model()->GetTemplateURLs()[0]->date_created().ToInternalValue()); - EXPECT_EQ(ASCIIToUTF16("key5"), model()->GetTemplateURLs()[1]->keyword()); + EXPECT_EQ(L"key5", model()->GetTemplateURLs()[1]->keyword()); EXPECT_FALSE(model()->GetTemplateURLs()[1]->safe_for_autoreplace()); EXPECT_EQ(now.ToInternalValue(), model()->GetTemplateURLs()[1]->date_created().ToInternalValue()); - EXPECT_EQ(ASCIIToUTF16("key6"), model()->GetTemplateURLs()[2]->keyword()); + EXPECT_EQ(L"key6", model()->GetTemplateURLs()[2]->keyword()); EXPECT_FALSE(model()->GetTemplateURLs()[2]->safe_for_autoreplace()); EXPECT_EQ(month_ago.ToInternalValue(), model()->GetTemplateURLs()[2]->date_created().ToInternalValue()); @@ -555,8 +549,8 @@ TEST_F(TemplateURLModelTest, Reset) { const size_t initial_count = model()->GetTemplateURLs().size(); TemplateURL* t_url = new TemplateURL(); t_url->SetURL("http://www.google.com/foo/bar", 0, 0); - t_url->set_keyword(ASCIIToUTF16("keyword")); - t_url->set_short_name(ASCIIToUTF16("google")); + t_url->set_keyword(L"keyword"); + t_url->set_short_name(L"google"); GURL favicon_url("http://favicon.url"); t_url->SetFavIconURL(favicon_url); t_url->set_date_created(Time::FromTimeT(100)); @@ -566,8 +560,8 @@ TEST_F(TemplateURLModelTest, Reset) { BlockTillServiceProcessesRequests(); // Reset the short name, keyword, url and make sure it takes. - const string16 new_short_name(ASCIIToUTF16("a")); - const string16 new_keyword(ASCIIToUTF16("b")); + const std::wstring new_short_name(L"a"); + const std::wstring new_keyword(L"b"); const std::string new_url("c"); model()->ResetTemplateURL(t_url, new_short_name, new_keyword, new_url); ASSERT_EQ(new_short_name, t_url->short_name()); @@ -576,8 +570,7 @@ TEST_F(TemplateURLModelTest, Reset) { // Make sure the mappings in the model were updated. ASSERT_TRUE(model()->GetTemplateURLForKeyword(new_keyword) == t_url); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("keyword")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"keyword") == NULL); TemplateURL last_url = *t_url; @@ -594,8 +587,8 @@ TEST_F(TemplateURLModelTest, DefaultSearchProvider) { // Add a new TemplateURL. VerifyLoad(); const size_t initial_count = model()->GetTemplateURLs().size(); - TemplateURL* t_url = AddKeywordWithDate("key1", false, "http://foo1", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + TemplateURL* t_url = AddKeywordWithDate(L"key1", false, "http://foo1", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); test_util_.ResetObserverCount(); model()->SetDefaultSearchProvider(t_url); @@ -626,8 +619,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { const size_t initial_count = model()->GetTemplateURLs().size(); - AddKeywordWithDate("", false, "http://foo1", "http://sugg1", - "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + AddKeywordWithDate(std::wstring(), false, "http://foo1", "http://sugg1", + "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // We just added a few items, validate them. ASSERT_EQ(initial_count + 1, model()->GetTemplateURLs().size()); @@ -649,40 +642,36 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { ChangeModelToLoadState(); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), GURL(), NULL)); - TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo1", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL(), NULL)); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo1", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo2"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo2"), NULL)); + ASSERT_FALSE(model()->CanReplaceKeyword(L"foo", GURL("http://foo2"), NULL)); } TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { ChangeModelToLoadState(); - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("foo"), - GURL("http://foo.com"), NULL)); - TemplateURL* t_url = AddKeywordWithDate("foo", false, "http://foo.com", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", true, Time()); + ASSERT_TRUE(model()->CanReplaceKeyword(L"foo", GURL("http://foo.com"), NULL)); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, "http://foo.com", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. - ASSERT_TRUE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), - GURL("http://foo.com"), NULL)); + ASSERT_TRUE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); // ResetTemplateURL marks the TemplateURL as unsafe to replace, so it should // no longer be replaceable. model()->ResetTemplateURL(t_url, t_url->short_name(), t_url->keyword(), t_url->url()->url()); - ASSERT_FALSE(model()->CanReplaceKeyword(ASCIIToUTF16("bar"), + ASSERT_FALSE(model()->CanReplaceKeyword(L"bar", GURL("http://foo.com"), NULL)); } @@ -703,7 +692,7 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { template_url->SetURL("http://url", 0, 0); template_url->SetSuggestionsURL("http://url2", 0, 0); template_url->SetInstantURL("http://instant", 0, 0); - template_url->set_short_name(ASCIIToUTF16("a")); + template_url->set_short_name(L"a"); template_url->set_safe_for_autoreplace(true); template_url->set_date_created(Time::FromTimeT(100)); @@ -733,7 +722,7 @@ TEST_F(TemplateURLModelTest, DefaultSearchProviderLoadedFromPrefs) { ASSERT_EQ("http://url2", default_turl->suggestions_url()->url()); ASSERT_TRUE(default_turl->instant_url()); EXPECT_EQ("http://instant", default_turl->instant_url()->url()); - ASSERT_EQ(ASCIIToUTF16("a"), default_turl->short_name()); + ASSERT_EQ(L"a", default_turl->short_name()); ASSERT_EQ(id, default_turl->id()); // Now do a load and make sure the default search provider really takes. @@ -793,20 +782,20 @@ TEST_F(TemplateURLModelTest, BuildQueryTerms) { TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { struct TestData { const std::string url; - const string16 term; + const std::wstring term; } data[] = { - { "http://foo/", string16() }, - { "http://foo/foo?q=xx", string16() }, - { "http://x/bar?q=xx", string16() }, - { "http://x/foo?y=xx", string16() }, - { "http://x/foo?q=xx", ASCIIToUTF16("xx") }, - { "http://x/foo?a=b&q=xx", ASCIIToUTF16("xx") }, - { "http://x/foo?q=b&q=xx", string16() }, + { "http://foo/", L"" }, + { "http://foo/foo?q=xx", L"" }, + { "http://x/bar?q=xx", L"" }, + { "http://x/foo?y=xx", L"" }, + { "http://x/foo?q=xx", L"xx" }, + { "http://x/foo?a=b&q=xx", L"xx" }, + { "http://x/foo?q=b&q=xx", L"" }, }; ChangeModelToLoadState(); - AddKeywordWithDate("x", false, "http://x/foo?q={searchTerms}", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name", false, Time()); + AddKeywordWithDate(L"x", false, "http://x/foo?q={searchTerms}", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { history::URLVisitedDetails details; @@ -827,15 +816,15 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { }; ChangeModelToLoadState(); - AddKeywordWithDate("x", false, "http://x/foo", "http://sugg1", - "http://icon1", "UTF-8;UTF-16", "name", false, Time()); + AddKeywordWithDate(L"x", false, "http://x/foo", "http://sugg1", + "http://icon1", "UTF-8;UTF-16", L"name", false, Time()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { history::URLVisitedDetails details; details.row = history::URLRow(GURL(data[i].url)); details.transition = 0; model()->UpdateKeywordSearchTermsForURL(details); - ASSERT_EQ(string16(), GetAndClearSearchTerm()); + ASSERT_EQ(std::wstring(), GetAndClearSearchTerm()); } } @@ -845,12 +834,12 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { // test. ChangeModelToLoadState(); SetGoogleBaseURL("http://google.com/"); - const TemplateURL* t_url = AddKeywordWithDate("", true, + const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true, "{google:baseURL}?q={searchTerms}", "http://sugg1", "http://icon1", - "UTF-8;UTF-16", "name", false, Time()); + "UTF-8;UTF-16", L"name", false, Time()); ASSERT_EQ(t_url, model()->GetTemplateURLForHost("google.com")); EXPECT_EQ("google.com", t_url->url()->GetHost()); - EXPECT_EQ(ASCIIToUTF16("google.com"), t_url->keyword()); + EXPECT_EQ(L"google.com", t_url->keyword()); // Change the Google base url. test_util_.ResetObserverCount(); @@ -861,9 +850,9 @@ TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { ASSERT_EQ(t_url, model()->GetTemplateURLForHost("foo.com")); EXPECT_TRUE(model()->GetTemplateURLForHost("google.com") == NULL); EXPECT_EQ("foo.com", t_url->url()->GetHost()); - EXPECT_EQ(ASCIIToUTF16("foo.com"), t_url->keyword()); + EXPECT_EQ(L"foo.com", t_url->keyword()); EXPECT_EQ("http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, - ASCIIToUTF16("x"), TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); } struct QueryHistoryCallbackImpl { @@ -892,16 +881,16 @@ TEST_F(TemplateURLModelTest, GenerateVisitOnKeyword) { // Create a keyword. TemplateURL* t_url = AddKeywordWithDate( - "keyword", false, "http://foo.com/foo?query={searchTerms}", - "http://sugg1", "http://icon1", "UTF-8;UTF-16", "keyword", - true, base::Time::Now()); + L"keyword", false, "http://foo.com/foo?query={searchTerms}", + "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"keyword", true, + base::Time::Now()); // Add a visit that matches the url of the keyword. HistoryService* history = profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); history->AddPage( - GURL(t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("blah"), 0, - string16())), + GURL(t_url->url()->ReplaceSearchTerms(*t_url, L"blah", 0, + std::wstring())), NULL, 0, GURL(), PageTransition::KEYWORD, history::RedirectList(), history::SOURCE_BROWSED, false); @@ -933,14 +922,12 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { TemplateURL* t_url = CreatePreloadedTemplateURL(); ChangeModelToLoadState(); model()->Add(t_url); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); BlockTillServiceProcessesRequests(); // Ensure that merging clears this engine. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -948,8 +935,7 @@ TEST_F(TemplateURLModelTest, LoadDeletesUnusedProvider) { // Reload the model to verify that the database was updated as a result of the // merge. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) == NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") == NULL); } // Make sure that load routine doesn't delete prepopulated engines that no @@ -963,7 +949,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Do the copy after t_url is added so that the id is set. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); // Wait for any saves to finish. BlockTillServiceProcessesRequests(); @@ -971,7 +957,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Ensure that merging won't clear it if the user has edited it. ResetModel(true); const TemplateURL* url_for_unittest = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(url_for_unittest != NULL); AssertEquals(copy_t_url, *url_for_unittest); @@ -980,8 +966,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsModifiedProvider) { // Reload the model to verify that save/reload retains the item. ResetModel(true); - ASSERT_TRUE( - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")) != NULL); + ASSERT_TRUE(model()->GetTemplateURLForKeyword(L"unittest") != NULL); } // Make sure that load routine doesn't delete @@ -1018,7 +1003,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { // internal state is correct. TemplateURL copy_t_url = *t_url; - ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest"))); + ASSERT_EQ(t_url, model()->GetTemplateURLForKeyword(L"unittest")); ASSERT_EQ(t_url, model()->GetDefaultSearchProvider()); BlockTillServiceProcessesRequests(); @@ -1027,7 +1012,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); @@ -1040,7 +1025,7 @@ TEST_F(TemplateURLModelTest, LoadRetainsDefaultProvider) { ResetModel(true); { const TemplateURL* keyword_url = - model()->GetTemplateURLForKeyword(ASCIIToUTF16("unittest")); + model()->GetTemplateURLForKeyword(L"unittest"); ASSERT_TRUE(keyword_url != NULL); AssertEquals(copy_t_url, *keyword_url); ASSERT_EQ(keyword_url, model()->GetDefaultSearchProvider()); @@ -1063,7 +1048,7 @@ TEST_F(TemplateURLModelTest, LoadUpdatesSearchURL) { // This test basically verifies that no asserts or crashes occur // during this operation. TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) { - string16 prepopulated_url; + std::wstring prepopulated_url; TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL( 0, &prepopulated_url); t_url->set_safe_for_autoreplace(false); @@ -1107,8 +1092,8 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { test_util_.ResetObserverCount(); // Set a regular default search provider. - TemplateURL* regular_default = AddKeywordWithDate("key1", false, - "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", "name1", + TemplateURL* regular_default = AddKeywordWithDate(L"key1", false, + "http://foo1", "http://sugg1", "http://icon1", "UTF-8;UTF-16", L"name1", true, Time()); VerifyObserverCount(1); model()->SetDefaultSearchProvider(regular_default); @@ -1133,7 +1118,7 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { scoped_ptr<TemplateURL> expected_managed_default1(new TemplateURL()); expected_managed_default1->SetURL(kSearchURL, 0, 0); expected_managed_default1->SetFavIconURL(GURL(kIconURL)); - expected_managed_default1->set_short_name(ASCIIToUTF16("test1")); + expected_managed_default1->set_short_name(L"test1"); std::vector<std::string> encodings_vector; base::SplitString(kEncodings, ';', &encodings_vector); expected_managed_default1->set_input_encodings(encodings_vector); @@ -1157,7 +1142,7 @@ TEST_F(TemplateURLModelTest, TestManagedDefaultSearch) { scoped_ptr<TemplateURL> expected_managed_default2(new TemplateURL()); expected_managed_default2->SetURL(kNewSearchURL, 0, 0); expected_managed_default2->SetSuggestionsURL(kNewSuggestURL, 0, 0); - expected_managed_default2->set_short_name(ASCIIToUTF16("test2")); + expected_managed_default2->set_short_name(L"test2"); expected_managed_default2->set_show_in_default_list(true); actual_managed_default = model()->GetDefaultSearchProvider(); ExpectSimilar(actual_managed_default, expected_managed_default2.get()); diff --git a/chrome/browser/search_engines/template_url_parser.cc b/chrome/browser/search_engines/template_url_parser.cc index e671d63..245ca3f 100644 --- a/chrome/browser/search_engines/template_url_parser.cc +++ b/chrome/browser/search_engines/template_url_parser.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -138,7 +138,7 @@ class ParsingContext { TemplateURL* template_url() { return url_; } - void AddImageRef(const std::string& type, int width, int height) { + void AddImageRef(const std::wstring& type, int width, int height) { if (width > 0 && height > 0) current_image_.reset(new TemplateURL::ImageRef(type, width, height)); } @@ -147,9 +147,9 @@ class ParsingContext { current_image_.reset(); } - void SetImageURL(const GURL& url) { + void SetImageURL(const std::wstring& url) { if (current_image_.get()) { - current_image_->url = url; + current_image_->url = GURL(WideToUTF8(url)); url_->add_image_ref(*current_image_); current_image_.reset(); } @@ -159,11 +159,11 @@ class ParsingContext { string_.clear(); } - void AppendString(const string16& string) { + void AppendString(const std::wstring& string) { string_ += string; } - const string16& GetString() { + const std::wstring& GetString() { return string_; } @@ -233,7 +233,7 @@ class ParsingContext { scoped_ptr<TemplateURL::ImageRef> current_image_; // Character content for the current element. - string16 string_; + std::wstring string_; TemplateURLParser::ParameterFilter* parameter_filter_; @@ -259,8 +259,12 @@ class ParsingContext { std::map<std::string, ParsingContext::ElementType>* ParsingContext::kElementNameToElementTypeMap = NULL; -string16 XMLCharToUTF16(const xmlChar* value, int length) { - return UTF8ToUTF16(std::string((const char*)value, length)); +std::wstring XMLCharToWide(const xmlChar* value) { + return UTF8ToWide(std::string((const char*)value)); +} + +std::wstring XMLCharToWide(const xmlChar* value, int length) { + return UTF8ToWide(std::string((const char*)value, length)); } std::string XMLCharToString(const xmlChar* value) { @@ -340,12 +344,12 @@ void ParseImage(const xmlChar** atts, ParsingContext* context) { const xmlChar** attributes = atts; int width = 0; int height = 0; - std::string type; + std::wstring type; while (*attributes) { std::string name(XMLCharToString(*attributes)); const xmlChar* value = attributes[1]; if (name == kImageTypeAttribute) { - type = XMLCharToString(value); + type = XMLCharToWide(value); } else if (name == kImageWidthAttribute) { base::StringToInt(XMLCharToString(value), &width); } else if (name == kImageHeightAttribute) { @@ -364,6 +368,7 @@ void ParseParam(const xmlChar** atts, ParsingContext* context) { return; const xmlChar** attributes = atts; + std::wstring type; std::string key, value; while (*attributes) { std::string name(XMLCharToString(*attributes)); @@ -482,14 +487,14 @@ void EndElementImpl(void *ctx, const xmlChar *name) { context->template_url()->set_description(context->GetString()); break; case ParsingContext::IMAGE: { - GURL image_url(UTF16ToUTF8(context->GetString())); + GURL image_url(WideToUTF8(context->GetString())); if (image_url.SchemeIs(chrome::kDataScheme)) { // TODO (jcampan): bug 1169256: when dealing with data URL, we need to // decode the data URL in the renderer. For now, we'll just point to the // fav icon from the URL. context->set_derive_image_from_url(true); } else { - context->SetImageURL(image_url); + context->SetImageURL(context->GetString()); } context->EndImage(); break; @@ -498,7 +503,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { context->template_url()->add_language(context->GetString()); break; case ParsingContext::INPUT_ENCODING: { - std::string input_encoding = UTF16ToASCII(context->GetString()); + std::string input_encoding = WideToASCII(context->GetString()); if (IsValidEncodingString(input_encoding)) context->template_url()->add_input_encoding(input_encoding); break; @@ -515,7 +520,7 @@ void EndElementImpl(void *ctx, const xmlChar *name) { void CharactersImpl(void *ctx, const xmlChar *ch, int len) { ParsingContext* context = reinterpret_cast<ParsingContext*>(ctx); - context->AppendString(XMLCharToUTF16(ch, len)); + context->AppendString(XMLCharToWide(ch, len)); } // Returns true if the ref is null, or the url wrapped by ref is diff --git a/chrome/browser/search_engines/template_url_parser_unittest.cc b/chrome/browser/search_engines/template_url_parser_unittest.cc index c339092..14d6203 100644 --- a/chrome/browser/search_engines/template_url_parser_unittest.cc +++ b/chrome/browser/search_engines/template_url_parser_unittest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_parser.h" #include "chrome/common/chrome_paths.h" @@ -85,7 +84,7 @@ TEST_F(TemplateURLParserTest, TestDictionary) { return; ParseFile("dictionary.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Dictionary.com"), template_url_.short_name()); + EXPECT_EQ(L"Dictionary.com", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://cache.lexico.com/g/d/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -99,7 +98,7 @@ TEST_F(TemplateURLParserTest, TestMSDN) { return; ParseFile("msdn.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Search \" MSDN"), template_url_.short_name()); + EXPECT_EQ(L"Search \" MSDN", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://search.msdn.microsoft.com/search/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -113,7 +112,7 @@ TEST_F(TemplateURLParserTest, TestWikipedia) { return; ParseFile("wikipedia.xml", NULL); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Wikipedia (English)"), template_url_.short_name()); + EXPECT_EQ(L"Wikipedia (English)", template_url_.short_name()); EXPECT_TRUE(template_url_.GetFavIconURL() == GURL("http://en.wikipedia.org/favicon.ico")); EXPECT_TRUE(template_url_.url() != NULL); @@ -164,7 +163,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxEbay) { ParamFilterImpl filter("ebay", "ebay"); ParseFile("firefox_ebay.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("eBay"), template_url_.short_name()); + EXPECT_EQ(L"eBay", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); std::string exp_url = @@ -185,7 +184,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxWebster) { ParamFilterImpl filter("", "Mozilla"); ParseFile("firefox_webster.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Webster"), template_url_.short_name()); + EXPECT_EQ(L"Webster", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_EQ("http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", @@ -203,7 +202,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { ParamFilterImpl filter("", "Mozilla"); ParseFile("firefox_yahoo.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); + EXPECT_EQ(L"Yahoo", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_EQ("http://ff.search.yahoo.com/gossip?" @@ -226,7 +225,7 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) { ParamFilterImpl filter("", "Mozilla"); ParseFile("post_suggestion.xml", &filter); ASSERT_TRUE(parse_result_); - EXPECT_EQ(ASCIIToUTF16("Yahoo"), template_url_.short_name()); + EXPECT_EQ(L"Yahoo", template_url_.short_name()); EXPECT_TRUE(template_url_.url() != NULL); EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_TRUE(template_url_.suggestions_url() == NULL); diff --git a/chrome/browser/search_engines/template_url_prepopulate_data.cc b/chrome/browser/search_engines/template_url_prepopulate_data.cc index 6cb64bd..fbd89b4 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -3379,11 +3379,11 @@ TemplateURL* MakePrepopulatedTemplateURL(const wchar_t* name, new_turl->SetSuggestionsURL(WideToUTF8(suggest_url), 0, 0); if (instant_url) new_turl->SetInstantURL(WideToUTF8(instant_url), 0, 0); - new_turl->set_short_name(WideToUTF16Hack(name)); + new_turl->set_short_name(name); if (keyword == NULL) new_turl->set_autogenerate_keyword(true); else - new_turl->set_keyword(WideToUTF16Hack(keyword)); + new_turl->set_keyword(keyword); new_turl->set_show_in_default_list(true); new_turl->set_safe_for_autoreplace(true); new_turl->set_date_created(Time()); diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc index 1261915..f79f6b6 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc @@ -1,11 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/file_util.h" #include "base/scoped_temp_dir.h" #include "base/scoped_vector.h" -#include "base/utf_string_conversions.h" #include "chrome/browser/search_engines/search_engine_type.h" #include "chrome/browser/search_engines/search_terms_data.h" #include "chrome/browser/search_engines/template_url.h" @@ -120,8 +119,8 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { &prefs, &(t_urls.get()), &default_index); ASSERT_EQ(1u, t_urls.size()); - EXPECT_EQ(ASCIIToUTF16("foo"), t_urls[0]->short_name()); - EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); + EXPECT_EQ(L"foo", t_urls[0]->short_name()); + EXPECT_EQ(L"fook", t_urls[0]->keyword()); EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); diff --git a/chrome/browser/search_engines/template_url_table_model.cc b/chrome/browser/search_engines/template_url_table_model.cc index 18c239d..453b98d 100644 --- a/chrome/browser/search_engines/template_url_table_model.cc +++ b/chrome/browser/search_engines/template_url_table_model.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -180,7 +180,7 @@ string16 TemplateURLTableModel::GetText(int row, int col_id) { switch (col_id) { case IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN: { - string16 url_short_name = url.short_name(); + string16 url_short_name = WideToUTF16Hack(url.short_name()); // TODO(xji): Consider adding a special case if the short name is a URL, // since those should always be displayed LTR. Please refer to // http://crbug.com/6726 for more information. @@ -195,7 +195,7 @@ string16 TemplateURLTableModel::GetText(int row, int col_id) { case IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN: { // Keyword should be domain name. Force it to have LTR directionality. - string16 keyword = url.keyword(); + string16 keyword = WideToUTF16(url.keyword()); keyword = base::i18n::GetDisplayStringInLTRDirectionality(keyword); return keyword; } @@ -279,7 +279,8 @@ void TemplateURLTableModel::ModifyTemplateURL(int index, DCHECK(index >= 0 && index <= RowCount()); const TemplateURL* template_url = &GetTemplateURL(index); template_url_model_->RemoveObserver(this); - template_url_model_->ResetTemplateURL(template_url, title, keyword, url); + template_url_model_->ResetTemplateURL(template_url, UTF16ToWideHack(title), + UTF16ToWideHack(keyword), url); if (template_url_model_->GetDefaultSearchProvider() == template_url && !TemplateURL::SupportsReplacement(template_url)) { // The entry was the default search provider, but the url has been modified diff --git a/chrome/browser/search_engines/template_url_unittest.cc b/chrome/browser/search_engines/template_url_unittest.cc index 819164c..3faa2aa 100644 --- a/chrome/browser/search_engines/template_url_unittest.cc +++ b/chrome/browser/search_engines/template_url_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,8 +28,8 @@ class TestSearchTermsData : public SearchTermsData { #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) // Returns the value for the Chrome Omnibox rlz. - virtual string16 GetRlzParameterValue() const { - return string16(); + virtual std::wstring GetRlzParameterValue() const { + return L""; } #endif @@ -68,16 +68,15 @@ TEST_F(TemplateURLTest, TestValidWithComplete) { TEST_F(TemplateURLTest, URLRefTestSearchTerms) { struct SearchTermsCase { const char* url; - const string16 terms; + const wchar_t* terms; const char* output; } search_term_cases[] = { - { "http://foo{searchTerms}", ASCIIToUTF16("sea rch/bar"), - "http://foosea%20rch/bar" }, - { "http://foo{searchTerms}?boo=abc", ASCIIToUTF16("sea rch/bar"), + { "http://foo{searchTerms}", L"sea rch/bar", "http://foosea%20rch/bar" }, + { "http://foo{searchTerms}?boo=abc", L"sea rch/bar", "http://foosea%20rch/bar?boo=abc" }, - { "http://foo/?boo={searchTerms}", ASCIIToUTF16("sea rch/bar"), + { "http://foo/?boo={searchTerms}", L"sea rch/bar", "http://foo/?boo=sea+rch%2Fbar" }, - { "http://en.wikipedia.org/{searchTerms}", ASCIIToUTF16("wiki/?"), + { "http://en.wikipedia.org/{searchTerms}", L"wiki/?", "http://en.wikipedia.org/wiki/%3F" } }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(search_term_cases); ++i) { @@ -88,7 +87,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTerms) { ASSERT_TRUE(ref.SupportsReplacement()); GURL result = GURL(ref.ReplaceSearchTerms(t_url, value.terms, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ(value.output, result.spec()); } @@ -99,8 +98,8 @@ TEST_F(TemplateURLTest, URLRefTestCount) { TemplateURLRef ref("http://foo{searchTerms}{count?}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox/", result.spec()); } @@ -110,8 +109,8 @@ TEST_F(TemplateURLTest, URLRefTestCount2) { TemplateURLRef ref("http://foo{searchTerms}{count}", 0, 0); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://foox10/", result.spec()); } @@ -122,8 +121,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices) { 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxy/", result.spec()); } @@ -133,8 +132,8 @@ TEST_F(TemplateURLTest, URLRefTestIndices2) { TemplateURLRef ref("http://foo{searchTerms}x{startIndex}y{startPage}", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxx1y2/", result.spec()); } @@ -145,8 +144,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding) { "http://foo{searchTerms}x{inputEncoding?}y{outputEncoding?}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxutf-8ya/", result.spec()); } @@ -157,8 +156,8 @@ TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) { "http://foox{inputEncoding?}a{searchTerms}y{outputEncoding?}b", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxutf-8axyb/", result.spec()); } @@ -169,8 +168,8 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", 1, 2); ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); - GURL result = GURL(ref.ReplaceSearchTerms(t_url, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(t_url, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); ASSERT_EQ("http://fooxxutf-8yutf-8a/", result.spec()); } @@ -178,12 +177,12 @@ TEST_F(TemplateURLTest, URLRefTestEncoding2) { TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { struct SearchTermsCase { const char* url; - const string16 terms; + const wchar_t* terms; const char* output; } search_term_cases[] = { - { "{google:baseURL}{language}{searchTerms}", string16(), + { "{google:baseURL}{language}{searchTerms}", L"", "http://example.com/e/yy" }, - { "{google:baseSuggestURL}{searchTerms}", string16(), + { "{google:baseSuggestURL}{searchTerms}", L"", "http://clients1.example.com/complete/" } }; @@ -197,7 +196,7 @@ TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { ASSERT_TRUE(ref.SupportsReplacement()); GURL result = GURL(ref.ReplaceSearchTermsUsingTermsData( t_url, value.terms, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), search_terms_data)); ASSERT_TRUE(result.is_valid()); ASSERT_EQ(value.output, result.spec()); @@ -207,21 +206,21 @@ TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) { TEST_F(TemplateURLTest, URLRefTermToWide) { struct ToWideCase { const char* encoded_search_term; - const string16 expected_decoded_term; + const wchar_t* expected_decoded_term; } to_wide_cases[] = { - {"hello+world", ASCIIToUTF16("hello world")}, + {"hello+world", L"hello world"}, // Test some big-5 input. - {"%a7A%A6%6e+to+you", WideToUTF16(L"\x4f60\x597d to you")}, + {"%a7A%A6%6e+to+you", L"\x4f60\x597d to you"}, // Test some UTF-8 input. We should fall back to this when the encoding // doesn't look like big-5. We have a '5' in the middle, which is an invalid // Big-5 trailing byte. - {"%e4%bd%a05%e5%a5%bd+to+you", WideToUTF16(L"\x4f60\x35\x597d to you")}, + {"%e4%bd%a05%e5%a5%bd+to+you", L"\x4f60\x35\x597d to you"}, // Undecodable input should stay escaped. - {"%91%01+abcd", WideToUTF16(L"%91%01 abcd")}, + {"%91%01+abcd", L"%91%01 abcd"}, // Make sure we convert %2B to +. - {"C%2B%2B", ASCIIToUTF16("C++")}, + {"C%2B%2B", L"C++"}, // C%2B is escaped as C%252B, make sure we unescape it properly. - {"C%252B", ASCIIToUTF16("C%2B")}, + {"C%252B", L"C%2B"}, }; TemplateURL t_url; @@ -236,10 +235,10 @@ TEST_F(TemplateURLTest, URLRefTermToWide) { ASSERT_TRUE(ref.SupportsReplacement()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(to_wide_cases); i++) { - string16 result = ref.SearchTermToString16(t_url, + std::wstring result = ref.SearchTermToWide(t_url, to_wide_cases[i].encoded_search_term); - EXPECT_EQ(to_wide_cases[i].expected_decoded_term, result); + EXPECT_EQ(std::wstring(to_wide_cases[i].expected_decoded_term), result); } } @@ -259,16 +258,16 @@ TEST_F(TemplateURLTest, SetFavIcon) { TEST_F(TemplateURLTest, DisplayURLToURLRef) { struct TestData { const std::string url; - const string16 expected_result; + const std::wstring expected_result; } data[] = { { "http://foo{searchTerms}x{inputEncoding}y{outputEncoding}a", - ASCIIToUTF16("http://foo%sx{inputEncoding}y{outputEncoding}a") }, + L"http://foo%sx{inputEncoding}y{outputEncoding}a" }, { "http://X", - ASCIIToUTF16("http://X") }, + L"http://X" }, { "http://foo{searchTerms", - ASCIIToUTF16("http://foo{searchTerms") }, + L"http://foo{searchTerms" }, { "http://foo{searchTerms}{language}", - ASCIIToUTF16("http://foo%s{language}") }, + L"http://foo%s{language}" }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { TemplateURLRef ref(data[i].url, 1, 2); @@ -317,8 +316,8 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) { std::string expected_result = data[i].expected_result; ReplaceSubstringsAfterOffset(&expected_result, 0, "{language}", g_browser_process->GetApplicationLocale()); - GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("X"), - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + GURL result = GURL(ref.ReplaceSearchTerms(turl, L"X", + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(expected_result, result.spec()); } @@ -330,15 +329,13 @@ TEST_F(TemplateURLTest, ReplaceSearchTerms) { TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { struct TestData { const std::string encoding; - const string16 search_term; + const std::wstring search_term; const std::string url; const std::string expected_result; } data[] = { - { "BIG5", WideToUTF16(L"\x60BD"), - "http://foo/?{searchTerms}{inputEncoding}", + { "BIG5", L"\x60BD", "http://foo/?{searchTerms}{inputEncoding}", "http://foo/?%B1~BIG5" }, - { "UTF-8", ASCIIToUTF16("blah"), - "http://foo/?{searchTerms}{inputEncoding}", + { "UTF-8", L"blah", "http://foo/?{searchTerms}{inputEncoding}", "http://foo/?blahUTF-8" }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { @@ -347,7 +344,7 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { TemplateURLRef ref(data[i].url, 1, 2); GURL result = GURL(ref.ReplaceSearchTerms(turl, data[i].search_term, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, - string16())); + std::wstring())); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(data[i].expected_result, result.spec()); } @@ -356,19 +353,19 @@ TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) { TEST_F(TemplateURLTest, Suggestions) { struct TestData { const int accepted_suggestion; - const string16 original_query_for_suggestion; + const std::wstring original_query_for_suggestion; const std::string expected_result; } data[] = { - { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16(), + { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring(), "http://bar/foo?q=foobar" }, - { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, ASCIIToUTF16("foo"), + { TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, L"foo", "http://bar/foo?q=foobar" }, - { TemplateURLRef::NO_SUGGESTION_CHOSEN, string16(), + { TemplateURLRef::NO_SUGGESTION_CHOSEN, std::wstring(), "http://bar/foo?aq=f&q=foobar" }, - { TemplateURLRef::NO_SUGGESTION_CHOSEN, ASCIIToUTF16("foo"), + { TemplateURLRef::NO_SUGGESTION_CHOSEN, L"foo", "http://bar/foo?aq=f&q=foobar" }, - { 0, string16(), "http://bar/foo?aq=0&oq=&q=foobar" }, - { 1, ASCIIToUTF16("foo"), "http://bar/foo?aq=1&oq=foo&q=foobar" }, + { 0, std::wstring(), "http://bar/foo?aq=0&oq=&q=foobar" }, + { 1, L"foo", "http://bar/foo?aq=1&oq=foo&q=foobar" }, }; TemplateURL turl; turl.add_input_encoding("UTF-8"); @@ -377,7 +374,7 @@ TEST_F(TemplateURLTest, Suggestions) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { - GURL result = GURL(ref.ReplaceSearchTerms(turl, ASCIIToUTF16("foobar"), + GURL result = GURL(ref.ReplaceSearchTerms(turl, L"foobar", data[i].accepted_suggestion, data[i].original_query_for_suggestion)); EXPECT_TRUE(result.is_valid()); EXPECT_EQ(data[i].expected_result, result.spec()); @@ -386,7 +383,7 @@ TEST_F(TemplateURLTest, Suggestions) { #if defined(OS_WIN) TEST_F(TemplateURLTest, RLZ) { - string16 rlz_string; + std::wstring rlz_string; #if defined(GOOGLE_CHROME_BUILD) RLZTracker::GetAccessPointRlz(rlz_lib::CHROME_OMNIBOX, &rlz_string); #endif @@ -396,7 +393,7 @@ TEST_F(TemplateURLTest, RLZ) { ASSERT_TRUE(ref.IsValid()); ASSERT_TRUE(ref.SupportsReplacement()); GURL result(ref.ReplaceSearchTerms(t_url, L"x", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())); + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); ASSERT_TRUE(result.is_valid()); std::string expected_url = "http://bar/?"; if (!rlz_string.empty()) { @@ -464,14 +461,14 @@ TEST_F(TemplateURLTest, Keyword) { TemplateURL t_url; t_url.SetURL("http://www.google.com/search", 0, 0); EXPECT_FALSE(t_url.autogenerate_keyword()); - t_url.set_keyword(ASCIIToUTF16("foo")); - EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); + t_url.set_keyword(L"foo"); + EXPECT_EQ(L"foo", t_url.keyword()); t_url.set_autogenerate_keyword(true); EXPECT_TRUE(t_url.autogenerate_keyword()); - EXPECT_EQ(ASCIIToUTF16("google.com"), t_url.keyword()); - t_url.set_keyword(ASCIIToUTF16("foo")); + EXPECT_EQ(L"google.com", t_url.keyword()); + t_url.set_keyword(L"foo"); EXPECT_FALSE(t_url.autogenerate_keyword()); - EXPECT_EQ(ASCIIToUTF16("foo"), t_url.keyword()); + EXPECT_EQ(L"foo", t_url.keyword()); } TEST_F(TemplateURLTest, ParseParameterKnown) { diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc index 203042d..94b46d6 100644 --- a/chrome/browser/search_engines/util.cc +++ b/chrome/browser/search_engines/util.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,7 @@ #include <vector> #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" @@ -28,7 +29,7 @@ string16 GetDefaultSearchEngineName(Profile* profile) { // http://code.google.com/p/chromium/issues/detail?id=2573 return string16(); } - return default_provider->short_name(); + return WideToUTF16(default_provider->short_name()); } // Removes (and deletes) TemplateURLs from |urls| that have duplicate |