diff options
Diffstat (limited to 'chrome/browser/autocomplete')
8 files changed, 117 insertions, 105 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index cdaa56f..1846e2d 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -1010,7 +1010,7 @@ void AutocompleteController::AddHistoryContentsShortcut() { ACMatchClassification::NONE)); } match.destination_url = - HistoryUI::GetHistoryURLWithSearchText(input_.text()); + HistoryUI::GetHistoryURLWithSearchText(WideToUTF16(input_.text())); match.transition = PageTransition::AUTO_BOOKMARK; match.provider = history_contents_provider_; latest_result_.AddMatch(match); diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc index 951a9b0..35dbff5 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_view_browsertest.cc @@ -41,18 +41,18 @@ using base::TimeDelta; namespace { -const wchar_t kSearchKeyword[] = L"foo"; +const char kSearchKeyword[] = "foo"; const wchar_t kSearchKeywordKeys[] = { base::VKEY_F, base::VKEY_O, base::VKEY_O, 0 }; -const wchar_t kSearchURL[] = L"http://www.foo.com/search?q={searchTerms}"; -const wchar_t kSearchShortName[] = L"foo"; -const wchar_t kSearchText[] = L"abc"; +const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}"; +const char kSearchShortName[] = "foo"; +const char kSearchText[] = "abc"; const wchar_t kSearchTextKeys[] = { base::VKEY_A, base::VKEY_B, base::VKEY_C, 0 }; const char kSearchTextURL[] = "http://www.foo.com/search?q=abc"; -const wchar_t kSearchSingleChar[] = L"z"; +const char kSearchSingleChar[] = "z"; const wchar_t kSearchSingleCharKeys[] = { base::VKEY_Z, 0 }; const char kSearchSingleCharURL[] = "http://www.foo.com/search?q=z"; @@ -77,24 +77,24 @@ const char *kBlockedHostnames[] = { const struct TestHistoryEntry { const char* url; - const wchar_t* title; - const wchar_t* body; + const char* title; + const char* body; int visit_count; int typed_count; bool starred; } kHistoryEntries[] = { - {"http://www.bar.com/1", L"Page 1", kSearchText, 1, 1, false }, - {"http://www.bar.com/2", L"Page 2", kSearchText, 1, 1, false }, - {"http://www.bar.com/3", L"Page 3", kSearchText, 1, 1, false }, - {"http://www.bar.com/4", L"Page 4", kSearchText, 1, 1, false }, - {"http://www.bar.com/5", L"Page 5", kSearchText, 1, 1, false }, - {"http://www.bar.com/6", L"Page 6", kSearchText, 1, 1, false }, - {"http://www.bar.com/7", L"Page 7", kSearchText, 1, 1, false }, - {"http://www.bar.com/8", L"Page 8", kSearchText, 1, 1, false }, - {"http://www.bar.com/9", L"Page 9", kSearchText, 1, 1, false }, + {"http://www.bar.com/1", "Page 1", kSearchText, 1, 1, false }, + {"http://www.bar.com/2", "Page 2", kSearchText, 1, 1, false }, + {"http://www.bar.com/3", "Page 3", kSearchText, 1, 1, false }, + {"http://www.bar.com/4", "Page 4", kSearchText, 1, 1, false }, + {"http://www.bar.com/5", "Page 5", kSearchText, 1, 1, false }, + {"http://www.bar.com/6", "Page 6", kSearchText, 1, 1, false }, + {"http://www.bar.com/7", "Page 7", kSearchText, 1, 1, false }, + {"http://www.bar.com/8", "Page 8", kSearchText, 1, 1, false }, + {"http://www.bar.com/9", "Page 9", kSearchText, 1, 1, false }, // To trigger inline autocomplete. - {"http://www.abc.com", L"Page abc", kSearchText, 10000, 10000, true }, + {"http://www.abc.com", "Page abc", kSearchText, 10000, 10000, true }, }; } // namespace @@ -192,9 +192,9 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, ASSERT_TRUE(model->loaded()); TemplateURL* template_url = new TemplateURL(); - template_url->SetURL(kSearchURL, 0, 0); - template_url->set_keyword(kSearchKeyword); - template_url->set_short_name(kSearchShortName); + template_url->SetURL(UTF8ToWide(kSearchURL), 0, 0); + template_url->set_keyword(UTF8ToWide(kSearchKeyword)); + template_url->set_short_name(UTF8ToWide(kSearchShortName)); model->Add(template_url); model->SetDefaultSearchProvider(template_url); @@ -231,9 +231,10 @@ class AutocompleteEditViewTest : public InProcessBrowserTest, // Add everything in order of time. We don't want to have a time that // is "right now" or it will nondeterministically appear in the results. Time t = Time::Now() - TimeDelta::FromHours(i + 1); - history_service->AddPageWithDetails(url, cur.title, cur.visit_count, + history_service->AddPageWithDetails(url, UTF8ToUTF16(cur.title), + cur.visit_count, cur.typed_count, t, false); - history_service->SetPageContents(url, WideToUTF16(cur.body)); + history_service->SetPageContents(url, UTF8ToUTF16(cur.body)); if (cur.starred) { bookmark_model->SetURLStarred(url, std::wstring(), true); } @@ -330,22 +331,22 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { // Trigger keyword hint mode. ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(kSearchKeyword), edit_view->model()->keyword()); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Trigger keyword mode. ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_TAB, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(kSearchKeyword), edit_view->model()->keyword()); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Backspace without search text should bring back keyword hint mode. ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); ASSERT_TRUE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(kSearchKeyword), edit_view->model()->keyword()); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Trigger keyword mode again. ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_TAB, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(kSearchKeyword), edit_view->model()->keyword()); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); // Input something as search text. ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); @@ -355,7 +356,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { for (size_t i = 0; i < arraysize(kSearchText) - 1; ++i) { ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(kSearchKeyword), edit_view->model()->keyword()); + ASSERT_EQ(kSearchKeyword, WideToUTF8(edit_view->model()->keyword())); } // Input something as search text. @@ -367,9 +368,9 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, BackspaceInKeywordMode) { // the keyword mode. ASSERT_NO_FATAL_FAILURE(SendKey(base::VKEY_BACK, false, false, false)); ASSERT_FALSE(edit_view->model()->is_keyword_hint()); - ASSERT_EQ(std::wstring(), edit_view->model()->keyword()); - ASSERT_EQ(std::wstring(kSearchKeyword) + std::wstring(kSearchText), - edit_view->GetText()); + ASSERT_EQ(std::string(), WideToUTF8(edit_view->model()->keyword())); + ASSERT_EQ(std::string(kSearchKeyword) + kSearchText, + WideToUTF8(edit_view->GetText())); } IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, Escape) { @@ -459,7 +460,7 @@ IN_PROC_BROWSER_TEST_F(AutocompleteEditViewTest, EnterToSearch) { ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys)); ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); ASSERT_TRUE(popup_model->IsOpen()); - EXPECT_EQ(std::wstring(kSearchSingleChar), edit_view->GetText()); + EXPECT_EQ(kSearchSingleChar, WideToUTF8(edit_view->GetText())); // Check if the default match result is Search Primary Provider. ASSERT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, diff --git a/chrome/browser/autocomplete/history_contents_provider.cc b/chrome/browser/autocomplete/history_contents_provider.cc index c05fbdc..947f0be 100644 --- a/chrome/browser/autocomplete/history_contents_provider.cc +++ b/chrome/browser/autocomplete/history_contents_provider.cc @@ -120,7 +120,8 @@ void HistoryContentsProvider::Start(const AutocompleteInput& input, history::QueryOptions options; options.SetRecentDayRange(kDaysToSearch); options.max_count = kMaxMatchCount; - history->QueryHistory(input.text(), options, &request_consumer_, + history->QueryHistory(WideToUTF16(input.text()), options, + &request_consumer_, NewCallback(this, &HistoryContentsProvider::QueryComplete)); } } @@ -213,7 +214,7 @@ AutocompleteMatch HistoryContentsProvider::ResultToMatch( match.destination_url = result.url(); match.contents_class.push_back( ACMatchClassification(0, ACMatchClassification::URL)); - match.description = result.title(); + match.description = UTF16ToWide(result.title()); match.starred = (profile_->GetBookmarkModel() && profile_->GetBookmarkModel()->IsBookmarked(result.url())); @@ -277,6 +278,6 @@ void HistoryContentsProvider::QueryBookmarks(const AutocompleteInput& input) { void HistoryContentsProvider::AddBookmarkTitleMatchToResults( const bookmark_utils::TitleMatch& match) { history::URLResult url_result(match.node->GetURL(), match.match_positions); - url_result.set_title(match.node->GetTitle()); + url_result.set_title(WideToUTF16(match.node->GetTitle())); results_.AppendURLBySwapping(&url_result); } diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc index ff8fa09..2fd6e23 100644 --- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc @@ -19,12 +19,12 @@ namespace { struct TestEntry { const char* url; - const wchar_t* title; + const char* title; const char* body; } test_entries[] = { - {"http://www.google.com/1", L"PAGEONE 1", "FOO some body text"}, - {"http://www.google.com/2", L"PAGEONE 2", "FOO some more blah blah"}, - {"http://www.google.com/3", L"PAGETHREE 3", "BAR some hello world for you"}, + {"http://www.google.com/1", "PAGEONE 1", "FOO some body text"}, + {"http://www.google.com/2", "PAGEONE 2", "FOO some more blah blah"}, + {"http://www.google.com/3", "PAGETHREE 3", "BAR some hello world for you"}, }; class HistoryContentsProviderTest : public testing::Test, @@ -72,7 +72,7 @@ class HistoryContentsProviderTest : public testing::Test, history_service->AddPage(url, t, id_scope, i, GURL(), PageTransition::LINK, history::RedirectList(), false); - history_service->SetPageTitle(url, test_entries[i].title); + history_service->SetPageTitle(url, UTF8ToUTF16(test_entries[i].title)); history_service->SetPageContents(url, UTF8ToUTF16(test_entries[i].body)); } @@ -108,9 +108,9 @@ TEST_F(HistoryContentsProviderTest, Body) { const ACMatches& m = matches(); ASSERT_EQ(2U, m.size()); EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); - EXPECT_STREQ(test_entries[0].title, m[0].description.c_str()); + EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); - EXPECT_STREQ(test_entries[1].title, m[1].description.c_str()); + EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); } TEST_F(HistoryContentsProviderTest, Title) { @@ -121,9 +121,9 @@ TEST_F(HistoryContentsProviderTest, Title) { const ACMatches& m = matches(); ASSERT_EQ(2U, m.size()); EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); - EXPECT_STREQ(test_entries[0].title, m[0].description.c_str()); + EXPECT_STREQ(test_entries[0].title, WideToUTF8(m[0].description).c_str()); EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); - EXPECT_STREQ(test_entries[1].title, m[1].description.c_str()); + EXPECT_STREQ(test_entries[1].title, WideToUTF8(m[1].description).c_str()); } // The "minimal changes" flag should mean that we don't re-query the DB. diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc index 1952a65..a4cbd28 100644 --- a/chrome/browser/autocomplete/history_url_provider.cc +++ b/chrome/browser/autocomplete/history_url_provider.cc @@ -10,6 +10,7 @@ #include "base/histogram.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_backend.h" #include "chrome/browser/history/history_database.h" @@ -158,7 +159,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend, // for more results than we need, of every prefix type, in hopes this will // give us far more than enough to work with. CullRedirects() will then // reduce the list to the best kMaxMatches results. - db->AutocompleteForPrefix(i->prefix + params->input.text(), + db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()), kMaxMatches * 2, &url_matches); for (URLRowVector::const_iterator j(url_matches.begin()); j != url_matches.end(); ++j) { @@ -327,8 +328,9 @@ bool HistoryURLProvider::FixupExactSuggestion(history::URLDatabase* db, } else { // We have data for this match, use it. match->deletable = true; - match->description = info.title(); - AutocompleteMatch::ClassifyMatchInString(input.text(), info.title(), + match->description = UTF16ToWide(info.title()); + AutocompleteMatch::ClassifyMatchInString(input.text(), + UTF16ToWide(info.title()), ACMatchClassification::NONE, &match->description_class); } @@ -882,8 +884,9 @@ AutocompleteMatch HistoryURLProvider::HistoryMatchToACMatch( match.contents.length(), ACMatchClassification::URL, &match.contents_class); } - match.description = info.title(); - AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), + match.description = UTF16ToWide(info.title()); + AutocompleteMatch::ClassifyMatchInString(params->input.text(), + UTF16ToWide(info.title()), ACMatchClassification::NONE, &match.description_class); diff --git a/chrome/browser/autocomplete/history_url_provider_unittest.cc b/chrome/browser/autocomplete/history_url_provider_unittest.cc index 9e2f159..845d2e7 100644 --- a/chrome/browser/autocomplete/history_url_provider_unittest.cc +++ b/chrome/browser/autocomplete/history_url_provider_unittest.cc @@ -20,73 +20,73 @@ using base::TimeDelta; struct TestURLInfo { std::string url; - std::wstring title; + std::string title; int visit_count; int typed_count; }; // Contents of the test database. static TestURLInfo test_db[] = { - {"http://www.google.com/", L"Google", 3, 3}, + {"http://www.google.com/", "Google", 3, 3}, // High-quality pages should get a host synthesized as a lower-quality match. - {"http://slashdot.org/favorite_page.html", L"Favorite page", 200, 100}, + {"http://slashdot.org/favorite_page.html", "Favorite page", 200, 100}, // Less popular pages should have hosts synthesized as higher-quality // matches. - {"http://kerneltrap.org/not_very_popular.html", L"Less popular", 4, 0}, + {"http://kerneltrap.org/not_very_popular.html", "Less popular", 4, 0}, // Unpopular pages should not appear in the results at all. - {"http://freshmeat.net/unpopular.html", L"Unpopular", 1, 1}, + {"http://freshmeat.net/unpopular.html", "Unpopular", 1, 1}, // If a host has a match, we should pick it up during host synthesis. - {"http://news.google.com/?ned=us&topic=n", L"Google News - U.S.", 2, 2}, - {"http://news.google.com/", L"Google News", 1, 1}, + {"http://news.google.com/?ned=us&topic=n", "Google News - U.S.", 2, 2}, + {"http://news.google.com/", "Google News", 1, 1}, // Suggested short URLs must be "good enough" and must match user input. - {"http://foo.com/", L"Dir", 5, 5}, - {"http://foo.com/dir/", L"Dir", 2, 2}, - {"http://foo.com/dir/another/", L"Dir", 5, 1}, - {"http://foo.com/dir/another/again/", L"Dir", 10, 0}, - {"http://foo.com/dir/another/again/myfile.html", L"File", 10, 2}, + {"http://foo.com/", "Dir", 5, 5}, + {"http://foo.com/dir/", "Dir", 2, 2}, + {"http://foo.com/dir/another/", "Dir", 5, 1}, + {"http://foo.com/dir/another/again/", "Dir", 10, 0}, + {"http://foo.com/dir/another/again/myfile.html", "File", 10, 2}, // We throw in a lot of extra URLs here to make sure we're testing the // history database's query, not just the autocomplete provider. - {"http://startest.com/y/a", L"A", 2, 2}, - {"http://startest.com/y/b", L"B", 5, 2}, - {"http://startest.com/x/c", L"C", 5, 2}, - {"http://startest.com/x/d", L"D", 5, 5}, - {"http://startest.com/y/e", L"E", 4, 2}, - {"http://startest.com/y/f", L"F", 3, 2}, - {"http://startest.com/y/g", L"G", 3, 2}, - {"http://startest.com/y/h", L"H", 3, 2}, - {"http://startest.com/y/i", L"I", 3, 2}, - {"http://startest.com/y/j", L"J", 3, 2}, - {"http://startest.com/y/k", L"K", 3, 2}, - {"http://startest.com/y/l", L"L", 3, 2}, - {"http://startest.com/y/m", L"M", 3, 2}, + {"http://startest.com/y/a", "A", 2, 2}, + {"http://startest.com/y/b", "B", 5, 2}, + {"http://startest.com/x/c", "C", 5, 2}, + {"http://startest.com/x/d", "D", 5, 5}, + {"http://startest.com/y/e", "E", 4, 2}, + {"http://startest.com/y/f", "F", 3, 2}, + {"http://startest.com/y/g", "G", 3, 2}, + {"http://startest.com/y/h", "H", 3, 2}, + {"http://startest.com/y/i", "I", 3, 2}, + {"http://startest.com/y/j", "J", 3, 2}, + {"http://startest.com/y/k", "K", 3, 2}, + {"http://startest.com/y/l", "L", 3, 2}, + {"http://startest.com/y/m", "M", 3, 2}, // A file: URL is useful for testing that fixup does the right thing w.r.t. // the number of trailing slashes on the user's input. - {"file:///C:/foo.txt", L"", 2, 2}, + {"file:///C:/foo.txt", "", 2, 2}, // Results with absurdly high typed_counts so that very generic queries like // "http" will give consistent results even if more data is added above. - {"http://bogussite.com/a", L"Bogus A", 10002, 10000}, - {"http://bogussite.com/b", L"Bogus B", 10001, 10000}, - {"http://bogussite.com/c", L"Bogus C", 10000, 10000}, + {"http://bogussite.com/a", "Bogus A", 10002, 10000}, + {"http://bogussite.com/b", "Bogus B", 10001, 10000}, + {"http://bogussite.com/c", "Bogus C", 10000, 10000}, // Domain name with number. - {"http://www.17173.com/", L"Domain with number", 3, 3}, + {"http://www.17173.com/", "Domain with number", 3, 3}, // URLs to test exact-matching behavior. - {"http://go/", L"Intranet URL", 1, 1}, - {"http://gooey/", L"Intranet URL 2", 5, 5}, + {"http://go/", "Intranet URL", 1, 1}, + {"http://gooey/", "Intranet URL 2", 5, 5}, // URLs for testing offset adjustment. - {"http://www.\xEA\xB5\x90\xEC\x9C\xA1.kr/", L"Korean", 2, 2}, - {"http://spaces.com/path%20with%20spaces/foo.html", L"Spaces", 2, 2}, - {"http://ms/c++%20style%20guide", L"Style guide", 2, 2}, + {"http://www.\xEA\xB5\x90\xEC\x9C\xA1.kr/", "Korean", 2, 2}, + {"http://spaces.com/path%20with%20spaces/foo.html", "Spaces", 2, 2}, + {"http://ms/c++%20style%20guide", "Style guide", 2, 2}, }; class HistoryURLProviderTest : public testing::Test, @@ -172,7 +172,7 @@ void HistoryURLProviderTest::FillData() { for (size_t i = 0; i < arraysize(test_db); ++i) { const TestURLInfo& cur = test_db[i]; const GURL current_url(cur.url); - history_service_->AddPageWithDetails(current_url, cur.title, + history_service_->AddPageWithDetails(current_url, UTF8ToUTF16(cur.title), cur.visit_count, cur.typed_count, visit_time, false); } @@ -311,7 +311,8 @@ TEST_F(HistoryURLProviderTest, CullRedirects) { {"http://redirects/C", 10} }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(redirect); i++) { - history_service_->AddPageWithDetails(GURL(redirect[i].url), L"Title", + history_service_->AddPageWithDetails(GURL(redirect[i].url), + UTF8ToUTF16("Title"), redirect[i].count, redirect[i].count, Time::Now(), false); } diff --git a/chrome/browser/autocomplete/search_provider.cc b/chrome/browser/autocomplete/search_provider.cc index 3da49df..87d0a68 100644 --- a/chrome/browser/autocomplete/search_provider.cc +++ b/chrome/browser/autocomplete/search_provider.cc @@ -328,7 +328,7 @@ void SearchProvider::ScheduleHistoryQuery(TemplateURL::IDType search_id, profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); HistoryService::Handle request_handle = history_service->GetMostRecentKeywordSearchTerms( - search_id, text, static_cast<int>(kMaxMatches), + search_id, WideToUTF16(text), static_cast<int>(kMaxMatches), &history_request_consumer_, NewCallback(this, &SearchProvider::OnGotMostRecentKeywordSearchTerms)); @@ -537,7 +537,8 @@ void SearchProvider::AddHistoryResultsToMap(const HistoryResults& results, MatchMap* map) { for (HistoryResults::const_iterator i(results.begin()); i != results.end(); ++i) { - AddMatchToMap(i->term, CalculateRelevanceForHistory(i->time, is_keyword), + AddMatchToMap(UTF16ToWide(i->term), + CalculateRelevanceForHistory(i->time, is_keyword), AutocompleteMatch::SEARCH_HISTORY, did_not_accept_suggestion, is_keyword, map); } diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 26c5843..1e489f2 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -4,6 +4,7 @@ #include "base/string_util.h" #include "base/time.h" +#include "base/utf_string_conversions.h" #include "build/build_config.h" #include "chrome/browser/autocomplete/search_provider.h" #include "chrome/browser/chrome_thread.h" @@ -29,9 +30,9 @@ class SearchProviderTest : public testing::Test, public: SearchProviderTest() : default_t_url_(NULL), - term1_(L"term1"), + term1_(UTF8ToUTF16("term1")), keyword_t_url_(NULL), - keyword_term_(L"keyword"), + keyword_term_(UTF8ToUTF16("keyword")), io_thread_(ChromeThread::IO), quit_when_done_(false) { io_thread_.Start(); @@ -56,14 +57,14 @@ class SearchProviderTest : public testing::Test, void RunTillProviderDone(); // Invokes Start on provider_, then runs all pending tasks. - void QueryForInput(const std::wstring& text); + void QueryForInput(const string16& text); // See description above class for details of these fields. TemplateURL* default_t_url_; - const std::wstring term1_; + const string16 term1_; GURL term1_url_; TemplateURL* keyword_t_url_; - const std::wstring keyword_term_; + const string16 keyword_term_; GURL keyword_url_; MessageLoopForUI message_loop_; @@ -106,8 +107,8 @@ void SearchProviderTest::SetUp() { HistoryService* history = profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); term1_url_ = GURL(WideToUTF8(default_t_url_->url()->ReplaceSearchTerms( - *default_t_url_, term1_, 0, std::wstring()))); - history->AddPageWithDetails(term1_url_, std::wstring(), 1, 1, + *default_t_url_, UTF16ToWide(term1_), 0, std::wstring()))); + history->AddPageWithDetails(term1_url_, string16(), 1, 1, base::Time::Now(), false); history->SetKeywordSearchTermsForURL(term1_url_, default_t_url_->id(), term1_); @@ -123,8 +124,8 @@ void SearchProviderTest::SetUp() { // Add a page and search term for keyword_t_url_. keyword_url_ = GURL(WideToUTF8(keyword_t_url_->url()->ReplaceSearchTerms( - *keyword_t_url_, keyword_term_, 0, std::wstring()))); - history->AddPageWithDetails(keyword_url_, std::wstring(), 1, 1, + *keyword_t_url_, UTF16ToWide(keyword_term_), 0, std::wstring()))); + history->AddPageWithDetails(keyword_url_, string16(), 1, 1, base::Time::Now(), false); history->SetKeywordSearchTermsForURL(keyword_url_, keyword_t_url_->id(), keyword_term_); @@ -154,9 +155,10 @@ void SearchProviderTest::RunTillProviderDone() { #endif } -void SearchProviderTest::QueryForInput(const std::wstring& text) { +void SearchProviderTest::QueryForInput(const string16& text) { // Start a query. - AutocompleteInput input(text, std::wstring(), false, false, false); + AutocompleteInput input(UTF16ToWide(text), std::wstring(), + false, false, false); provider_->Start(input, false); // RunAllPending so that the task scheduled by SearchProvider to create the @@ -188,7 +190,7 @@ AutocompleteMatch SearchProviderTest::FindMatchWithDestination( // Make sure we query history for the default provider and a URLFetcher is // created for the default provider suggest results. TEST_F(SearchProviderTest, QueryDefaultProvider) { - std::wstring term = term1_.substr(0, term1_.size() - 1); + string16 term = term1_.substr(0, term1_.size() - 1); QueryForInput(term); // Make sure the default providers suggest service was queried. @@ -198,7 +200,8 @@ TEST_F(SearchProviderTest, QueryDefaultProvider) { // And the URL matches what we expected. GURL expected_url = GURL(WideToUTF8(default_t_url_->suggestions_url()-> - ReplaceSearchTerms(*default_t_url_, term, 0, std::wstring()))); + ReplaceSearchTerms(*default_t_url_, UTF16ToWide(term), + 0, std::wstring()))); ASSERT_TRUE(fetcher->original_url() == expected_url); // Tell the SearchProvider the suggest query is done. @@ -219,8 +222,9 @@ TEST_F(SearchProviderTest, QueryDefaultProvider) { // Issues a query that matches the registered keyword and makes sure history // is queried as well as URLFetchers getting created. TEST_F(SearchProviderTest, QueryKeywordProvider) { - std::wstring term = keyword_term_.substr(0, keyword_term_.size() - 1); - QueryForInput(keyword_t_url_->keyword() + L" " + term); + string16 term = keyword_term_.substr(0, keyword_term_.size() - 1); + QueryForInput(WideToUTF16(keyword_t_url_->keyword()) + + UTF8ToUTF16(" ") + term); // Make sure the default providers suggest service was queried. TestURLFetcher* default_fetcher = test_factory_.GetFetcherByID( @@ -240,7 +244,8 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { // And the URL matches what we expected. GURL expected_url = GURL(WideToUTF8(keyword_t_url_->suggestions_url()-> - ReplaceSearchTerms(*keyword_t_url_, term, 0, std::wstring()))); + ReplaceSearchTerms(*keyword_t_url_, UTF16ToWide(term), 0, + std::wstring()))); ASSERT_TRUE(keyword_fetcher->original_url() == expected_url); // Tell the SearchProvider the keyword suggest query is done. @@ -261,6 +266,6 @@ TEST_F(SearchProviderTest, QueryKeywordProvider) { EXPECT_TRUE(match.template_url); // The fill into edit should contain the keyword. - EXPECT_EQ(keyword_t_url_->keyword() + L" " + keyword_term_, + EXPECT_EQ(keyword_t_url_->keyword() + L" " + UTF16ToWide(keyword_term_), match.fill_into_edit); } |