| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/scoped_temp_dir.h" | 6 #include "base/scoped_temp_dir.h" |
| 7 #include "base/scoped_vector.h" | 7 #include "base/scoped_vector.h" |
| 8 #include "chrome/browser/search_engines/search_engine_type.h" | 8 #include "chrome/browser/search_engines/search_engine_type.h" |
| 9 #include "chrome/browser/search_engines/search_terms_data.h" | 9 #include "chrome/browser/search_engines/search_terms_data.h" |
| 10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == | 84 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == |
| 85 unique_ids.end()); | 85 unique_ids.end()); |
| 86 unique_ids.insert(urls[turl_i]->prepopulate_id()); | 86 unique_ids.insert(urls[turl_i]->prepopulate_id()); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Verifies that default search providers from the preferences file | 91 // Verifies that default search providers from the preferences file |
| 92 // override the built-in ones. | 92 // override the built-in ones. |
| 93 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { | 93 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
| 94 TestingPrefService prefs; | 94 scoped_ptr<TestingPrefService> prefs( |
| 95 TemplateURLPrepopulateData::RegisterUserPrefs(&prefs); | 95 TestingPrefService::CreateTestingPrefService()); |
| 96 prefs.SetUserPref(prefs::kSearchProviderOverridesVersion, | 96 TemplateURLPrepopulateData::RegisterUserPrefs(prefs.get()); |
| 97 Value::CreateIntegerValue(1)); | 97 prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, |
| 98 Value::CreateIntegerValue(1)); |
| 98 ListValue* overrides = new ListValue; | 99 ListValue* overrides = new ListValue; |
| 99 DictionaryValue* entry = new DictionaryValue; | 100 DictionaryValue* entry = new DictionaryValue; |
| 100 entry->SetString("name", "foo"); | 101 entry->SetString("name", "foo"); |
| 101 entry->SetString("keyword", "fook"); | 102 entry->SetString("keyword", "fook"); |
| 102 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); | 103 entry->SetString("search_url", "http://foo.com/s?q={searchTerms}"); |
| 103 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); | 104 entry->SetString("favicon_url", "http://foi.com/favicon.ico"); |
| 104 entry->SetString("suggest_url", ""); | 105 entry->SetString("suggest_url", ""); |
| 105 entry->SetString("instant_url", ""); | 106 entry->SetString("instant_url", ""); |
| 106 entry->SetString("encoding", "UTF-8"); | 107 entry->SetString("encoding", "UTF-8"); |
| 107 entry->SetInteger("search_engine_type", 1); | 108 entry->SetInteger("search_engine_type", 1); |
| 108 entry->SetInteger("logo_id", 0); | 109 entry->SetInteger("logo_id", 0); |
| 109 entry->SetInteger("id", 1001); | 110 entry->SetInteger("id", 1001); |
| 110 overrides->Append(entry); | 111 overrides->Append(entry); |
| 111 prefs.SetUserPref(prefs::kSearchProviderOverrides, overrides); | 112 prefs->SetUserPref(prefs::kSearchProviderOverrides, overrides); |
| 112 | 113 |
| 113 int version = TemplateURLPrepopulateData::GetDataVersion(&prefs); | 114 int version = TemplateURLPrepopulateData::GetDataVersion(prefs.get()); |
| 114 EXPECT_EQ(1, version); | 115 EXPECT_EQ(1, version); |
| 115 | 116 |
| 116 ScopedVector<TemplateURL> t_urls; | 117 ScopedVector<TemplateURL> t_urls; |
| 117 size_t default_index; | 118 size_t default_index; |
| 118 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 119 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 119 &prefs, &(t_urls.get()), &default_index); | 120 prefs.get(), &(t_urls.get()), &default_index); |
| 120 | 121 |
| 121 ASSERT_EQ(1u, t_urls.size()); | 122 ASSERT_EQ(1u, t_urls.size()); |
| 122 EXPECT_EQ(L"foo", t_urls[0]->short_name()); | 123 EXPECT_EQ(L"foo", t_urls[0]->short_name()); |
| 123 EXPECT_EQ(L"fook", t_urls[0]->keyword()); | 124 EXPECT_EQ(L"fook", t_urls[0]->keyword()); |
| 124 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); | 125 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); |
| 125 EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); | 126 EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); |
| 126 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); | 127 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
| 127 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); | 128 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); |
| 128 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type()); | 129 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type()); |
| 129 EXPECT_EQ(0, t_urls[0]->logo_id()); | 130 EXPECT_EQ(0, t_urls[0]->logo_id()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 EXPECT_EQ(kNoSearchEngineLogo, | 178 EXPECT_EQ(kNoSearchEngineLogo, |
| 178 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine)); | 179 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine)); |
| 179 GURL engine_with_logo("http://www.ask.com/"); | 180 GURL engine_with_logo("http://www.ask.com/"); |
| 180 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK, | 181 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK, |
| 181 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo)); | 182 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo)); |
| 182 GURL engine_no_logo("http://araby.com/"); | 183 GURL engine_no_logo("http://araby.com/"); |
| 183 EXPECT_EQ(kNoSearchEngineLogo, | 184 EXPECT_EQ(kNoSearchEngineLogo, |
| 184 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo)); | 185 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo)); |
| 185 | 186 |
| 186 } | 187 } |
| OLD | NEW |