OLD | NEW |
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 "chrome/browser/autocomplete/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); | 146 keyword_url_ = AddSearchToHistory(keyword_t_url_, keyword_term_, 1); |
147 | 147 |
148 // Keywords are updated by the InMemoryHistoryBackend only after the message | 148 // Keywords are updated by the InMemoryHistoryBackend only after the message |
149 // has been processed on the history thread. Block until history processes all | 149 // has been processed on the history thread. Block until history processes all |
150 // requests to ensure the InMemoryDatabase is the state we expect it. | 150 // requests to ensure the InMemoryDatabase is the state we expect it. |
151 profile_.BlockUntilHistoryProcessesPendingRequests(); | 151 profile_.BlockUntilHistoryProcessesPendingRequests(); |
152 | 152 |
153 provider_ = new SearchProvider(this, &profile_); | 153 provider_ = new SearchProvider(this, &profile_); |
154 | 154 |
155 URLFetcher::set_factory(&test_factory_); | 155 URLFetcher::set_factory(&test_factory_); |
156 | |
157 // Prevent the Instant field trial from kicking in. | |
158 PrefService* service = profile_.GetPrefs(); | |
159 service->SetBoolean(prefs::kInstantEnabledOnce, true); | |
160 } | 156 } |
161 | 157 |
162 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { | 158 void SearchProviderTest::OnProviderUpdate(bool updated_matches) { |
163 if (quit_when_done_ && provider_->done()) { | 159 if (quit_when_done_ && provider_->done()) { |
164 quit_when_done_ = false; | 160 quit_when_done_ = false; |
165 message_loop_.Quit(); | 161 message_loop_.Quit(); |
166 } | 162 } |
167 } | 163 } |
168 | 164 |
169 void SearchProviderTest::RunTillProviderDone() { | 165 void SearchProviderTest::RunTillProviderDone() { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 | 616 |
621 // Verifies AutocompleteControllers sets descriptions for results correctly. | 617 // Verifies AutocompleteControllers sets descriptions for results correctly. |
622 TEST_F(SearchProviderTest, UpdateKeywordDescriptions) { | 618 TEST_F(SearchProviderTest, UpdateKeywordDescriptions) { |
623 // Add an entry that corresponds to a keyword search with 'term2'. | 619 // Add an entry that corresponds to a keyword search with 'term2'. |
624 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); | 620 AddSearchToHistory(keyword_t_url_, ASCIIToUTF16("term2"), 1); |
625 profile_.BlockUntilHistoryProcessesPendingRequests(); | 621 profile_.BlockUntilHistoryProcessesPendingRequests(); |
626 | 622 |
627 ACProviders providers; | 623 ACProviders providers; |
628 SearchProvider* provider = provider_.release(); | 624 SearchProvider* provider = provider_.release(); |
629 providers.push_back(provider); | 625 providers.push_back(provider); |
630 AutocompleteController controller(providers, &profile_); | 626 AutocompleteController controller(providers); |
631 controller.set_search_provider(provider); | 627 controller.set_search_provider(provider); |
632 provider->set_listener(&controller); | 628 provider->set_listener(&controller); |
633 controller.Start(ASCIIToUTF16("k t"), string16(), false, false, true, | 629 controller.Start(ASCIIToUTF16("k t"), string16(), false, false, true, |
634 AutocompleteInput::ALL_MATCHES); | 630 AutocompleteInput::ALL_MATCHES); |
635 const AutocompleteResult& result = controller.result(); | 631 const AutocompleteResult& result = controller.result(); |
636 | 632 |
637 // There should be two matches, one for the keyword one for what you typed. | 633 // There should be two matches, one for the keyword one for what you typed. |
638 ASSERT_EQ(2u, result.size()); | 634 ASSERT_EQ(2u, result.size()); |
639 | 635 |
640 EXPECT_TRUE(result.match_at(0).template_url != NULL); | 636 EXPECT_TRUE(result.match_at(0).template_url != NULL); |
641 EXPECT_TRUE(result.match_at(1).template_url != NULL); | 637 EXPECT_TRUE(result.match_at(1).template_url != NULL); |
642 EXPECT_NE(result.match_at(0).template_url, | 638 EXPECT_NE(result.match_at(0).template_url, |
643 result.match_at(1).template_url); | 639 result.match_at(1).template_url); |
644 | 640 |
645 EXPECT_FALSE(result.match_at(0).description.empty()); | 641 EXPECT_FALSE(result.match_at(0).description.empty()); |
646 EXPECT_FALSE(result.match_at(1).description.empty()); | 642 EXPECT_FALSE(result.match_at(1).description.empty()); |
647 EXPECT_NE(result.match_at(0).description, | 643 EXPECT_NE(result.match_at(0).description, |
648 result.match_at(1).description); | 644 result.match_at(1).description); |
649 } | 645 } |
OLD | NEW |