summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-10 23:52:43 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-10 23:52:43 +0000
commite7a5b787751ed3c1c31f66ae919f11911393b974 (patch)
tree7627eb287c3e079a240f6cc8f98cf94c36a568b4 /chrome/browser/autocomplete
parent01b9961c2ee639c10b07624d40a73702a9f3d0ec (diff)
downloadchromium_src-e7a5b787751ed3c1c31f66ae919f11911393b974.zip
chromium_src-e7a5b787751ed3c1c31f66ae919f11911393b974.tar.gz
chromium_src-e7a5b787751ed3c1c31f66ae919f11911393b974.tar.bz2
Make the autocomplete system and various other connected bits of code use GURL instead of wstring where appropriate. Original patch by phajdan.jr@gmail.com, r=me,sky. See http://codereview.chromium.org/13205 .
BUG=715234 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6758 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete.cc14
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc33
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h20
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_unittest.cc12
-rw-r--r--chrome/browser/autocomplete/history_contents_provider.cc2
-rw-r--r--chrome/browser/autocomplete/history_contents_provider_unittest.cc26
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc15
-rw-r--r--chrome/browser/autocomplete/history_url_provider.h2
-rw-r--r--chrome/browser/autocomplete/history_url_provider_unittest.cc119
-rw-r--r--chrome/browser/autocomplete/keyword_provider.cc6
-rw-r--r--chrome/browser/autocomplete/keyword_provider_unittest.cc54
-rw-r--r--chrome/browser/autocomplete/search_provider.cc8
-rw-r--r--chrome/browser/autocomplete/search_provider.h4
14 files changed, 164 insertions, 165 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc
index 5d2fb87..f0e16e3 100644
--- a/chrome/browser/autocomplete/autocomplete.cc
+++ b/chrome/browser/autocomplete/autocomplete.cc
@@ -20,6 +20,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "googleurl/src/gurl.h"
#include "googleurl/src/url_canon_ip.h"
#include "net/base/net_util.h"
#include "net/base/registry_controlled_domain.h"
@@ -442,7 +443,7 @@ void AutocompleteProvider::UpdateStarredStateOfMatches() {
size_t AutocompleteResult::max_matches_ = 6;
void AutocompleteResult::Selection::Clear() {
- destination_url.clear();
+ destination_url = GURL();
provider_affinity = NULL;
is_history_what_you_typed_match = false;
}
@@ -516,7 +517,7 @@ void AutocompleteResult::SortAndCull() {
default_match_ = begin();
}
-std::wstring AutocompleteResult::GetAlternateNavURL(
+GURL AutocompleteResult::GetAlternateNavURL(
const AutocompleteInput& input,
const_iterator match) const {
if (((input.type() == AutocompleteInput::UNKNOWN) ||
@@ -525,11 +526,11 @@ std::wstring AutocompleteResult::GetAlternateNavURL(
for (const_iterator i(begin()); i != end(); ++i) {
if (i->is_history_what_you_typed_match) {
return (i->destination_url == match->destination_url) ?
- std::wstring() : i->destination_url;
+ GURL() : i->destination_url;
}
}
}
- return std::wstring();
+ return GURL();
}
#ifndef NDEBUG
@@ -727,7 +728,7 @@ ACMatches AutocompleteController::GetMatchesNotInLatestResult(
DCHECK(provider);
// Determine the set of destination URLs.
- std::set<std::wstring> destination_urls;
+ std::set<GURL> destination_urls;
for (AutocompleteResult::const_iterator i(latest_result_.begin());
i != latest_result_.end(); ++i)
destination_urls.insert(i->destination_url);
@@ -814,8 +815,7 @@ void AutocompleteController::AddHistoryContentsShortcut() {
ACMatchClassification::NONE));
}
match.destination_url =
- UTF8ToWide(HistoryTabUI::GetHistoryURLWithSearchText(
- input_.text()).spec());
+ HistoryTabUI::GetHistoryURLWithSearchText(input_.text());
match.transition = PageTransition::AUTO_BOOKMARK;
match.provider = history_contents_provider_;
latest_result_.AddMatch(match);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 357fbd9..03267af 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -137,9 +137,8 @@ void AutocompleteEditModel::SetUserText(const std::wstring& text) {
void AutocompleteEditModel::GetDataForURLExport(GURL* url,
std::wstring* title,
SkBitmap* favicon) {
- const std::wstring url_str(GetURLForCurrentText(NULL, NULL, NULL));
- *url = GURL(url_str);
- if (url_str == permanent_text_) {
+ *url = GetURLForCurrentText(NULL, NULL, NULL);
+ if (UTF8ToWide(url->possibly_invalid_spec()) == permanent_text_) {
*title = controller_->GetTitle();
*favicon = controller_->GetFavIcon();
}
@@ -205,9 +204,9 @@ void AutocompleteEditModel::StartAutocomplete(
bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
// Reset local state.
- paste_and_go_url_.clear();
+ paste_and_go_url_ = GURL();
paste_and_go_transition_ = PageTransition::TYPED;
- paste_and_go_alternate_nav_url_.clear();
+ paste_and_go_alternate_nav_url_ = GURL();
// Ask the controller what do do with this input.
paste_and_go_controller->SetProfile(profile_);
@@ -229,7 +228,7 @@ bool AutocompleteEditModel::CanPasteAndGo(const std::wstring& text) const {
paste_and_go_alternate_nav_url_ =
result.GetAlternateNavURL(paste_and_go_controller->input(), match);
- return !paste_and_go_url_.empty();
+ return paste_and_go_url_.is_valid();
}
void AutocompleteEditModel::PasteAndGo() {
@@ -247,14 +246,14 @@ void AutocompleteEditModel::AcceptInput(WindowOpenDisposition disposition,
// Get the URL and transition type for the selected entry.
PageTransition::Type transition;
bool is_history_what_you_typed_match;
- std::wstring alternate_nav_url;
- const std::wstring url(GetURLForCurrentText(&transition,
- &is_history_what_you_typed_match,
- &alternate_nav_url));
- if (url.empty())
+ GURL alternate_nav_url;
+ const GURL url(GetURLForCurrentText(&transition,
+ &is_history_what_you_typed_match,
+ &alternate_nav_url));
+ if (!url.is_valid())
return;
- if (url == permanent_text_) {
+ if (UTF8ToWide(url.spec()) == permanent_text_) {
// When the user hit enter on the existing permanent URL, treat it like a
// reload for scoring purposes. We could detect this by just checking
// user_input_in_progress_, but it seems better to treat "edits" that end
@@ -565,10 +564,10 @@ std::wstring AutocompleteEditModel::UserTextFromDisplayText(
text : (keyword_ + L" " + text);
}
-std::wstring AutocompleteEditModel::GetURLForCurrentText(
+GURL AutocompleteEditModel::GetURLForCurrentText(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url) {
+ GURL* alternate_nav_url) {
return (popup_->is_open() || !popup_->autocomplete_controller()->done()) ?
popup_->URLsForCurrentSelection(transition,
is_history_what_you_typed_match,
@@ -868,13 +867,13 @@ void AutocompleteEditView::Update(const TabContents* tab_for_state_restoring) {
}
}
-void AutocompleteEditView::OpenURL(const std::wstring& url,
+void AutocompleteEditView::OpenURL(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url,
+ const GURL& alternate_nav_url,
size_t selected_line,
const std::wstring& keyword) {
- if (url.empty())
+ if (!url.is_valid())
return;
model_->SendOpenNotification(selected_line, keyword);
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index fc6398d..dc7d0a5 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -46,10 +46,10 @@ class AutocompleteEditController {
// |alternate_nav_url|, if non-empty, contains the alternate navigation URL
// for |url|, which the controller can check for existence. See comments on
// AutocompleteResult::GetAlternateNavURL().
- virtual void OnAutocompleteAccept(const std::wstring& url,
+ virtual void OnAutocompleteAccept(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url) = 0;
+ const GURL& alternate_nav_url) = 0;
// Called when anything has changed that might affect the layout or contents
// of the views around the edit, including the text of the edit and the
@@ -325,9 +325,9 @@ class AutocompleteEditModel {
//
// See AutocompleteEdit for a description of the args (they may be null if
// not needed).
- std::wstring GetURLForCurrentText(PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url);
+ GURL GetURLForCurrentText(PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
AutocompleteEditView* view_;
@@ -394,7 +394,7 @@ class AutocompleteEditModel {
// arrows to a different item with the same text, we can still distinguish
// them and not revert all the way to the permanent_text_.
bool has_temporary_text_;
- std::wstring original_url_;
+ GURL original_url_;
KeywordUIState original_keyword_ui_state_;
// When the user's last action was to paste and replace all the text, we
@@ -427,9 +427,9 @@ class AutocompleteEditModel {
bool show_search_hint_;
// Paste And Go-related state. See CanPasteAndGo().
- mutable std::wstring paste_and_go_url_;
+ mutable GURL paste_and_go_url_;
mutable PageTransition::Type paste_and_go_transition_;
- mutable std::wstring paste_and_go_alternate_nav_url_;
+ mutable GURL paste_and_go_alternate_nav_url_;
Profile* profile_;
@@ -494,10 +494,10 @@ class AutocompleteEditView
// If the URL was expanded from a keyword, |keyword| is that keyword.
//
// This may close the popup.
- void OpenURL(const std::wstring& url,
+ void OpenURL(const GURL& url,
WindowOpenDisposition disposition,
PageTransition::Type transition,
- const std::wstring& alternate_nav_url,
+ const GURL& alternate_nav_url,
size_t selected_line,
const std::wstring& keyword);
diff --git a/chrome/browser/autocomplete/autocomplete_popup.h b/chrome/browser/autocomplete/autocomplete_popup.h
index 593f169..6f7808a 100644
--- a/chrome/browser/autocomplete/autocomplete_popup.h
+++ b/chrome/browser/autocomplete/autocomplete_popup.h
@@ -274,10 +274,10 @@ class AutocompletePopupModel : public NotificationObserver {
// If |alternate_nav_url| is non-NULL, it will be set to the alternate
// navigation URL for |url| if one exists, or left unchanged otherwise. See
// comments on AutocompleteResult::GetAlternateNavURL().
- std::wstring URLsForCurrentSelection(
+ GURL URLsForCurrentSelection(
PageTransition::Type* transition,
bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url) const;
+ GURL* alternate_nav_url) const;
// This is sort of a hybrid between StartAutocomplete() and
// URLForCurrentSelection(). When the popup isn't open and the user hits
@@ -292,11 +292,11 @@ class AutocompletePopupModel : public NotificationObserver {
//
// If there are no matches for |text|, leaves the outparams unset and returns
// the empty string.
- std::wstring URLsForDefaultMatch(const std::wstring& text,
- const std::wstring& desired_tld,
- PageTransition::Type* transition,
- bool* is_history_what_you_typed_match,
- std::wstring* alternate_nav_url);
+ GURL URLsForDefaultMatch(const std::wstring& text,
+ const std::wstring& desired_tld,
+ PageTransition::Type* transition,
+ bool* is_history_what_you_typed_match,
+ GURL* alternate_nav_url);
// Gets the selected keyword or keyword hint for the given match. Returns
// true if |keyword| represents a keyword hint, or false if |keyword|
diff --git a/chrome/browser/autocomplete/autocomplete_unittest.cc b/chrome/browser/autocomplete/autocomplete_unittest.cc
index a945a5b..9127659 100644
--- a/chrome/browser/autocomplete/autocomplete_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_unittest.cc
@@ -4,6 +4,7 @@
#include "base/message_loop.h"
#include "base/ref_counted.h"
+#include "base/string_util.h"
#include "chrome/browser/autocomplete/autocomplete.h"
#include "chrome/common/notification_registrar.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -75,12 +76,12 @@ void TestProvider::AddResults(int start_at, int num) {
wchar_t str[16];
swprintf_s(str, L"%d", i);
match.fill_into_edit = prefix_ + str;
- match.destination_url = match.fill_into_edit;
+ match.destination_url = GURL(WideToUTF8(match.fill_into_edit));
- match.contents = match.destination_url;
+ match.contents = match.fill_into_edit;
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
- match.description = match.destination_url;
+ match.description = match.fill_into_edit;
match.description_class.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
@@ -131,12 +132,13 @@ void AutocompleteProviderTest::ResetController(bool same_destinations) {
providers_.clear();
// Construct two new providers, with either the same or different prefixes.
- TestProvider* providerA = new TestProvider(num_results_per_provider, L"a");
+ TestProvider* providerA = new TestProvider(num_results_per_provider,
+ L"http://a");
providerA->AddRef();
providers_.push_back(providerA);
TestProvider* providerB = new TestProvider(num_results_per_provider * 2,
- same_destinations ? L"a" : L"b");
+ same_destinations ? L"http://a" : L"http://b");
providerB->AddRef();
providers_.push_back(providerB);
diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc
index cc1598f..a2397af 100644
--- a/chrome/browser/autocomplete/history_contents_provider.cc
+++ b/chrome/browser/autocomplete/history_contents_provider.cc
@@ -196,7 +196,7 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch(
AutocompleteMatch match(this, score, false, MatchInTitle(result) ?
AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY);
match.fill_into_edit = StringForURLDisplay(result.url(), true);
- match.destination_url = UTF8ToWide(result.url().spec());
+ match.destination_url = result.url();
match.contents = match.fill_into_edit;
match.contents_class.push_back(
ACMatchClassification(0, ACMatchClassification::URL));
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
index 0ab3d76..4c3009e 100644
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc
@@ -26,12 +26,6 @@ struct TestEntry {
{"http://www.google.com/3", L"PAGETHREE 3", L"BAR some hello world for you"},
};
-// For comparing TestEntry.url with wide strings generated by the autocomplete
-// code
-bool UrlIs(const char* url, const std::wstring& str) {
- return WideToUTF8(str) == std::string(url);
-}
-
class HistoryContentsProviderTest : public testing::Test,
public ACProviderListener {
public:
@@ -109,9 +103,9 @@ TEST_F(HistoryContentsProviderTest, Body) {
// The results should be the first two pages, in decreasing order.
const ACMatches& m = matches();
ASSERT_EQ(2, m.size());
- EXPECT_TRUE(UrlIs(test_entries[1].url, m[0].destination_url));
+ EXPECT_EQ(test_entries[1].url, m[0].destination_url.spec());
EXPECT_STREQ(test_entries[1].title, m[0].description.c_str());
- EXPECT_TRUE(UrlIs(test_entries[0].url, m[1].destination_url));
+ EXPECT_EQ(test_entries[0].url, m[1].destination_url.spec());
EXPECT_STREQ(test_entries[0].title, m[1].description.c_str());
}
@@ -122,9 +116,9 @@ TEST_F(HistoryContentsProviderTest, Title) {
// The results should be the first two pages.
const ACMatches& m = matches();
ASSERT_EQ(2, m.size());
- EXPECT_TRUE(UrlIs(test_entries[1].url, m[0].destination_url));
+ EXPECT_EQ(test_entries[1].url, m[0].destination_url.spec());
EXPECT_STREQ(test_entries[1].title, m[0].description.c_str());
- EXPECT_TRUE(UrlIs(test_entries[0].url, m[1].destination_url));
+ EXPECT_EQ(test_entries[0].url, m[1].destination_url.spec());
EXPECT_STREQ(test_entries[0].title, m[1].description.c_str());
}
@@ -164,7 +158,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
RunQuery(sync_input, false);
const ACMatches& m1 = matches();
ASSERT_EQ(1, m1.size());
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m1[0].destination_url));
+ EXPECT_EQ(bookmark_url, m1[0].destination_url);
EXPECT_EQ(L"bar", m1[0].description);
EXPECT_TRUE(m1[0].starred);
@@ -173,7 +167,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
provider()->Start(async_input, false);
const ACMatches& m2 = matches();
ASSERT_EQ(1, m2.size());
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m2[0].destination_url));
+ EXPECT_EQ(bookmark_url, m2[0].destination_url);
// Run the message loop (needed for async history results).
MessageLoop::current()->Run();
@@ -181,10 +175,10 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) {
// We should two urls now, bookmark_url and http://www.google.com/3.
const ACMatches& m3 = matches();
ASSERT_EQ(2, m3.size());
- if (bookmark_url.spec() == WideToUTF8(m3[0].destination_url)) {
- EXPECT_EQ(L"http://www.google.com/3", m3[1].destination_url);
+ if (bookmark_url == m3[0].destination_url) {
+ EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec());
} else {
- EXPECT_EQ(bookmark_url.spec(), WideToUTF8(m3[1].destination_url));
- EXPECT_EQ(L"http://www.google.com/3", m3[0].destination_url);
+ EXPECT_EQ(bookmark_url, m3[1].destination_url);
+ EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec());
}
}
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 175fca4..0737036 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -149,8 +149,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
max_matches() * 2, &url_matches);
for (URLRowVector::const_iterator j(url_matches.begin());
j != url_matches.end(); ++j) {
- const Prefix* best_prefix = BestPrefix(UTF8ToWide(j->url().spec()),
- std::wstring());
+ const Prefix* best_prefix = BestPrefix(j->url(), std::wstring());
DCHECK(best_prefix != NULL);
history_matches.push_back(HistoryMatch(*j, i->prefix.length(),
!i->num_components,
@@ -232,7 +231,7 @@ void HistoryURLProvider::SuggestExactInput(const AutocompleteInput& input,
(canonicalized_url.IsStandard() &&
!canonicalized_url.SchemeIsFile() && canonicalized_url.host().empty()))
return;
- match.destination_url = UTF8ToWide(canonicalized_url.spec());
+ match.destination_url = canonicalized_url;
match.fill_into_edit = StringForURLDisplay(canonicalized_url, false);
// NOTE: Don't set match.input_location (to allow inline autocompletion)
// here, it's surprising and annoying.
@@ -283,7 +282,7 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db,
// * and the input _without_ the TLD _is_ in the history DB,
// * ...then just before pressing "ctrl" the best match we supplied was the
// what-you-typed match, so stick with it by promoting this.
- if (!db->GetRowForURL(GURL(match.destination_url), &info)) {
+ if (!db->GetRowForURL(match.destination_url, &info)) {
if (params->input.desired_tld().empty())
return false;
// This code should match what SuggestExactInput() would do with no
@@ -517,9 +516,8 @@ void HistoryURLProvider::PromoteOrCreateShorterSuggestion(
search_base = GURL(new_match);
} else if (!can_add_search_base_to_matches) {
- // TODO(brettw) this extra GURL conversion should be unnecessary.
can_add_search_base_to_matches =
- (search_base != GURL(params.matches.front().destination_url));
+ (search_base != params.matches.front().destination_url);
}
if (search_base == match.url_info.url())
return; // Couldn't shorten |match|, so no range of URLs to search over.
@@ -662,9 +660,10 @@ void HistoryURLProvider::RunAutocompletePasses(const AutocompleteInput& input,
}
const HistoryURLProvider::Prefix* HistoryURLProvider::BestPrefix(
- const std::wstring& text,
+ const GURL& url,
const std::wstring& prefix_suffix) const {
const Prefix* best_prefix = NULL;
+ const std::wstring text(UTF8ToWide(url.spec()));
for (Prefixes::const_iterator i(prefixes_.begin()); i != prefixes_.end();
++i) {
if ((best_prefix == NULL) ||
@@ -798,7 +797,7 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch(
AutocompleteMatch match(this,
CalculateRelevance(params->input.type(), match_type, match_number),
!!info.visit_count(), AutocompleteMatch::HISTORY_URL);
- match.destination_url = UTF8ToWide(info.url().possibly_invalid_spec());
+ match.destination_url = info.url();
match.fill_into_edit = gfx::ElideUrl(info.url(), ChromeFont(), 0,
match_type == WHAT_YOU_TYPED ? std::wstring() : params->languages);
if (!params->input.prevent_inline_autocomplete()) {
diff --git a/chrome/browser/autocomplete/history_url_provider.h b/chrome/browser/autocomplete/history_url_provider.h
index e8d1838..dfb462d 100644
--- a/chrome/browser/autocomplete/history_url_provider.h
+++ b/chrome/browser/autocomplete/history_url_provider.h
@@ -321,7 +321,7 @@ class HistoryURLProvider : public AutocompleteProvider {
// |prefix_suffix| (which may be empty) is appended to every attempted
// prefix. This is useful when you need to figure out the innermost match
// for some user input in a URL.
- const Prefix* BestPrefix(const std::wstring& text,
+ const Prefix* BestPrefix(const GURL& text,
const std::wstring& prefix_suffix) const;
// Adds the exact input for what the user has typed as input. This is
diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc
index 610191f..70602ee 100644
--- a/chrome/browser/autocomplete/history_url_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc
@@ -5,6 +5,7 @@
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/string_util.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/history/history.h"
@@ -98,7 +99,7 @@ class HistoryURLProviderTest : public testing::Test,
void RunTest(const std::wstring text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
- const std::wstring* expected_urls,
+ const std::string* expected_urls,
int num_results);
MessageLoopForUI message_loop_;
@@ -156,7 +157,7 @@ void HistoryURLProviderTest::FillData() {
void HistoryURLProviderTest::RunTest(const std::wstring text,
const std::wstring& desired_tld,
bool prevent_inline_autocomplete,
- const std::wstring* expected_urls,
+ const std::string* expected_urls,
int num_results) {
AutocompleteInput input(text, desired_tld, prevent_inline_autocomplete,
false, false);
@@ -167,41 +168,41 @@ void HistoryURLProviderTest::RunTest(const std::wstring text,
matches_ = autocomplete_->matches();
ASSERT_EQ(num_results, matches_.size());
for (int i = 0; i < num_results; ++i)
- EXPECT_EQ(expected_urls[i], matches_[i].destination_url);
+ EXPECT_EQ(expected_urls[i], matches_[i].destination_url.spec());
}
TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// Test that hosts get synthesized below popular pages.
- const std::wstring expected_nonsynth[] = {
- L"http://slash/",
- L"http://slashdot.org/favorite_page.html",
- L"http://slashdot.org/",
+ const std::string expected_nonsynth[] = {
+ "http://slash/",
+ "http://slashdot.org/favorite_page.html",
+ "http://slashdot.org/",
};
RunTest(L"slash", std::wstring(), true, expected_nonsynth,
arraysize(expected_nonsynth));
// Test that hosts get synthesized above less popular pages.
- const std::wstring expected_synth[] = {
- L"http://kernel/",
- L"http://kerneltrap.org/",
- L"http://kerneltrap.org/not_very_popular.html",
+ const std::string expected_synth[] = {
+ "http://kernel/",
+ "http://kerneltrap.org/",
+ "http://kerneltrap.org/not_very_popular.html",
};
RunTest(L"kernel", std::wstring(), true, expected_synth,
arraysize(expected_synth));
// Test that unpopular pages are ignored completely.
- const std::wstring expected_what_you_typed_only[] = {
- L"http://fresh/",
+ const std::string expected_what_you_typed_only[] = {
+ "http://fresh/",
};
RunTest(L"fresh", std::wstring(), true, expected_what_you_typed_only,
arraysize(expected_what_you_typed_only));
// Test that if we have a synthesized host that matches a suggestion, they
// get combined into one.
- const std::wstring expected_combine[] = {
- L"http://news/",
- L"http://news.google.com/",
- L"http://news.google.com/?ned=us&topic=n",
+ const std::string expected_combine[] = {
+ "http://news/",
+ "http://news.google.com/",
+ "http://news.google.com/?ned=us&topic=n",
};
RunTest(L"news", std::wstring(), true, expected_combine,
arraysize(expected_combine));
@@ -212,21 +213,21 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// Test that short URL matching works correctly as the user types more
// (several tests):
// The entry for foo.com is the best of all five foo.com* entries.
- const std::wstring short_1[] = {
- L"http://foo/",
- L"http://foo.com/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
+ const std::string short_1[] = {
+ "http://foo/",
+ "http://foo.com/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
};
RunTest(L"foo", std::wstring(), true, short_1, arraysize(short_1));
// When the user types the whole host, make sure we don't get two results for
// it.
- const std::wstring short_2[] = {
- L"http://foo.com/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
- L"http://foo.com/dir/another/",
+ const std::string short_2[] = {
+ "http://foo.com/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
+ "http://foo.com/dir/another/",
};
RunTest(L"foo.com", std::wstring(), true, short_2, arraysize(short_2));
RunTest(L"foo.com/", std::wstring(), true, short_2, arraysize(short_2));
@@ -234,20 +235,20 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// The filename is the second best of the foo.com* entries, but there is a
// shorter URL that's "good enough". The host doesn't match the user input
// and so should not appear.
- const std::wstring short_3[] = {
- L"http://foo.com/d",
- L"http://foo.com/dir/another/",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/",
+ const std::string short_3[] = {
+ "http://foo.com/d",
+ "http://foo.com/dir/another/",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/",
};
RunTest(L"foo.com/d", std::wstring(), true, short_3, arraysize(short_3));
// We shouldn't promote shorter URLs than the best if they're not good
// enough.
- const std::wstring short_4[] = {
- L"http://foo.com/dir/another/a",
- L"http://foo.com/dir/another/again/myfile.html",
- L"http://foo.com/dir/another/again/",
+ const std::string short_4[] = {
+ "http://foo.com/dir/another/a",
+ "http://foo.com/dir/another/again/myfile.html",
+ "http://foo.com/dir/another/again/",
};
RunTest(L"foo.com/dir/another/a", std::wstring(), true, short_4,
arraysize(short_4));
@@ -257,18 +258,18 @@ TEST_F(HistoryURLProviderTest, PromoteShorterURLs) {
// working. See TODO in URLDatabase::AutocompleteForPrefix.
TEST_F(HistoryURLProviderTest, DISABLED_Starred) {
// Test that starred pages sort properly.
- const std::wstring star_1[] = {
- L"http://startest/",
- L"http://startest.com/x/d",
- L"http://startest.com/x/c",
- L"http://startest.com/y/a",
+ const std::string star_1[] = {
+ "http://startest/",
+ "http://startest.com/x/d",
+ "http://startest.com/x/c",
+ "http://startest.com/y/a",
};
RunTest(L"startest", std::wstring(), true, star_1, arraysize(star_1));
- const std::wstring star_2[] = {
- L"http://startest.com/y",
- L"http://startest.com/y/a",
- L"http://startest.com/y/b",
- L"http://startest.com/y/e",
+ const std::string star_2[] = {
+ "http://startest.com/y",
+ "http://startest.com/y/a",
+ "http://startest.com/y/b",
+ "http://startest.com/y/e",
};
RunTest(L"startest.com/y", std::wstring(), true, star_2, arraysize(star_2));
}
@@ -279,13 +280,13 @@ TEST_F(HistoryURLProviderTest, CullRedirects) {
// the results to be in A,B,C order. Note also that our visit counts are
// all high enough so that domain synthesizing won't get triggered.
struct RedirectCase {
- const wchar_t* url;
+ const char* url;
int count;
};
static const RedirectCase redirect[] = {
- {L"http://redirects/A", 30},
- {L"http://redirects/B", 20},
- {L"http://redirects/C", 10}
+ {"http://redirects/A", 30},
+ {"http://redirects/B", 20},
+ {"http://redirects/C", 10}
};
for (int i = 0; i < arraysize(redirect); i++) {
history_service_->AddPageWithDetails(GURL(redirect[i].url), L"Title",
@@ -308,8 +309,8 @@ TEST_F(HistoryURLProviderTest, CullRedirects) {
// all but the first one (A) should be culled. We should get the default
// "what you typed" result, plus this one.
const std::wstring typing(L"http://redirects/");
- const std::wstring expected_results[] = {
- typing,
+ const std::string expected_results[] = {
+ WideToUTF8(typing),
redirect[0].url};
RunTest(typing, std::wstring(), true, expected_results,
arraysize(expected_results));
@@ -321,29 +322,29 @@ TEST_F(HistoryURLProviderTest, Fixup) {
RunTest(L"#", std::wstring(), false, NULL, 0);
- const std::wstring crash_1[] = {L"http://%20/"};
+ const std::string crash_1[] = {"http://%20/"};
RunTest(L"%20", std::wstring(), false, crash_1, arraysize(crash_1));
// Fixing up "file:" should result in an inline autocomplete offset of just
// after "file:", not just after "file://".
const std::wstring input_1(L"file:");
- const std::wstring fixup_1[] = {L"file:///", L"file:///C:/foo.txt"};
+ const std::string fixup_1[] = {"file:///", "file:///C:/foo.txt"};
RunTest(input_1, std::wstring(), false, fixup_1, arraysize(fixup_1));
EXPECT_EQ(input_1.length(), matches_[1].inline_autocomplete_offset);
// Fixing up "http:/" should result in an inline autocomplete offset of just
// after "http:/", not just after "http:".
const std::wstring input_2(L"http:/");
- const std::wstring fixup_2[] = {
- L"http://bogussite.com/a",
- L"http://bogussite.com/b",
- L"http://bogussite.com/c",
+ const std::string fixup_2[] = {
+ "http://bogussite.com/a",
+ "http://bogussite.com/b",
+ "http://bogussite.com/c",
};
RunTest(input_2, std::wstring(), false, fixup_2, arraysize(fixup_2));
EXPECT_EQ(input_2.length(), matches_[0].inline_autocomplete_offset);
// Adding a TLD to a small number like "56" should result in "www.56.com"
// rather than "0.0.0.56.com".
- std::wstring fixup_3[] = {L"http://www.56.com/"};
+ std::string fixup_3[] = {"http://www.56.com/"};
RunTest(L"56", L"com", true, fixup_3, arraysize(fixup_3));
}
diff --git a/chrome/browser/autocomplete/keyword_provider.cc b/chrome/browser/autocomplete/keyword_provider.cc
index badc300..9f0eb3e 100644
--- a/chrome/browser/autocomplete/keyword_provider.cc
+++ b/chrome/browser/autocomplete/keyword_provider.cc
@@ -168,7 +168,7 @@ void KeywordProvider::FillInURLAndContents(
ACMatchClassification(0, ACMatchClassification::DIM));
} else {
// Keyword that has no replacement text (aka a shorthand for a URL).
- match->destination_url.assign(element->url()->url());
+ match->destination_url = GURL(WideToUTF8(element->url()->url()));
match->contents.assign(element->short_name());
AutocompleteMatch::ClassifyLocationInString(0, match->contents.length(),
match->contents.length(), ACMatchClassification::NONE,
@@ -180,9 +180,9 @@ void KeywordProvider::FillInURLAndContents(
// input, but we rely on later canonicalization functions to do more
// fixup to make the URL valid if necessary.
DCHECK(element->url()->SupportsReplacement());
- match->destination_url.assign(element->url()->ReplaceSearchTerms(
+ match->destination_url = element->url()->ReplaceSearchTerms(
*element, remaining_input, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
- std::wstring()));
+ std::wstring());
std::vector<size_t> content_param_offsets;
match->contents.assign(l10n_util::GetStringF(IDS_KEYWORD_SEARCH,
element->short_name(),
diff --git a/chrome/browser/autocomplete/keyword_provider_unittest.cc b/chrome/browser/autocomplete/keyword_provider_unittest.cc
index c51e1fa..e82e8d6 100644
--- a/chrome/browser/autocomplete/keyword_provider_unittest.cc
+++ b/chrome/browser/autocomplete/keyword_provider_unittest.cc
@@ -11,10 +11,11 @@
class KeywordProviderTest : public testing::Test {
protected:
+ template<class ResultType>
struct test_data {
const std::wstring input;
const size_t num_results;
- const std::wstring output[3];
+ const ResultType output[3];
};
KeywordProviderTest() : kw_provider_(NULL) { }
@@ -23,9 +24,10 @@ class KeywordProviderTest : public testing::Test {
virtual void SetUp();
virtual void TearDown();
- void RunTest(test_data* keyword_cases,
+ template<class ResultType>
+ void RunTest(test_data<ResultType>* keyword_cases,
int num_cases,
- std::wstring AutocompleteMatch::* member);
+ ResultType AutocompleteMatch::* member);
protected:
scoped_refptr<KeywordProvider> kw_provider_;
@@ -52,10 +54,11 @@ void KeywordProviderTest::TearDown() {
kw_provider_ = NULL;
}
+template<class ResultType>
void KeywordProviderTest::RunTest(
- test_data* keyword_cases,
+ test_data<ResultType>* keyword_cases,
int num_cases,
- std::wstring AutocompleteMatch::* member) {
+ ResultType AutocompleteMatch::* member) {
ACMatches matches;
for (int i = 0; i < num_cases; ++i) {
AutocompleteInput input(keyword_cases[i].input, std::wstring(), true,
@@ -74,7 +77,7 @@ void KeywordProviderTest::RunTest(
}
TEST_F(KeywordProviderTest, Edit) {
- test_data edit_cases[] = {
+ test_data<std::wstring> edit_cases[] = {
// Searching for a nonexistent prefix should give nothing.
{L"Not Found", 0, {}},
{L"aaaaaNot Found", 0, {}},
@@ -105,34 +108,35 @@ TEST_F(KeywordProviderTest, Edit) {
{L"mailto:z", 1, {L"z "}},
};
- RunTest(edit_cases, arraysize(edit_cases),
- &AutocompleteMatch::fill_into_edit);
+ RunTest<std::wstring>(edit_cases, arraysize(edit_cases),
+ &AutocompleteMatch::fill_into_edit);
}
TEST_F(KeywordProviderTest, URL) {
- test_data url_cases[] = {
+ test_data<GURL> url_cases[] = {
// No query input -> empty destination URL.
- {L"z", 1, {L""}},
- {L"z \t", 1, {L""}},
+ {L"z", 1, {GURL("")}},
+ {L"z \t", 1, {GURL("")}},
// Check that tokenization only collapses whitespace between first tokens
// and query input, but not rest of URL, is escaped.
- {L"z a b c++", 1, {L"a+++b+++c%2B%2B=z"}},
- {L"www.www www", 1, {L" +%2B?=wwwfoo "}},
+ {L"z a b c++", 1, {GURL("a+++b+++c%2B%2B=z")}},
+ {L"www.www www", 1, {GURL(" +%2B?=wwwfoo ")}},
// Substitution should work with various locations of the "%s".
- {L"aaa 1a2b", 2, {L"http://aaaa/?aaaa=1&b=1a2b&c", L"1a2b"}},
- {L"a 1 2 3", 3, {L"aa.com?foo=1+2+3", L"bogus URL 1+2+3",
- L"http://aaaa/?aaaa=1&b=1+2+3&c"}},
- {L"www.w w", 2, {L" +%2B?=wfoo ", L"weaselwweasel"}},
+ {L"aaa 1a2b", 2, {GURL("http://aaaa/?aaaa=1&b=1a2b&c"),
+ GURL("1a2b")}},
+ {L"a 1 2 3", 3, {GURL("aa.com?foo=1+2+3"), GURL("bogus URL 1+2+3"),
+ GURL("http://aaaa/?aaaa=1&b=1+2+3&c")}},
+ {L"www.w w", 2, {GURL(" +%2B?=wfoo "), GURL("weaselwweasel")}},
};
- RunTest(url_cases, arraysize(url_cases),
- &AutocompleteMatch::destination_url);
+ RunTest<GURL>(url_cases, arraysize(url_cases),
+ &AutocompleteMatch::destination_url);
}
TEST_F(KeywordProviderTest, Contents) {
- test_data contents_cases[] = {
+ test_data<std::wstring> contents_cases[] = {
// No query input -> substitute "<enter query>" into contents.
{L"z", 1, {L"Search z for <enter query>"}},
{L"z \t", 1, {L"Search z for <enter query>"}},
@@ -150,12 +154,12 @@ TEST_F(KeywordProviderTest, Contents) {
{L"www.w w", 2, {L"Search www for w", L"Search weasel for w"}},
};
- RunTest(contents_cases, arraysize(contents_cases),
- &AutocompleteMatch::contents);
+ RunTest<std::wstring>(contents_cases, arraysize(contents_cases),
+ &AutocompleteMatch::contents);
}
TEST_F(KeywordProviderTest, Description) {
- test_data description_cases[] = {
+ test_data<std::wstring> description_cases[] = {
// Whole keyword should be returned for both exact and inexact matches.
{L"z foo", 1, {L"(Keyword: z)"}},
{L"a foo", 3, {L"(Keyword: aa)", L"(Keyword: ab)",
@@ -168,8 +172,8 @@ TEST_F(KeywordProviderTest, Description) {
{L"z a b c++", 1, {L"(Keyword: z)"}},
};
- RunTest(description_cases, arraysize(description_cases),
- &AutocompleteMatch::description);
+ RunTest<std::wstring>(description_cases, arraysize(description_cases),
+ &AutocompleteMatch::description);
}
TEST_F(KeywordProviderTest, AddKeyword) {
diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc
index 0bad51c..32c2fb2 100644
--- a/chrome/browser/autocomplete/search_provider.cc
+++ b/chrome/browser/autocomplete/search_provider.cc
@@ -88,9 +88,9 @@ void SearchProvider::Run() {
const TemplateURLRef* const suggestions_url =
default_provider_.suggestions_url();
DCHECK(suggestions_url->SupportsReplacement());
- fetcher_.reset(new URLFetcher(GURL(suggestions_url->ReplaceSearchTerms(
+ fetcher_.reset(new URLFetcher(suggestions_url->ReplaceSearchTerms(
default_provider_, input_.text(),
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())),
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()),
URLFetcher::GET, this));
fetcher_->set_request_context(profile_->GetRequestContext());
fetcher_->Start();
@@ -320,7 +320,7 @@ bool SearchProvider::ParseSuggestResults(Value* root_val) {
description_list && description_list->Get(i, &site_val) &&
site_val->IsType(Value::TYPE_STRING) &&
site_val->GetAsString(&site_name)) {
- navigation_results_.push_back(NavigationResult(suggestion_str,
+ navigation_results_.push_back(NavigationResult(GURL(suggestion_str),
site_name));
}
} else {
@@ -566,7 +566,7 @@ AutocompleteMatch SearchProvider::NavigationToMatch(
AutocompleteMatch match(this, relevance, false,
AutocompleteMatch::NAVSUGGEST);
match.destination_url = navigation.url;
- match.contents = StringForURLDisplay(GURL(navigation.url), true);
+ match.contents = StringForURLDisplay(navigation.url, true);
// TODO(kochi): Consider moving HistoryURLProvider::TrimHttpPrefix() to some
// public utility function.
if (!url_util::FindAndCompareScheme(input_.text(), "http", NULL))
diff --git a/chrome/browser/autocomplete/search_provider.h b/chrome/browser/autocomplete/search_provider.h
index 2ff00ad..8fe402f 100644
--- a/chrome/browser/autocomplete/search_provider.h
+++ b/chrome/browser/autocomplete/search_provider.h
@@ -61,13 +61,13 @@ class SearchProvider : public AutocompleteProvider,
private:
struct NavigationResult {
- NavigationResult(const std::wstring& url, const std::wstring& site_name)
+ NavigationResult(const GURL& url, const std::wstring& site_name)
: url(url),
site_name(site_name) {
}
// The URL.
- std::wstring url;
+ GURL url;
// Name for the site.
std::wstring site_name;