Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thread safe handling of Profiles Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/scoped_temp_dir.h" 7 #include "base/scoped_temp_dir.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/search_engines/search_engine_type.h" 9 #include "chrome/browser/search_engines/search_engine_type.h"
10 #include "chrome/browser/search_engines/search_terms_data.h" 10 #include "chrome/browser/search_engines/search_terms_data.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword()); 125 EXPECT_EQ(ASCIIToUTF16("fook"), t_urls[0]->keyword());
126 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost()); 126 EXPECT_EQ("foo.com", t_urls[0]->url()->GetHost());
127 EXPECT_EQ("foi.com", t_urls[0]->GetFaviconURL().host()); 127 EXPECT_EQ("foi.com", t_urls[0]->GetFaviconURL().host());
128 EXPECT_EQ(1u, t_urls[0]->input_encodings().size()); 128 EXPECT_EQ(1u, t_urls[0]->input_encodings().size());
129 EXPECT_EQ(1001, t_urls[0]->prepopulate_id()); 129 EXPECT_EQ(1001, t_urls[0]->prepopulate_id());
130 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type()); 130 EXPECT_EQ(SEARCH_ENGINE_GOOGLE, t_urls[0]->search_engine_type());
131 EXPECT_EQ(0, t_urls[0]->logo_id()); 131 EXPECT_EQ(0, t_urls[0]->logo_id());
132 } 132 }
133 133
134 TEST_F(TemplateURLPrepopulateDataTest, SearchEngineFromOrigin) { 134 TEST_F(TemplateURLPrepopulateDataTest, SearchEngineFromOrigin) {
135 UIThreadSearchTermsData search_terms_data;
136 std::set<GURL> unique_engines; 135 std::set<GURL> unique_engines;
137 136
138 { // Scoping for the profile. 137 { // Scoping for the profile.
139 TestingProfile profile; 138 TestingProfile profile;
139 UIThreadSearchTermsData search_terms_data(&profile);
Peter Kasting 2011/08/10 20:54:06 You can pass NULL here and below.
140 for (size_t i = 0; i < arraysize(kCountryIds); ++i) { 140 for (size_t i = 0; i < arraysize(kCountryIds); ++i) {
141 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall, 141 profile.GetPrefs()->SetInteger(prefs::kCountryIDAtInstall,
142 kCountryIds[i]); 142 kCountryIds[i]);
143 ScopedVector<TemplateURL> urls; 143 ScopedVector<TemplateURL> urls;
144 size_t default_index; 144 size_t default_index;
145 TemplateURLPrepopulateData::GetPrepopulatedEngines( 145 TemplateURLPrepopulateData::GetPrepopulatedEngines(
146 profile.GetPrefs(), &(urls.get()), &default_index); 146 profile.GetPrefs(), &(urls.get()), &default_index);
147 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) { 147 for (size_t turl_i = 0; turl_i < urls.size(); ++turl_i) {
148 GURL engine_url(urls[turl_i]->url()->url()); 148 GURL engine_url(urls[turl_i]->url()->url());
149 if (!engine_url.is_valid()) { 149 if (!engine_url.is_valid()) {
150 engine_url = TemplateURLService::GenerateSearchURLUsingTermsData( 150 engine_url = TemplateURLService::GenerateSearchURLUsingTermsData(
151 urls[turl_i], search_terms_data); 151 urls[turl_i], search_terms_data);
152 } 152 }
153 GURL origin = engine_url.GetOrigin(); 153 GURL origin = engine_url.GetOrigin();
154 unique_engines.insert(origin); 154 unique_engines.insert(origin);
155 } 155 }
156 } 156 }
157 } 157 }
158 158
159 TestingProfile profile; 159 TestingProfile profile;
160 UIThreadSearchTermsData search_terms_data(&profile);
160 for (std::set<GURL>::iterator it = unique_engines.begin(); 161 for (std::set<GURL>::iterator it = unique_engines.begin();
161 it != unique_engines.end(); ++it) { 162 it != unique_engines.end(); ++it) {
162 scoped_ptr<TemplateURL> found_url( 163 scoped_ptr<TemplateURL> found_url(
163 TemplateURLPrepopulateData::GetEngineForOrigin(profile.GetPrefs(), 164 TemplateURLPrepopulateData::GetEngineForOrigin(&profile, *it));
164 *it));
165 EXPECT_EQ( 165 EXPECT_EQ(
166 TemplateURLService::GenerateSearchURLUsingTermsData( 166 TemplateURLService::GenerateSearchURLUsingTermsData(
167 found_url.get(), search_terms_data).GetOrigin(), 167 found_url.get(), search_terms_data).GetOrigin(),
168 it->GetOrigin()); 168 it->GetOrigin());
169 } 169 }
170 170
171 GURL not_a_search_engine("http://example.com/"); 171 GURL not_a_search_engine("http://example.com/");
172 EXPECT_EQ(NULL, TemplateURLPrepopulateData::GetEngineForOrigin( 172 EXPECT_EQ(NULL, TemplateURLPrepopulateData::GetEngineForOrigin(&profile,
173 profile.GetPrefs(),
174 not_a_search_engine)); 173 not_a_search_engine));
175 } 174 }
176 175
177 TEST_F(TemplateURLPrepopulateDataTest, GetSearchEngineLogo) { 176 TEST_F(TemplateURLPrepopulateDataTest, GetSearchEngineLogo) {
178 GURL bad_engine("http://example.com/"); 177 GURL bad_engine("http://example.com/");
179 EXPECT_EQ(kNoSearchEngineLogo, 178 EXPECT_EQ(kNoSearchEngineLogo,
180 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine)); 179 TemplateURLPrepopulateData::GetSearchEngineLogo(bad_engine));
181 GURL engine_with_logo("http://www.ask.com/"); 180 GURL engine_with_logo("http://www.ask.com/");
182 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK, 181 EXPECT_EQ(IDR_SEARCH_ENGINE_LOGO_ASK,
183 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo)); 182 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_with_logo));
184 GURL engine_no_logo("http://araby.com/"); 183 GURL engine_no_logo("http://araby.com/");
185 EXPECT_EQ(kNoSearchEngineLogo, 184 EXPECT_EQ(kNoSearchEngineLogo,
186 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo)); 185 TemplateURLPrepopulateData::GetSearchEngineLogo(engine_no_logo));
187 186
188 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698