OLD | NEW |
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/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void RunQuery(const string16 query); | 182 void RunQuery(const string16 query); |
183 | 183 |
184 void ResetControllerWithKeywordAndSearchProviders(); | 184 void ResetControllerWithKeywordAndSearchProviders(); |
185 void ResetControllerWithKeywordProvider(); | 185 void ResetControllerWithKeywordProvider(); |
186 void RunExactKeymatchTest(bool allow_exact_keyword_match); | 186 void RunExactKeymatchTest(bool allow_exact_keyword_match); |
187 | 187 |
188 AutocompleteResult result_; | 188 AutocompleteResult result_; |
189 scoped_ptr<AutocompleteController> controller_; | 189 scoped_ptr<AutocompleteController> controller_; |
190 | 190 |
191 private: | 191 private: |
192 // content::NotificationObserver | 192 // content::NotificationObserver: |
193 virtual void Observe(int type, | 193 virtual void Observe(int type, |
194 const content::NotificationSource& source, | 194 const content::NotificationSource& source, |
195 const content::NotificationDetails& details) OVERRIDE; | 195 const content::NotificationDetails& details) OVERRIDE; |
196 | 196 |
197 base::MessageLoopForUI message_loop_; | 197 base::MessageLoopForUI message_loop_; |
198 content::NotificationRegistrar registrar_; | 198 content::NotificationRegistrar registrar_; |
199 TestingProfile profile_; | 199 TestingProfile profile_; |
200 }; | 200 }; |
201 | 201 |
202 void AutocompleteProviderTest::RegisterTemplateURL( | 202 void AutocompleteProviderTest::RegisterTemplateURL( |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 428 |
429 // Tests that the default selection is set properly when updating results. | 429 // Tests that the default selection is set properly when updating results. |
430 TEST_F(AutocompleteProviderTest, Query) { | 430 TEST_F(AutocompleteProviderTest, Query) { |
431 TestProvider* provider1 = NULL; | 431 TestProvider* provider1 = NULL; |
432 TestProvider* provider2 = NULL; | 432 TestProvider* provider2 = NULL; |
433 ResetControllerWithTestProviders(false, &provider1, &provider2); | 433 ResetControllerWithTestProviders(false, &provider1, &provider2); |
434 RunTest(); | 434 RunTest(); |
435 | 435 |
436 // Make sure the default match gets set to the highest relevance match. The | 436 // Make sure the default match gets set to the highest relevance match. The |
437 // highest relevance matches should come from the second provider. | 437 // highest relevance matches should come from the second provider. |
438 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers | 438 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); |
439 ASSERT_NE(result_.end(), result_.default_match()); | 439 ASSERT_NE(result_.end(), result_.default_match()); |
440 EXPECT_EQ(provider2, result_.default_match()->provider); | 440 EXPECT_EQ(provider2, result_.default_match()->provider); |
441 } | 441 } |
442 | 442 |
443 // Tests assisted query stats. | 443 // Tests assisted query stats. |
444 TEST_F(AutocompleteProviderTest, AssistedQueryStats) { | 444 TEST_F(AutocompleteProviderTest, AssistedQueryStats) { |
445 ResetControllerWithTestProviders(false, NULL, NULL); | 445 ResetControllerWithTestProviders(false, NULL, NULL); |
446 RunTest(); | 446 RunTest(); |
447 | 447 |
448 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); // two providers | 448 ASSERT_EQ(kResultsPerProvider * 2, result_.size()); |
449 | 449 |
450 // Now, check the results from the second provider, as they should not have | 450 // Now, check the results from the second provider, as they should not have |
451 // assisted query stats set. | 451 // assisted query stats set. |
452 for (size_t i = 0; i < kResultsPerProvider; ++i) { | 452 for (size_t i = 0; i < kResultsPerProvider; ++i) { |
453 EXPECT_TRUE( | 453 EXPECT_TRUE( |
454 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); | 454 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); |
455 } | 455 } |
456 // The first provider has a test keyword, so AQS should be non-empty. | 456 // The first provider has a test keyword, so AQS should be non-empty. |
457 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) { | 457 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) { |
458 EXPECT_FALSE( | 458 EXPECT_FALSE( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path()); | 606 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0&", url.path()); |
607 | 607 |
608 // Test field trial triggered bit set. | 608 // Test field trial triggered bit set. |
609 controller_->search_provider_->field_trial_triggered_in_session_ = true; | 609 controller_->search_provider_->field_trial_triggered_in_session_ = true; |
610 EXPECT_TRUE( | 610 EXPECT_TRUE( |
611 controller_->search_provider_->field_trial_triggered_in_session()); | 611 controller_->search_provider_->field_trial_triggered_in_session()); |
612 url = controller_->GetDestinationURL(match, | 612 url = controller_->GetDestinationURL(match, |
613 base::TimeDelta::FromMilliseconds(2456)); | 613 base::TimeDelta::FromMilliseconds(2456)); |
614 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path()); | 614 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1&", url.path()); |
615 } | 615 } |
OLD | NEW |