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 #include "base/scoped_temp_dir.h" |
5 #include "base/scoped_vector.h" | 5 #include "base/scoped_vector.h" |
6 #include "chrome/browser/search_engines/template_url.h" | 6 #include "chrome/browser/search_engines/template_url.h" |
7 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 7 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
9 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 typedef testing::Test TemplateURLPrepopulateDataTest; | 12 typedef testing::Test TemplateURLPrepopulateDataTest; |
13 | 13 |
14 // Verifies the set of prepopulate data doesn't contain entries with duplicate | 14 // Verifies the set of prepopulate data doesn't contain entries with duplicate |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 71 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
72 profile.GetPrefs(), &(urls.get()), &url_count); | 72 profile.GetPrefs(), &(urls.get()), &url_count); |
73 std::set<int> unique_ids; | 73 std::set<int> unique_ids; |
74 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { | 74 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { |
75 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == | 75 ASSERT_TRUE(unique_ids.find(urls[turl_i]->prepopulate_id()) == |
76 unique_ids.end()); | 76 unique_ids.end()); |
77 unique_ids.insert(urls[turl_i]->prepopulate_id()); | 77 unique_ids.insert(urls[turl_i]->prepopulate_id()); |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
| 81 |
| 82 // Verifies that default search providers from the preferences file |
| 83 // override the built-in ones. |
| 84 TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { |
| 85 const char pref_data[] = |
| 86 "{ " |
| 87 " \"search_provider_overrides_version\":1," |
| 88 " \"search_provider_overrides\": [" |
| 89 " { \"name\":\"foo\"," |
| 90 " \"keyword\":\"fook\"," |
| 91 " \"search_url\":\"http://foo.com/s?q={searchTerms}\"," |
| 92 " \"favicon_url\":\"http://foi.com/favicon.ico\"," |
| 93 " \"suggest_url\":\"\"," |
| 94 " \"encoding\":\"UTF-8\"," |
| 95 " \"id\":1001" |
| 96 " }" |
| 97 " ]" |
| 98 "}"; |
| 99 |
| 100 ScopedTempDir temp_dir; |
| 101 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 102 FilePath preferences_file = temp_dir.path().AppendASCII("Preferences"); |
| 103 file_util::WriteFile(preferences_file, pref_data, sizeof(pref_data)); |
| 104 |
| 105 scoped_ptr<PrefService> prefs(new PrefService(new PrefValueStore( |
| 106 NULL, new JsonPrefStore(preferences_file, |
| 107 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), |
| 108 NULL, NULL))); |
| 109 |
| 110 TemplateURLPrepopulateData::RegisterUserPrefs(prefs.get()); |
| 111 |
| 112 int version = TemplateURLPrepopulateData::GetDataVersion(prefs.get()); |
| 113 EXPECT_EQ(1, version); |
| 114 |
| 115 std::vector<TemplateURL*> t_urls; |
| 116 size_t default_index; |
| 117 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 118 prefs.get(), &t_urls, &default_index); |
| 119 |
| 120 ASSERT_EQ(1u, t_urls.size()); |
| 121 EXPECT_EQ(L"foo", t_urls[0]->short_name()); |
| 122 EXPECT_EQ(L"fook", t_urls[0]->keyword()); |
| 123 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); |
| 124 EXPECT_EQ("foi.com", t_urls[0]->GetFavIconURL().host()); |
| 125 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); |
| 126 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); |
| 127 } |
OLD | NEW |