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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_provider_unittest.cc

Issue 10909130: autocomplete: Add AutocompleteProvider::Type enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix inadvertently-change parameter in test Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/autocomplete_provider.h" 5 #include "chrome/browser/autocomplete/autocomplete_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 27 matching lines...) Expand all
38 const char kTestTemplateURLKeyword[] = "t"; 38 const char kTestTemplateURLKeyword[] = "t";
39 } 39 }
40 40
41 // Autocomplete provider that provides known results. Note that this is 41 // Autocomplete provider that provides known results. Note that this is
42 // refcounted so that it can also be a task on the message loop. 42 // refcounted so that it can also be a task on the message loop.
43 class TestProvider : public AutocompleteProvider { 43 class TestProvider : public AutocompleteProvider {
44 public: 44 public:
45 TestProvider(int relevance, const string16& prefix, 45 TestProvider(int relevance, const string16& prefix,
46 Profile* profile, 46 Profile* profile,
47 const string16 match_keyword) 47 const string16 match_keyword)
48 : AutocompleteProvider(NULL, profile, ""), 48 : AutocompleteProvider(NULL, profile, AutocompleteProvider::TYPE_SEARCH),
49 relevance_(relevance), 49 relevance_(relevance),
50 prefix_(prefix), 50 prefix_(prefix),
51 match_keyword_(match_keyword) { 51 match_keyword_(match_keyword) {
52 } 52 }
53 53
54 virtual void Start(const AutocompleteInput& input, 54 virtual void Start(const AutocompleteInput& input,
55 bool minimal_changes); 55 bool minimal_changes);
56 56
57 void set_listener(AutocompleteProviderListener* listener) { 57 void set_listener(AutocompleteProviderListener* listener) {
58 listener_ = listener; 58 listener_ = listener;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 struct AssistedQueryStatsTestData { 156 struct AssistedQueryStatsTestData {
157 const AutocompleteMatch::Type match_type; 157 const AutocompleteMatch::Type match_type;
158 const std::string expected_aqs; 158 const std::string expected_aqs;
159 }; 159 };
160 160
161 protected: 161 protected:
162 // Registers a test TemplateURL under the given keyword. 162 // Registers a test TemplateURL under the given keyword.
163 void RegisterTemplateURL(const string16 keyword, 163 void RegisterTemplateURL(const string16 keyword,
164 const std::string& template_url); 164 const std::string& template_url);
165 165
166 void ResetControllerWithTestProviders(bool same_destinations); 166 // Resets |controller_| with two TestProviders. |provider1_ptr| and
167 // |provider2_ptr| are updated to point to the new providers if non-NULL.
168 void ResetControllerWithTestProviders(bool same_destinations,
169 TestProvider** provider1_ptr,
170 TestProvider** provider2_ptr);
167 171
168 // Runs a query on the input "a", and makes sure both providers' input is 172 // Runs a query on the input "a", and makes sure both providers' input is
169 // properly collected. 173 // properly collected.
170 void RunTest(); 174 void RunTest();
171 175
172 void RunRedundantKeywordTest(const KeywordTestData* match_data, size_t size); 176 void RunRedundantKeywordTest(const KeywordTestData* match_data, size_t size);
173 177
174 void RunAssistedQueryStatsTest( 178 void RunAssistedQueryStatsTest(
175 const AssistedQueryStatsTestData* aqs_test_data, 179 const AssistedQueryStatsTestData* aqs_test_data,
176 size_t size); 180 size_t size);
177 181
178 void RunQuery(const string16 query); 182 void RunQuery(const string16 query);
179 183
180 void ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); 184 void ResetControllerWithKeywordAndSearchProviders();
181 void ResetControllerWithKeywordProvider(); 185 void ResetControllerWithKeywordProvider();
182 void RunExactKeymatchTest(bool allow_exact_keyword_match); 186 void RunExactKeymatchTest(bool allow_exact_keyword_match);
183 187
184 // These providers are owned by the controller once it's created. 188 // Returns the provider of type |type| from |controller_|. NULL is returned
185 ACProviders providers_; 189 // if no provider of this type has been created.
190 AutocompleteProvider* GetProvider(AutocompleteProvider::Type type);
186 191
187 AutocompleteResult result_; 192 AutocompleteResult result_;
188 scoped_ptr<AutocompleteController> controller_; 193 scoped_ptr<AutocompleteController> controller_;
189 194
190 private: 195 private:
191 // content::NotificationObserver 196 // content::NotificationObserver
192 virtual void Observe(int type, 197 virtual void Observe(int type,
193 const content::NotificationSource& source, 198 const content::NotificationSource& source,
194 const content::NotificationDetails& details); 199 const content::NotificationDetails& details);
195 200
(...skipping 13 matching lines...) Expand all
209 TemplateURL* default_t_url = new TemplateURL(&profile_, data); 214 TemplateURL* default_t_url = new TemplateURL(&profile_, data);
210 TemplateURLService* turl_model = 215 TemplateURLService* turl_model =
211 TemplateURLServiceFactory::GetForProfile(&profile_); 216 TemplateURLServiceFactory::GetForProfile(&profile_);
212 turl_model->Add(default_t_url); 217 turl_model->Add(default_t_url);
213 turl_model->SetDefaultSearchProvider(default_t_url); 218 turl_model->SetDefaultSearchProvider(default_t_url);
214 TemplateURLID default_provider_id = default_t_url->id(); 219 TemplateURLID default_provider_id = default_t_url->id();
215 ASSERT_NE(0, default_provider_id); 220 ASSERT_NE(0, default_provider_id);
216 } 221 }
217 222
218 void AutocompleteProviderTest::ResetControllerWithTestProviders( 223 void AutocompleteProviderTest::ResetControllerWithTestProviders(
219 bool same_destinations) { 224 bool same_destinations,
220 // Forget about any existing providers. The controller owns them and will 225 TestProvider** provider1_ptr,
221 // Release() them below, when we delete it during the call to reset(). 226 TestProvider** provider2_ptr) {
222 providers_.clear();
223
224 // TODO: Move it outside this method, after refactoring the existing 227 // TODO: Move it outside this method, after refactoring the existing
225 // unit tests. Specifically: 228 // unit tests. Specifically:
226 // (1) Make sure that AutocompleteMatch.keyword is set iff there is 229 // (1) Make sure that AutocompleteMatch.keyword is set iff there is
227 // a corresponding call to RegisterTemplateURL; otherwise the 230 // a corresponding call to RegisterTemplateURL; otherwise the
228 // controller flow will crash; this practically means that 231 // controller flow will crash; this practically means that
229 // RunTests/ResetControllerXXX/RegisterTemplateURL should 232 // RunTests/ResetControllerXXX/RegisterTemplateURL should
230 // be coordinated with each other. 233 // be coordinated with each other.
231 // (2) Inject test arguments rather than rely on the hardcoded values, e.g. 234 // (2) Inject test arguments rather than rely on the hardcoded values, e.g.
232 // don't rely on kResultsPerProvided and default relevance ordering 235 // don't rely on kResultsPerProvided and default relevance ordering
233 // (B > A). 236 // (B > A).
234 RegisterTemplateURL(ASCIIToUTF16(kTestTemplateURLKeyword), 237 RegisterTemplateURL(ASCIIToUTF16(kTestTemplateURLKeyword),
235 "http://aqs/{searchTerms}/{google:assistedQueryStats}"); 238 "http://aqs/{searchTerms}/{google:assistedQueryStats}");
236 239
240 ACProviders providers;
241
237 // Construct two new providers, with either the same or different prefixes. 242 // Construct two new providers, with either the same or different prefixes.
238 TestProvider* providerA = 243 TestProvider* provider1 = new TestProvider(
239 new TestProvider(kResultsPerProvider, 244 kResultsPerProvider,
240 ASCIIToUTF16("http://a"), 245 ASCIIToUTF16("http://a"),
241 &profile_, 246 &profile_,
242 ASCIIToUTF16(kTestTemplateURLKeyword)); 247 ASCIIToUTF16(kTestTemplateURLKeyword));
243 providerA->AddRef(); 248 provider1->AddRef();
244 providers_.push_back(providerA); 249 providers.push_back(provider1);
245 250
246 TestProvider* providerB = new TestProvider( 251 TestProvider* provider2 = new TestProvider(
247 kResultsPerProvider * 2, 252 kResultsPerProvider * 2,
248 same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b"), 253 same_destinations ? ASCIIToUTF16("http://a") : ASCIIToUTF16("http://b"),
249 &profile_, 254 &profile_,
250 string16()); 255 string16());
251 providerB->AddRef(); 256 provider2->AddRef();
252 providers_.push_back(providerB); 257 providers.push_back(provider2);
253 258
254 // Reset the controller to contain our new providers. 259 // Reset the controller to contain our new providers.
255 AutocompleteController* controller = 260 AutocompleteController* controller =
256 new AutocompleteController(providers_, &profile_); 261 new AutocompleteController(providers, &profile_);
Peter Kasting 2012/09/11 01:38:42 Wait a minute. AutocompleteController declares Au
Daniel Erat 2012/09/11 02:09:22 Nice! Done.
257 controller_.reset(controller); 262 controller_.reset(controller);
258 providerA->set_listener(controller); 263 provider1->set_listener(controller);
259 providerB->set_listener(controller); 264 provider2->set_listener(controller);
260 265
261 // The providers don't complete synchronously, so listen for "result updated" 266 // The providers don't complete synchronously, so listen for "result updated"
262 // notifications. 267 // notifications.
263 registrar_.Add(this, 268 registrar_.Add(this,
264 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, 269 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY,
265 content::Source<AutocompleteController>(controller)); 270 content::Source<AutocompleteController>(controller));
271
272 if (provider1_ptr)
273 *provider1_ptr = provider1;
274 if (provider2_ptr)
275 *provider2_ptr = provider2;
266 } 276 }
267 277
268 void AutocompleteProviderTest:: 278 void AutocompleteProviderTest::
269 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { 279 ResetControllerWithKeywordAndSearchProviders() {
270 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 280 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
271 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 281 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
272 282
273 // Reset the default TemplateURL. 283 // Reset the default TemplateURL.
274 TemplateURLData data; 284 TemplateURLData data;
275 data.SetURL("http://defaultturl/{searchTerms}"); 285 data.SetURL("http://defaultturl/{searchTerms}");
276 TemplateURL* default_t_url = new TemplateURL(&profile_, data); 286 TemplateURL* default_t_url = new TemplateURL(&profile_, data);
277 TemplateURLService* turl_model = 287 TemplateURLService* turl_model =
278 TemplateURLServiceFactory::GetForProfile(&profile_); 288 TemplateURLServiceFactory::GetForProfile(&profile_);
279 turl_model->Add(default_t_url); 289 turl_model->Add(default_t_url);
280 turl_model->SetDefaultSearchProvider(default_t_url); 290 turl_model->SetDefaultSearchProvider(default_t_url);
281 TemplateURLID default_provider_id = default_t_url->id(); 291 TemplateURLID default_provider_id = default_t_url->id();
282 ASSERT_NE(0, default_provider_id); 292 ASSERT_NE(0, default_provider_id);
283 293
284 // Create another TemplateURL for KeywordProvider. 294 // Create another TemplateURL for KeywordProvider.
285 data.short_name = ASCIIToUTF16("k"); 295 data.short_name = ASCIIToUTF16("k");
286 data.SetKeyword(ASCIIToUTF16("k")); 296 data.SetKeyword(ASCIIToUTF16("k"));
287 data.SetURL("http://keyword/{searchTerms}"); 297 data.SetURL("http://keyword/{searchTerms}");
288 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data); 298 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data);
289 turl_model->Add(keyword_t_url); 299 turl_model->Add(keyword_t_url);
290 ASSERT_NE(0, keyword_t_url->id()); 300 ASSERT_NE(0, keyword_t_url->id());
291 301
292 // Forget about any existing providers. The controller owns them and will 302 controller_.reset(new AutocompleteController(
293 // Release() them below, when we delete it during the call to reset(). 303 &profile_, NULL,
294 providers_.clear(); 304 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH));
295
296 // Create both a keyword and search provider, and add them in that order.
297 // (Order is important; see comments in RunExactKeymatchTest().)
298 AutocompleteProvider* keyword_provider = new KeywordProvider(NULL, &profile_);
299 keyword_provider->AddRef();
300 providers_.push_back(keyword_provider);
301 AutocompleteProvider* search_provider = new SearchProvider(NULL, &profile_);
302 search_provider->AddRef();
303 providers_.push_back(search_provider);
304
305 controller_.reset(new AutocompleteController(providers_, &profile_));
306 } 305 }
307 306
308 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { 307 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() {
309 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( 308 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse(
310 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); 309 &profile_, &TemplateURLServiceFactory::BuildInstanceFor);
311 310
312 TemplateURLService* turl_model = 311 TemplateURLService* turl_model =
313 TemplateURLServiceFactory::GetForProfile(&profile_); 312 TemplateURLServiceFactory::GetForProfile(&profile_);
314 313
315 // Create a TemplateURL for KeywordProvider. 314 // Create a TemplateURL for KeywordProvider.
316 TemplateURLData data; 315 TemplateURLData data;
317 data.short_name = ASCIIToUTF16("foo.com"); 316 data.short_name = ASCIIToUTF16("foo.com");
318 data.SetKeyword(ASCIIToUTF16("foo.com")); 317 data.SetKeyword(ASCIIToUTF16("foo.com"));
319 data.SetURL("http://foo.com/{searchTerms}"); 318 data.SetURL("http://foo.com/{searchTerms}");
320 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data); 319 TemplateURL* keyword_t_url = new TemplateURL(&profile_, data);
321 turl_model->Add(keyword_t_url); 320 turl_model->Add(keyword_t_url);
322 ASSERT_NE(0, keyword_t_url->id()); 321 ASSERT_NE(0, keyword_t_url->id());
323 322
324 // Create another TemplateURL for KeywordProvider. 323 // Create another TemplateURL for KeywordProvider.
325 data.short_name = ASCIIToUTF16("bar.com"); 324 data.short_name = ASCIIToUTF16("bar.com");
326 data.SetKeyword(ASCIIToUTF16("bar.com")); 325 data.SetKeyword(ASCIIToUTF16("bar.com"));
327 data.SetURL("http://bar.com/{searchTerms}"); 326 data.SetURL("http://bar.com/{searchTerms}");
328 keyword_t_url = new TemplateURL(&profile_, data); 327 keyword_t_url = new TemplateURL(&profile_, data);
329 turl_model->Add(keyword_t_url); 328 turl_model->Add(keyword_t_url);
330 ASSERT_NE(0, keyword_t_url->id()); 329 ASSERT_NE(0, keyword_t_url->id());
331 330
332 // Forget about any existing providers. The controller owns them and will 331 controller_.reset(new AutocompleteController(
333 // Release() them below, when we delete it during the call to reset(). 332 &profile_, NULL, AutocompleteProvider::TYPE_KEYWORD));
334 providers_.clear();
335
336 // Create both a keyword and search provider, and add them in that order.
337 // (Order is important; see comments in RunExactKeymatchTest().)
338 KeywordProvider* keyword_provider = new KeywordProvider(NULL, &profile_);
339 keyword_provider->AddRef();
340 providers_.push_back(keyword_provider);
341
342 AutocompleteController* controller =
343 new AutocompleteController(providers_, &profile_);
344 controller->set_keyword_provider(keyword_provider);
345 controller_.reset(controller);
346 } 333 }
347 334
348 void AutocompleteProviderTest::RunTest() { 335 void AutocompleteProviderTest::RunTest() {
349 RunQuery(ASCIIToUTF16("a")); 336 RunQuery(ASCIIToUTF16("a"));
350 } 337 }
351 338
352 void AutocompleteProviderTest::RunRedundantKeywordTest( 339 void AutocompleteProviderTest::RunRedundantKeywordTest(
353 const KeywordTestData* match_data, 340 const KeywordTestData* match_data,
354 size_t size) { 341 size_t size) {
355 ACMatches matches; 342 ACMatches matches;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 void AutocompleteProviderTest::RunExactKeymatchTest( 399 void AutocompleteProviderTest::RunExactKeymatchTest(
413 bool allow_exact_keyword_match) { 400 bool allow_exact_keyword_match) {
414 // Send the controller input which exactly matches the keyword provider we 401 // Send the controller input which exactly matches the keyword provider we
415 // created in ResetControllerWithKeywordAndSearchProviders(). The default 402 // created in ResetControllerWithKeywordAndSearchProviders(). The default
416 // match should thus be a keyword match iff |allow_exact_keyword_match| is 403 // match should thus be a keyword match iff |allow_exact_keyword_match| is
417 // true. 404 // true.
418 controller_->Start(ASCIIToUTF16("k test"), string16(), true, false, 405 controller_->Start(ASCIIToUTF16("k test"), string16(), true, false,
419 allow_exact_keyword_match, 406 allow_exact_keyword_match,
420 AutocompleteInput::SYNCHRONOUS_MATCHES); 407 AutocompleteInput::SYNCHRONOUS_MATCHES);
421 EXPECT_TRUE(controller_->done()); 408 EXPECT_TRUE(controller_->done());
422 // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider 409 EXPECT_EQ(GetProvider(allow_exact_keyword_match ?
Peter Kasting 2012/09/11 01:38:42 Nit: Simpler, because you can kill GetProvider() e
Daniel Erat 2012/09/11 02:09:22 Duh. Done.
423 // first, then the search provider. So if the default match is a keyword 410 AutocompleteProvider::TYPE_KEYWORD : AutocompleteProvider::TYPE_SEARCH),
424 // match, it will come from provider 0, otherwise from provider 1.
425 EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1],
426 controller_->result().default_match()->provider); 411 controller_->result().default_match()->provider);
427 } 412 }
428 413
414 AutocompleteProvider* AutocompleteProviderTest::GetProvider(
415 AutocompleteProvider::Type type) {
416 for (ACProviders::const_iterator it = controller_->providers()->begin();
417 it != controller_->providers()->end(); ++it) {
418 if ((*it)->type() == type)
419 return *it;
420 }
421 return NULL;
422 }
423
429 void AutocompleteProviderTest::Observe( 424 void AutocompleteProviderTest::Observe(
430 int type, 425 int type,
431 const content::NotificationSource& source, 426 const content::NotificationSource& source,
432 const content::NotificationDetails& details) { 427 const content::NotificationDetails& details) {
433 if (controller_->done()) { 428 if (controller_->done()) {
434 result_.CopyFrom(controller_->result()); 429 result_.CopyFrom(controller_->result());
435 MessageLoop::current()->Quit(); 430 MessageLoop::current()->Quit();
436 } 431 }
437 } 432 }
438 433
439 // Tests that the default selection is set properly when updating results. 434 // Tests that the default selection is set properly when updating results.
440 TEST_F(AutocompleteProviderTest, Query) { 435 TEST_F(AutocompleteProviderTest, Query) {
441 ResetControllerWithTestProviders(false); 436 TestProvider* provider1 = NULL;
437 TestProvider* provider2 = NULL;
438 ResetControllerWithTestProviders(false, &provider1, &provider2);
442 RunTest(); 439 RunTest();
443 440
444 // Make sure the default match gets set to the highest relevance match. The 441 // Make sure the default match gets set to the highest relevance match. The
445 // highest relevance matches should come from the second provider. 442 // highest relevance matches should come from the second provider.
446 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers 443 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers
447 ASSERT_NE(result_.end(), result_.default_match()); 444 ASSERT_NE(result_.end(), result_.default_match());
448 EXPECT_EQ(providers_[1], result_.default_match()->provider); 445 EXPECT_EQ(provider2, result_.default_match()->provider);
449 } 446 }
450 447
451 // Tests assisted query stats. 448 // Tests assisted query stats.
452 TEST_F(AutocompleteProviderTest, AssistedQueryStats) { 449 TEST_F(AutocompleteProviderTest, AssistedQueryStats) {
453 ResetControllerWithTestProviders(false); 450 ResetControllerWithTestProviders(false, NULL, NULL);
454 RunTest(); 451 RunTest();
455 452
456 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers 453 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers
457 454
458 // Now, check the results from the second provider, as they should not have 455 // Now, check the results from the second provider, as they should not have
459 // assisted query stats set. 456 // assisted query stats set.
460 for (size_t i = 0; i < kResultsPerProvider; ++i) { 457 for (size_t i = 0; i < kResultsPerProvider; ++i) {
461 EXPECT_TRUE( 458 EXPECT_TRUE(
462 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); 459 result_.match_at(i)->search_terms_args->assisted_query_stats.empty());
463 } 460 }
464 // The first provider has a test keyword, so AQS should be non-empty. 461 // The first provider has a test keyword, so AQS should be non-empty.
465 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) { 462 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) {
466 EXPECT_FALSE( 463 EXPECT_FALSE(
467 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); 464 result_.match_at(i)->search_terms_args->assisted_query_stats.empty());
468 } 465 }
469 } 466 }
470 467
471 TEST_F(AutocompleteProviderTest, RemoveDuplicates) { 468 TEST_F(AutocompleteProviderTest, RemoveDuplicates) {
472 ResetControllerWithTestProviders(true); 469 TestProvider* provider1 = NULL;
470 TestProvider* provider2 = NULL;
471 ResetControllerWithTestProviders(true, &provider1, &provider2);
473 RunTest(); 472 RunTest();
474 473
475 // Make sure all the first provider's results were eliminated by the second 474 // Make sure all the first provider's results were eliminated by the second
476 // provider's. 475 // provider's.
477 EXPECT_EQ(kResultsPerProvider, result_.size()); 476 EXPECT_EQ(kResultsPerProvider, result_.size());
478 for (AutocompleteResult::const_iterator i(result_.begin()); 477 for (AutocompleteResult::const_iterator i(result_.begin());
479 i != result_.end(); ++i) 478 i != result_.end(); ++i)
480 EXPECT_EQ(providers_[1], i->provider); 479 EXPECT_EQ(provider2, i->provider);
481 } 480 }
482 481
483 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) { 482 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {
484 ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); 483 ResetControllerWithKeywordAndSearchProviders();
485 RunExactKeymatchTest(true); 484 RunExactKeymatchTest(true);
486 RunExactKeymatchTest(false); 485 RunExactKeymatchTest(false);
487 } 486 }
488 487
489 // Test that redundant associated keywords are removed. 488 // Test that redundant associated keywords are removed.
490 TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) { 489 TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) {
491 ResetControllerWithKeywordProvider(); 490 ResetControllerWithKeywordProvider();
492 491
493 // Get the controller's internal members in the correct state. 492 // Get the controller's internal members in the correct state.
494 RunQuery(ASCIIToUTF16("fo")); 493 RunQuery(ASCIIToUTF16("fo"));
(...skipping 27 matching lines...) Expand all
522 { ASCIIToUTF16("bar.com"), string16(), true }, 521 { ASCIIToUTF16("bar.com"), string16(), true },
523 }; 522 };
524 523
525 SCOPED_TRACE("Duplicate url with multiple keywords"); 524 SCOPED_TRACE("Duplicate url with multiple keywords");
526 RunRedundantKeywordTest(multiple_keyword, 525 RunRedundantKeywordTest(multiple_keyword,
527 ARRAYSIZE_UNSAFE(multiple_keyword)); 526 ARRAYSIZE_UNSAFE(multiple_keyword));
528 } 527 }
529 } 528 }
530 529
531 TEST_F(AutocompleteProviderTest, UpdateAssistedQueryStats) { 530 TEST_F(AutocompleteProviderTest, UpdateAssistedQueryStats) {
532 ResetControllerWithTestProviders(false); 531 ResetControllerWithTestProviders(false, NULL, NULL);
533 532
534 { 533 {
535 AssistedQueryStatsTestData test_data[] = { 534 AssistedQueryStatsTestData test_data[] = {
536 // MSVC doesn't support zero-length arrays, so supply some dummy data. 535 // MSVC doesn't support zero-length arrays, so supply some dummy data.
537 { AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, "" } 536 { AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, "" }
538 }; 537 };
539 SCOPED_TRACE("No matches"); 538 SCOPED_TRACE("No matches");
540 // Note: We pass 0 here to ignore the dummy data above. 539 // Note: We pass 0 here to ignore the dummy data above.
541 RunAssistedQueryStatsTest(test_data, 0); 540 RunAssistedQueryStatsTest(test_data, 0);
542 } 541 }
(...skipping 14 matching lines...) Expand all
557 { AutocompleteMatch::NAVSUGGEST, "chrome.3.57j58j5l2j0l3j59" }, 556 { AutocompleteMatch::NAVSUGGEST, "chrome.3.57j58j5l2j0l3j59" },
558 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.4.57j58j5l2j0l3j59" }, 557 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.4.57j58j5l2j0l3j59" },
559 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.5.57j58j5l2j0l3j59" }, 558 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.5.57j58j5l2j0l3j59" },
560 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.6.57j58j5l2j0l3j59" }, 559 { AutocompleteMatch::SEARCH_SUGGEST, "chrome.6.57j58j5l2j0l3j59" },
561 { AutocompleteMatch::SEARCH_HISTORY, "chrome.7.57j58j5l2j0l3j59" }, 560 { AutocompleteMatch::SEARCH_HISTORY, "chrome.7.57j58j5l2j0l3j59" },
562 }; 561 };
563 SCOPED_TRACE("Multiple matches"); 562 SCOPED_TRACE("Multiple matches");
564 RunAssistedQueryStatsTest(test_data, ARRAYSIZE_UNSAFE(test_data)); 563 RunAssistedQueryStatsTest(test_data, ARRAYSIZE_UNSAFE(test_data));
565 } 564 }
566 } 565 }
567
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698