Index: chrome/browser/autocomplete/shortcuts_backend_unittest.cc |
diff --git a/chrome/browser/autocomplete/shortcuts_backend_unittest.cc b/chrome/browser/autocomplete/shortcuts_backend_unittest.cc |
index 7e4455a3713c34046607b08978f67c64719fb173..f814098dbffef2529896c828760b64d0baf031d8 100644 |
--- a/chrome/browser/autocomplete/shortcuts_backend_unittest.cc |
+++ b/chrome/browser/autocomplete/shortcuts_backend_unittest.cc |
@@ -11,7 +11,10 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/autocomplete/shortcuts_backend_factory.h" |
#include "chrome/browser/history/shortcuts_database.h" |
+#include "chrome/browser/search_engines/template_url_service.h" |
+#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/test/base/testing_profile.h" |
+#include "chrome/test/base/ui_test_utils.h" |
#include "content/public/test/test_browser_thread.h" |
#include "sql/statement.h" |
@@ -30,6 +33,7 @@ class ShortcutsBackendTest : public testing::Test, |
const std::string& contents_class = std::string(), |
const std::string& description_class = std::string(), |
AutocompleteMatch::Type type = AutocompleteMatchType::URL_WHAT_YOU_TYPED); |
+ void SetSearchProvider(); |
virtual void SetUp(); |
virtual void TearDown(); |
@@ -52,9 +56,10 @@ class ShortcutsBackendTest : public testing::Test, |
bool DeleteShortcutsWithIDs( |
const history::ShortcutsDatabase::ShortcutIDs& deleted_ids); |
+ protected: |
+ TestingProfile profile_; |
private: |
- TestingProfile profile_; |
scoped_refptr<ShortcutsBackend> backend_; |
base::MessageLoopForUI ui_message_loop_; |
content::TestBrowserThread ui_thread_; |
@@ -86,7 +91,20 @@ history::ShortcutsDatabase::Shortcut::MatchCore |
AutocompleteMatch::ClassificationsFromString(contents_class); |
match.description_class = |
AutocompleteMatch::ClassificationsFromString(description_class); |
- return ShortcutsBackend::MatchToMatchCore(match); |
+ return ShortcutsBackend::MatchToMatchCore(match, &profile_); |
+} |
+ |
+void ShortcutsBackendTest::SetSearchProvider() { |
+ TemplateURLService* template_url_service = |
+ TemplateURLServiceFactory::GetForProfile(&profile_); |
+ TemplateURLData data; |
+ data.SetURL("http://foo.com/search?bar={searchTerms}"); |
+ data.SetKeyword(base::UTF8ToUTF16("foo")); |
+ |
+ TemplateURL* template_url = new TemplateURL(&profile_, data); |
+ // Takes ownership of |template_url|. |
+ template_url_service->Add(template_url); |
+ template_url_service->SetDefaultSearchProvider(template_url); |
} |
void ShortcutsBackendTest::SetUp() { |
@@ -96,6 +114,12 @@ void ShortcutsBackendTest::SetUp() { |
backend_ = ShortcutsBackendFactory::GetForProfile(&profile_); |
ASSERT_TRUE(backend_.get()); |
backend_->AddObserver(this); |
+ |
+ TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
+ &profile_, &TemplateURLServiceFactory::BuildInstanceFor); |
+ TemplateURLService* template_url_service = |
+ TemplateURLServiceFactory::GetForProfile(&profile_); |
+ ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
} |
void ShortcutsBackendTest::TearDown() { |
@@ -164,6 +188,14 @@ TEST_F(ShortcutsBackendTest, SanitizeMatchCore) { |
"0,1", "0,0", AutocompleteMatchType::SEARCH_HISTORY }, |
{ "0,1", "0,0", AutocompleteMatchType::SEARCH_SUGGEST, |
"0,1", "0,0", AutocompleteMatchType::SEARCH_HISTORY }, |
+ { "0,1", "0,0", AutocompleteMatchType::SEARCH_SUGGEST_ENTITY, |
Peter Kasting
2014/03/21 18:36:26
Nit: If you're going to indent these less, then al
Anuj
2014/03/24 07:16:16
Done.
|
+ "", "", AutocompleteMatchType::SEARCH_HISTORY }, |
+ { "0,1", "0,0", AutocompleteMatchType::SEARCH_SUGGEST_INFINITE, |
+ "", "", AutocompleteMatchType::SEARCH_HISTORY }, |
+ { "0,1", "0,0", AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED, |
+ "", "", AutocompleteMatchType::SEARCH_HISTORY }, |
+ { "0,1", "0,0", AutocompleteMatchType::SEARCH_SUGGEST_PROFILE, |
+ "", "", AutocompleteMatchType::SEARCH_HISTORY }, |
}; |
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
@@ -177,6 +209,31 @@ TEST_F(ShortcutsBackendTest, SanitizeMatchCore) { |
} |
} |
+TEST_F(ShortcutsBackendTest, EntitySuggestionTest) { |
+ SetSearchProvider(); |
+ AutocompleteMatch match; |
+ match.fill_into_edit = base::UTF8ToUTF16("franklin d roosevelt"); |
+ match.type = AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
+ match.contents = base::UTF8ToUTF16("roosevelt"); |
+ match.contents_class = |
+ AutocompleteMatch::ClassificationsFromString("0,0,5,2"); |
+ match.description = base::UTF8ToUTF16("Franklin D. Roosevelt"); |
+ match.description_class = AutocompleteMatch::ClassificationsFromString("0,4"); |
+ match.destination_url = GURL( |
+ "http://www.foo.com/search?bar=franklin+d+roosevelt&gs_ssp=1234"); |
+ match.keyword = base::UTF8ToUTF16("foo"); |
+ |
+ history::ShortcutsDatabase::Shortcut::MatchCore match_core = |
+ ShortcutsBackend::MatchToMatchCore(match, &profile_); |
+ |
+ EXPECT_EQ("http://foo.com/search?bar=franklin+d+roosevelt", |
+ match_core.destination_url.spec()); |
+ EXPECT_EQ(match.fill_into_edit, match_core.contents); |
+ EXPECT_TRUE(match_core.contents_class.empty()); |
+ EXPECT_EQ(base::string16(), match_core.description); |
+ EXPECT_TRUE(match_core.description_class.empty()); |
+} |
+ |
TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { |
InitBackend(); |
EXPECT_FALSE(changed_notified()); |