diff options
Diffstat (limited to 'chrome/browser/template_url_model_unittest.cc')
-rw-r--r-- | chrome/browser/template_url_model_unittest.cc | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/chrome/browser/template_url_model_unittest.cc b/chrome/browser/template_url_model_unittest.cc index 3af0c5c..492ac2b 100644 --- a/chrome/browser/template_url_model_unittest.cc +++ b/chrome/browser/template_url_model_unittest.cc @@ -138,14 +138,16 @@ class TemplateURLModelTest : public testing::Test, TemplateURLRef::google_base_url_ = NULL; } - TemplateURL* AddKeywordWithDate(const std::wstring & keyword, - const std::wstring & url, - const std::wstring & short_name, + TemplateURL* AddKeywordWithDate(const std::wstring& keyword, + bool autogenerate_keyword, + const std::wstring& url, + 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->set_keyword(keyword); + template_url->set_autogenerate_keyword(autogenerate_keyword); template_url->set_short_name(short_name); template_url->set_date_created(created_date); template_url->set_safe_for_autoreplace(safe_for_autoreplace); @@ -309,14 +311,16 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { EXPECT_EQ(0, model_->GetTemplateURLs().size()); // Create one with a 0 time. - AddKeywordWithDate(L"key1", L"http://foo1", L"name1", true, Time()); + AddKeywordWithDate(L"key1", false, L"http://foo1", L"name1", true, Time()); // Create one for now and +/- 1 day. - AddKeywordWithDate(L"key2", L"http://foo2", L"name2", true, now - one_day); - AddKeywordWithDate(L"key3", L"http://foo3", L"name3", true, now); - AddKeywordWithDate(L"key4", L"http://foo4", L"name4", true, now + one_day); + AddKeywordWithDate(L"key2", false, L"http://foo2", L"name2", true, + now - one_day); + AddKeywordWithDate(L"key3", false, L"http://foo3", L"name3", true, now); + AddKeywordWithDate(L"key4", false, L"http://foo4", L"name4", true, + now + one_day); // Try the other three states. - AddKeywordWithDate(L"key5", L"http://foo5", L"name5", false, now); - AddKeywordWithDate(L"key6", L"http://foo6", L"name6", false, month_ago); + AddKeywordWithDate(L"key5", false, L"http://foo5", L"name5", false, now); + AddKeywordWithDate(L"key6", false, L"http://foo6", L"name6", false, month_ago); // We just added a few items, validate them. EXPECT_EQ(6, model_->GetTemplateURLs().size()); @@ -395,8 +399,8 @@ TEST_F(TemplateURLModelTest, DefaultSearchProvider) { // Add a new TemplateURL. VerifyLoad(); const size_t initial_count = model_->GetTemplateURLs().size(); - TemplateURL* t_url = - AddKeywordWithDate(L"key1", L"http://foo1", L"name1", true, Time()); + TemplateURL* t_url = AddKeywordWithDate(L"key1", false, L"http://foo1", + L"name1", true, Time()); changed_count_ = 0; model_->SetDefaultSearchProvider(t_url); @@ -427,7 +431,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { const size_t initial_count = model_->GetTemplateURLs().size(); - AddKeywordWithDate(std::wstring(), L"http://foo1", L"name1", true, Time()); + AddKeywordWithDate(std::wstring(), false, L"http://foo1", L"name1", true, + Time()); // We just added a few items, validate them. ASSERT_EQ(initial_count + 1, model_->GetTemplateURLs().size()); @@ -449,8 +454,8 @@ TEST_F(TemplateURLModelTest, TemplateURLWithNoKeyword) { TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", std::wstring(), NULL)); - TemplateURL* t_url = - AddKeywordWithDate(L"foo", L"http://foo1", L"name1", true, Time()); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, L"http://foo1", + L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", L"http://foo2", NULL)); @@ -465,8 +470,8 @@ TEST_F(TemplateURLModelTest, CantReplaceWithSameKeyword) { TEST_F(TemplateURLModelTest, CantReplaceWithSameHosts) { ASSERT_TRUE(model_->CanReplaceKeyword(L"foo", L"http://foo.com", NULL)); - TemplateURL* t_url = - AddKeywordWithDate(L"foo", L"http://foo.com", L"name1", true, Time()); + TemplateURL* t_url = AddKeywordWithDate(L"foo", false, L"http://foo.com", + L"name1", true, Time()); // Can still replace, newly added template url is marked safe to replace. ASSERT_TRUE(model_->CanReplaceKeyword(L"bar", L"http://foo.com", NULL)); @@ -594,8 +599,8 @@ TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { { "http://x/foo?q=b&q=xx", L"" }, }; - AddKeywordWithDate(L"x", L"http://x/foo?q={searchTerms}", L"name", false, - Time()); + AddKeywordWithDate(L"x", false, L"http://x/foo?q={searchTerms}", L"name", + false, Time()); for (size_t i = 0; i < arraysize(data); ++i) { model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url))); @@ -612,7 +617,7 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { { "http://x/foo?y=xx" }, }; - AddKeywordWithDate(L"x", L"http://x/foo", L"name", false, Time()); + AddKeywordWithDate(L"x", false, L"http://x/foo", L"name", false, Time()); for (size_t i = 0; i < arraysize(data); ++i) { model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url))); @@ -621,21 +626,28 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { } TEST_F(TemplateURLModelTest, ChangeGoogleBaseValue) { + // NOTE: Do not do a VerifyLoad() here as it will load the prepopulate data, + // which also has a {google:baseURL} keyword in it, which will confuse this + // test. SetGoogleBaseURL(L"http://google.com/"); - const TemplateURL* t_url = - AddKeywordWithDate(L"x", L"{google:baseURL}?q={searchTerms}", - L"name", false, Time()); + const TemplateURL* t_url = AddKeywordWithDate(std::wstring(), true, + L"{google:baseURL}?q={searchTerms}", L"name", false, Time()); ASSERT_EQ(t_url, model_->GetTemplateURLForHost("google.com")); - ASSERT_EQ("google.com", t_url->url()->GetHost()); + EXPECT_EQ("google.com", t_url->url()->GetHost()); + EXPECT_EQ(L"google.com", t_url->keyword()); // Change the Google base url. + model_->loaded_ = true; // Hack to make sure we get notified of the base URL + // changing. SetGoogleBaseURL(L"http://foo.com/"); model_->GoogleBaseURLChanged(); + VerifyObserverCount(1); // Make sure the host->TemplateURL map was updated appropriately. ASSERT_EQ(t_url, model_->GetTemplateURLForHost("foo.com")); - ASSERT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL); - ASSERT_EQ("foo.com", t_url->url()->GetHost()); - ASSERT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, + EXPECT_TRUE(model_->GetTemplateURLForHost("google.com") == NULL); + EXPECT_EQ("foo.com", t_url->url()->GetHost()); + EXPECT_EQ(L"foo.com", t_url->keyword()); + EXPECT_EQ(L"http://foo.com/?q=x", t_url->url()->ReplaceSearchTerms(*t_url, L"x", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); } |