| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete.h" | 10 #include "chrome/browser/autocomplete/autocomplete.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_match.h" | 11 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 12 #include "chrome/browser/autocomplete/keyword_provider.h" | 12 #include "chrome/browser/autocomplete/keyword_provider.h" |
| 13 #include "chrome/browser/autocomplete/search_provider.h" | 13 #include "chrome/browser/autocomplete/search_provider.h" |
| 14 #include "chrome/browser/search_engines/template_url.h" | 14 #include "chrome/browser/search_engines/template_url.h" |
| 15 #include "chrome/browser/search_engines/template_url_service.h" | 15 #include "chrome/browser/search_engines/template_url_service.h" |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/test/testing_browser_process.h" | 18 #include "chrome/test/testing_browser_process.h" |
| 18 #include "chrome/test/testing_browser_process_test.h" | 19 #include "chrome/test/testing_browser_process_test.h" |
| 19 #include "chrome/test/testing_profile.h" | 20 #include "chrome/test/testing_profile.h" |
| 20 #include "content/common/notification_observer.h" | 21 #include "content/common/notification_observer.h" |
| 21 #include "content/common/notification_registrar.h" | 22 #include "content/common/notification_registrar.h" |
| 22 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 static std::ostream& operator<<(std::ostream& os, | 26 static std::ostream& operator<<(std::ostream& os, |
| 26 const AutocompleteResult::const_iterator& it) { | 27 const AutocompleteResult::const_iterator& it) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 void ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); | 116 void ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); |
| 116 void RunExactKeymatchTest(bool allow_exact_keyword_match); | 117 void RunExactKeymatchTest(bool allow_exact_keyword_match); |
| 117 | 118 |
| 118 // These providers are owned by the controller once it's created. | 119 // These providers are owned by the controller once it's created. |
| 119 ACProviders providers_; | 120 ACProviders providers_; |
| 120 | 121 |
| 121 AutocompleteResult result_; | 122 AutocompleteResult result_; |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 // NotificationObserver | 125 // NotificationObserver |
| 125 virtual void Observe(NotificationType type, | 126 virtual void Observe(int type, |
| 126 const NotificationSource& source, | 127 const NotificationSource& source, |
| 127 const NotificationDetails& details); | 128 const NotificationDetails& details); |
| 128 | 129 |
| 129 ScopedTestingBrowserProcess browser_process_; | 130 ScopedTestingBrowserProcess browser_process_; |
| 130 | 131 |
| 131 MessageLoopForUI message_loop_; | 132 MessageLoopForUI message_loop_; |
| 132 scoped_ptr<AutocompleteController> controller_; | 133 scoped_ptr<AutocompleteController> controller_; |
| 133 NotificationRegistrar registrar_; | 134 NotificationRegistrar registrar_; |
| 134 TestingProfile profile_; | 135 TestingProfile profile_; |
| 135 }; | 136 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 152 providers_.push_back(providerB); | 153 providers_.push_back(providerB); |
| 153 | 154 |
| 154 // Reset the controller to contain our new providers. | 155 // Reset the controller to contain our new providers. |
| 155 AutocompleteController* controller = new AutocompleteController(providers_); | 156 AutocompleteController* controller = new AutocompleteController(providers_); |
| 156 controller_.reset(controller); | 157 controller_.reset(controller); |
| 157 providerA->set_listener(controller); | 158 providerA->set_listener(controller); |
| 158 providerB->set_listener(controller); | 159 providerB->set_listener(controller); |
| 159 | 160 |
| 160 // The providers don't complete synchronously, so listen for "result updated" | 161 // The providers don't complete synchronously, so listen for "result updated" |
| 161 // notifications. | 162 // notifications. |
| 162 registrar_.Add(this, NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 163 registrar_.Add(this, |
| 164 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 163 NotificationService::AllSources()); | 165 NotificationService::AllSources()); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void AutocompleteProviderTest:: | 168 void AutocompleteProviderTest:: |
| 167 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { | 169 ResetControllerWithTestProvidersWithKeywordAndSearchProviders() { |
| 168 profile_.CreateTemplateURLService(); | 170 profile_.CreateTemplateURLService(); |
| 169 | 171 |
| 170 // Reset the default TemplateURL. | 172 // Reset the default TemplateURL. |
| 171 TemplateURL* default_t_url = new TemplateURL(); | 173 TemplateURL* default_t_url = new TemplateURL(); |
| 172 default_t_url->SetURL("http://defaultturl/{searchTerms}", 0, 0); | 174 default_t_url->SetURL("http://defaultturl/{searchTerms}", 0, 0); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 allow_exact_keyword_match, | 225 allow_exact_keyword_match, |
| 224 AutocompleteInput::SYNCHRONOUS_MATCHES); | 226 AutocompleteInput::SYNCHRONOUS_MATCHES); |
| 225 EXPECT_TRUE(controller_->done()); | 227 EXPECT_TRUE(controller_->done()); |
| 226 // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider | 228 // ResetControllerWithKeywordAndSearchProviders() adds the keyword provider |
| 227 // first, then the search provider. So if the default match is a keyword | 229 // first, then the search provider. So if the default match is a keyword |
| 228 // match, it will come from provider 0, otherwise from provider 1. | 230 // match, it will come from provider 0, otherwise from provider 1. |
| 229 EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1], | 231 EXPECT_EQ(providers_[allow_exact_keyword_match ? 0 : 1], |
| 230 controller_->result().default_match()->provider); | 232 controller_->result().default_match()->provider); |
| 231 } | 233 } |
| 232 | 234 |
| 233 void AutocompleteProviderTest::Observe(NotificationType type, | 235 void AutocompleteProviderTest::Observe(int type, |
| 234 const NotificationSource& source, | 236 const NotificationSource& source, |
| 235 const NotificationDetails& details) { | 237 const NotificationDetails& details) { |
| 236 if (controller_->done()) { | 238 if (controller_->done()) { |
| 237 result_.CopyFrom(controller_->result()); | 239 result_.CopyFrom(controller_->result()); |
| 238 MessageLoop::current()->Quit(); | 240 MessageLoop::current()->Quit(); |
| 239 } | 241 } |
| 240 } | 242 } |
| 241 | 243 |
| 242 // Tests that the default selection is set properly when updating results. | 244 // Tests that the default selection is set properly when updating results. |
| 243 TEST_F(AutocompleteProviderTest, Query) { | 245 TEST_F(AutocompleteProviderTest, Query) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " << | 471 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " << |
| 470 input_cases[i].input; | 472 input_cases[i].input; |
| 471 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " << | 473 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " << |
| 472 input_cases[i].input; | 474 input_cases[i].input; |
| 473 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " << | 475 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " << |
| 474 input_cases[i].input; | 476 input_cases[i].input; |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 | 479 |
| 478 } // namespace | 480 } // namespace |
| OLD | NEW |