Chromium Code Reviews| 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 "components/omnibox/browser/autocomplete_provider.h" | 5 #include "components/omnibox/browser/autocomplete_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | |
| 11 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | |
| 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | |
| 19 #include "chrome/browser/chrome_notification_types.h" | |
| 20 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 21 #include "chrome/test/base/testing_browser_process.h" | |
| 22 #include "chrome/test/base/testing_profile.h" | |
| 23 #include "components/metrics/proto/omnibox_event.pb.h" | 18 #include "components/metrics/proto/omnibox_event.pb.h" |
| 24 #include "components/omnibox/browser/autocomplete_controller.h" | 19 #include "components/omnibox/browser/autocomplete_controller.h" |
| 25 #include "components/omnibox/browser/autocomplete_input.h" | 20 #include "components/omnibox/browser/autocomplete_input.h" |
| 26 #include "components/omnibox/browser/autocomplete_match.h" | 21 #include "components/omnibox/browser/autocomplete_match.h" |
| 27 #include "components/omnibox/browser/autocomplete_provider_listener.h" | 22 #include "components/omnibox/browser/autocomplete_provider_listener.h" |
| 28 #include "components/omnibox/browser/keyword_provider.h" | 23 #include "components/omnibox/browser/keyword_provider.h" |
| 24 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | |
| 29 #include "components/omnibox/browser/search_provider.h" | 25 #include "components/omnibox/browser/search_provider.h" |
| 30 #include "components/search_engines/search_engines_switches.h" | 26 #include "components/search_engines/search_engines_switches.h" |
| 31 #include "components/search_engines/template_url.h" | 27 #include "components/search_engines/template_url.h" |
| 32 #include "components/search_engines/template_url_service.h" | 28 #include "components/search_engines/template_url_service.h" |
| 33 #include "content/public/browser/notification_observer.h" | 29 #include "components/search_engines/template_url_service_client.h" |
| 34 #include "content/public/browser/notification_registrar.h" | |
| 35 #include "content/public/browser/notification_source.h" | |
| 36 #include "content/public/test/test_browser_thread_bundle.h" | |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 31 |
| 39 static std::ostream& operator<<(std::ostream& os, | 32 static std::ostream& operator<<(std::ostream& os, |
| 40 const AutocompleteResult::const_iterator& it) { | 33 const AutocompleteResult::const_iterator& it) { |
| 41 return os << static_cast<const AutocompleteMatch*>(&(*it)); | 34 return os << static_cast<const AutocompleteMatch*>(&(*it)); |
| 42 } | 35 } |
| 43 | 36 |
| 44 namespace { | 37 namespace { |
| 38 | |
| 45 const size_t kResultsPerProvider = 3; | 39 const size_t kResultsPerProvider = 3; |
| 46 const char kTestTemplateURLKeyword[] = "t"; | 40 const char kTestTemplateURLKeyword[] = "t"; |
| 47 } | 41 |
| 42 class TestingSchemeClassifier : public AutocompleteSchemeClassifier { | |
| 43 public: | |
| 44 TestingSchemeClassifier() {} | |
| 45 | |
| 46 metrics::OmniboxInputType::Type GetInputTypeForScheme( | |
| 47 const std::string& scheme) const override { | |
| 48 return net::URLRequest::IsHandledProtocol(scheme) | |
| 49 ? metrics::OmniboxInputType::URL | |
| 50 : metrics::OmniboxInputType::INVALID; | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 DISALLOW_COPY_AND_ASSIGN(TestingSchemeClassifier); | |
| 55 }; | |
| 56 | |
| 57 // AutocompleteProviderClient implementation that calls the specified closure | |
| 58 // when the result is ready. | |
| 59 class AutocompleteProviderClientWithClosure | |
| 60 : public MockAutocompleteProviderClient { | |
| 61 public: | |
| 62 AutocompleteProviderClientWithClosure() {} | |
| 63 | |
| 64 void set_closure(const base::Closure& closure) { closure_ = closure; } | |
| 65 | |
| 66 private: | |
| 67 void OnAutocompleteControllerResultReady( | |
| 68 AutocompleteController* controller) override { | |
| 69 if (closure_.is_null()) { | |
|
Peter Kasting
2015/11/20 19:52:18
Nit: Can combine these conditionals:
if (cont
Abhishek
2015/11/21 12:11:20
Done.
| |
| 70 return; | |
| 71 } | |
| 72 | |
| 73 if (controller->done()) { | |
| 74 closure_.Run(); | |
| 75 base::MessageLoop::current()->QuitWhenIdle(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 base::Closure closure_; | |
| 80 | |
| 81 DISALLOW_COPY_AND_ASSIGN(AutocompleteProviderClientWithClosure); | |
| 82 }; | |
| 83 | |
| 84 } // namespace | |
| 48 | 85 |
| 49 // Autocomplete provider that provides known results. Note that this is | 86 // Autocomplete provider that provides known results. Note that this is |
| 50 // refcounted so that it can also be a task on the message loop. | 87 // refcounted so that it can also be a task on the message loop. |
| 51 class TestProvider : public AutocompleteProvider { | 88 class TestProvider : public AutocompleteProvider { |
| 52 public: | 89 public: |
| 53 TestProvider(int relevance, const base::string16& prefix, | 90 TestProvider(int relevance, |
| 54 Profile* profile, | 91 const base::string16& prefix, |
| 55 const base::string16 match_keyword) | 92 const base::string16 match_keyword, |
| 93 AutocompleteProviderClient* client) | |
| 56 : AutocompleteProvider(AutocompleteProvider::TYPE_SEARCH), | 94 : AutocompleteProvider(AutocompleteProvider::TYPE_SEARCH), |
| 57 listener_(NULL), | 95 listener_(nullptr), |
| 58 profile_(profile), | |
| 59 relevance_(relevance), | 96 relevance_(relevance), |
| 60 prefix_(prefix), | 97 prefix_(prefix), |
| 61 match_keyword_(match_keyword) { | 98 match_keyword_(match_keyword), |
| 62 } | 99 client_(client) {} |
| 63 | 100 |
| 64 void Start(const AutocompleteInput& input, bool minimal_changes) override; | 101 void Start(const AutocompleteInput& input, bool minimal_changes) override; |
| 65 | 102 |
| 66 void set_listener(AutocompleteProviderListener* listener) { | 103 void set_listener(AutocompleteProviderListener* listener) { |
| 67 listener_ = listener; | 104 listener_ = listener; |
| 68 } | 105 } |
| 69 | 106 |
| 70 private: | 107 private: |
| 71 ~TestProvider() override {} | 108 ~TestProvider() override {} |
| 72 | 109 |
| 73 void Run(); | 110 void Run(); |
| 74 | 111 |
| 75 void AddResults(int start_at, int num); | 112 void AddResults(int start_at, int num); |
| 76 void AddResultsWithSearchTermsArgs( | 113 void AddResultsWithSearchTermsArgs( |
| 77 int start_at, | 114 int start_at, |
| 78 int num, | 115 int num, |
| 79 AutocompleteMatch::Type type, | 116 AutocompleteMatch::Type type, |
| 80 const TemplateURLRef::SearchTermsArgs& search_terms_args); | 117 const TemplateURLRef::SearchTermsArgs& search_terms_args); |
| 81 | 118 |
| 82 AutocompleteProviderListener* listener_; | 119 AutocompleteProviderListener* listener_; |
| 83 Profile* profile_; | |
| 84 int relevance_; | 120 int relevance_; |
| 85 const base::string16 prefix_; | 121 const base::string16 prefix_; |
| 86 const base::string16 match_keyword_; | 122 const base::string16 match_keyword_; |
| 123 AutocompleteProviderClient* client_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(TestProvider); | |
| 87 }; | 126 }; |
| 88 | 127 |
| 89 void TestProvider::Start(const AutocompleteInput& input, bool minimal_changes) { | 128 void TestProvider::Start(const AutocompleteInput& input, bool minimal_changes) { |
| 90 if (minimal_changes) | 129 if (minimal_changes) |
| 91 return; | 130 return; |
| 92 | 131 |
| 93 matches_.clear(); | 132 matches_.clear(); |
| 94 | 133 |
| 95 if (input.from_omnibox_focus()) | 134 if (input.from_omnibox_focus()) |
| 96 return; | 135 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 108 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("query"))); | 147 TemplateURLRef::SearchTermsArgs(base::ASCIIToUTF16("query"))); |
| 109 | 148 |
| 110 if (input.want_asynchronous_matches()) { | 149 if (input.want_asynchronous_matches()) { |
| 111 done_ = false; | 150 done_ = false; |
| 112 base::ThreadTaskRunnerHandle::Get()->PostTask( | 151 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 113 FROM_HERE, base::Bind(&TestProvider::Run, this)); | 152 FROM_HERE, base::Bind(&TestProvider::Run, this)); |
| 114 } | 153 } |
| 115 } | 154 } |
| 116 | 155 |
| 117 void TestProvider::Run() { | 156 void TestProvider::Run() { |
| 118 DCHECK_GT(kResultsPerProvider, 0U); | 157 ASSERT_GT(kResultsPerProvider, 0U); |
|
Peter Kasting
2015/11/20 19:52:18
Don't bother checking this; this is a hardcoded co
Abhishek
2015/11/21 12:11:20
I believe original author intention was just to do
Peter Kasting
2015/11/21 21:08:42
I'm saying, the double-check isn't necessary. Jus
Abhishek
2015/11/23 15:22:07
Sorry for the confusion here!
Done.
| |
| 119 AddResults(1, kResultsPerProvider); | 158 AddResults(1, kResultsPerProvider); |
| 120 done_ = true; | 159 done_ = true; |
| 121 DCHECK(listener_); | 160 DCHECK(listener_); |
| 122 listener_->OnProviderUpdate(true); | 161 listener_->OnProviderUpdate(true); |
| 123 } | 162 } |
| 124 | 163 |
| 125 void TestProvider::AddResults(int start_at, int num) { | 164 void TestProvider::AddResults(int start_at, int num) { |
| 126 AddResultsWithSearchTermsArgs(start_at, | 165 AddResultsWithSearchTermsArgs( |
| 127 num, | 166 start_at, num, AutocompleteMatchType::URL_WHAT_YOU_TYPED, |
| 128 AutocompleteMatchType::URL_WHAT_YOU_TYPED, | 167 TemplateURLRef::SearchTermsArgs(base::string16())); |
| 129 TemplateURLRef::SearchTermsArgs( | |
| 130 base::string16())); | |
| 131 } | 168 } |
| 132 | 169 |
| 133 void TestProvider::AddResultsWithSearchTermsArgs( | 170 void TestProvider::AddResultsWithSearchTermsArgs( |
| 134 int start_at, | 171 int start_at, |
| 135 int num, | 172 int num, |
| 136 AutocompleteMatch::Type type, | 173 AutocompleteMatch::Type type, |
| 137 const TemplateURLRef::SearchTermsArgs& search_terms_args) { | 174 const TemplateURLRef::SearchTermsArgs& search_terms_args) { |
| 138 for (int i = start_at; i < num; i++) { | 175 for (int i = start_at; i < num; i++) { |
| 139 AutocompleteMatch match(this, relevance_ - i, false, type); | 176 AutocompleteMatch match(this, relevance_ - i, false, type); |
| 140 | 177 |
| 141 match.fill_into_edit = prefix_ + base::UTF8ToUTF16(base::IntToString(i)); | 178 match.fill_into_edit = prefix_ + base::UTF8ToUTF16(base::IntToString(i)); |
| 142 match.destination_url = GURL(base::UTF16ToUTF8(match.fill_into_edit)); | 179 match.destination_url = GURL(base::UTF16ToUTF8(match.fill_into_edit)); |
| 143 match.allowed_to_be_default_match = true; | 180 match.allowed_to_be_default_match = true; |
| 144 | 181 |
| 145 match.contents = match.fill_into_edit; | 182 match.contents = match.fill_into_edit; |
| 146 match.contents_class.push_back( | 183 match.contents_class.push_back( |
| 147 ACMatchClassification(0, ACMatchClassification::NONE)); | 184 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 148 match.description = match.fill_into_edit; | 185 match.description = match.fill_into_edit; |
| 149 match.description_class.push_back( | 186 match.description_class.push_back( |
| 150 ACMatchClassification(0, ACMatchClassification::NONE)); | 187 ACMatchClassification(0, ACMatchClassification::NONE)); |
| 151 match.search_terms_args.reset( | 188 match.search_terms_args.reset( |
| 152 new TemplateURLRef::SearchTermsArgs(search_terms_args)); | 189 new TemplateURLRef::SearchTermsArgs(search_terms_args)); |
| 153 if (!match_keyword_.empty()) { | 190 if (!match_keyword_.empty()) { |
| 154 match.keyword = match_keyword_; | 191 match.keyword = match_keyword_; |
| 155 TemplateURLService* service = | 192 TemplateURLService* service = client_->GetTemplateURLService(); |
| 156 TemplateURLServiceFactory::GetForProfile(profile_); | 193 ASSERT_TRUE(match.GetTemplateURL(service, false) != nullptr); |
|
Peter Kasting
2015/11/20 19:52:18
Nit: I believe with nullptr you can now do ASSERT_
Abhishek
2015/11/21 12:11:20
Done.
| |
| 157 ASSERT_TRUE(match.GetTemplateURL(service, false) != NULL); | |
| 158 } | 194 } |
| 159 | 195 |
| 160 matches_.push_back(match); | 196 matches_.push_back(match); |
| 161 } | 197 } |
| 162 } | 198 } |
| 163 | 199 |
| 164 class AutocompleteProviderTest : public testing::Test, | 200 class AutocompleteProviderTest : public testing::Test { |
| 165 public content::NotificationObserver { | 201 public: |
| 202 AutocompleteProviderTest(); | |
| 203 ~AutocompleteProviderTest() override {}; | |
| 204 | |
| 166 protected: | 205 protected: |
| 206 void TearDown() override; | |
|
Peter Kasting
2015/11/20 19:52:18
Nit: Functions go below member type definitions.
Abhishek
2015/11/21 12:11:20
I've removed it. Because we can use destructor wit
| |
| 207 | |
| 167 struct KeywordTestData { | 208 struct KeywordTestData { |
| 168 const base::string16 fill_into_edit; | 209 const base::string16 fill_into_edit; |
| 169 const base::string16 keyword; | 210 const base::string16 keyword; |
| 170 const base::string16 expected_associated_keyword; | 211 const base::string16 expected_associated_keyword; |
| 171 }; | 212 }; |
| 172 | 213 |
| 173 struct AssistedQueryStatsTestData { | 214 struct AssistedQueryStatsTestData { |
| 174 const AutocompleteMatch::Type match_type; | 215 const AutocompleteMatch::Type match_type; |
| 175 const std::string expected_aqs; | 216 const std::string expected_aqs; |
| 176 }; | 217 }; |
| 177 | 218 |
| 178 protected: | 219 // Registers a test TemplateURL under the given keyword. |
| 179 // Registers a test TemplateURL under the given keyword. | |
| 180 void RegisterTemplateURL(const base::string16 keyword, | 220 void RegisterTemplateURL(const base::string16 keyword, |
| 181 const std::string& template_url); | 221 const std::string& template_url); |
| 182 | 222 |
| 183 // Resets |controller_| with two TestProviders. |provider1_ptr| and | 223 // Resets |controller_| with two TestProviders. |provider1_ptr| and |
| 184 // |provider2_ptr| are updated to point to the new providers if non-NULL. | 224 // |provider2_ptr| are updated to point to the new providers if non-NULL. |
| 185 void ResetControllerWithTestProviders(bool same_destinations, | 225 void ResetControllerWithTestProviders(bool same_destinations, |
| 186 TestProvider** provider1_ptr, | 226 TestProvider** provider1_ptr, |
| 187 TestProvider** provider2_ptr); | 227 TestProvider** provider2_ptr); |
| 188 | 228 |
| 189 // Runs a query on the input "a", and makes sure both providers' input is | 229 // Runs a query on the input "a", and makes sure both providers' input is |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 return controller_->search_provider_->field_trial_triggered_in_session(); | 262 return controller_->search_provider_->field_trial_triggered_in_session(); |
| 223 } | 263 } |
| 224 void set_current_page_classification( | 264 void set_current_page_classification( |
| 225 metrics::OmniboxEventProto::PageClassification classification) { | 265 metrics::OmniboxEventProto::PageClassification classification) { |
| 226 controller_->input_.current_page_classification_ = classification; | 266 controller_->input_.current_page_classification_ = classification; |
| 227 } | 267 } |
| 228 | 268 |
| 229 AutocompleteResult result_; | 269 AutocompleteResult result_; |
| 230 | 270 |
| 231 private: | 271 private: |
| 232 // content::NotificationObserver: | 272 // Reset controller with provided AutocompleteProvider::Type |type| |
|
Peter Kasting
2015/11/20 19:52:18
Nit: Function comments should be declarative (Rese
Abhishek
2015/11/21 12:11:20
Done.
| |
| 233 void Observe(int type, | 273 void ResetControllerWithType(int type); |
| 234 const content::NotificationSource& source, | |
| 235 const content::NotificationDetails& details) override; | |
| 236 | 274 |
| 237 content::TestBrowserThreadBundle thread_bundle_; | 275 base::MessageLoop message_loop_; |
| 238 content::NotificationRegistrar registrar_; | |
| 239 TestingProfile profile_; | |
| 240 scoped_ptr<AutocompleteController> controller_; | 276 scoped_ptr<AutocompleteController> controller_; |
| 277 // Owned by |controller_|. | |
| 278 AutocompleteProviderClientWithClosure* client_; | |
| 279 // Used to ensure that |client_| ownership has been passed to |controller_| | |
| 280 // exactly once. | |
| 281 bool client_owned_; | |
| 282 | |
| 283 DISALLOW_COPY_AND_ASSIGN(AutocompleteProviderTest); | |
| 241 }; | 284 }; |
| 242 | 285 |
| 286 AutocompleteProviderTest::AutocompleteProviderTest() | |
| 287 : client_(new AutocompleteProviderClientWithClosure()), | |
| 288 client_owned_(false) { | |
| 289 scoped_ptr<TemplateURLService> template_url_service( | |
| 290 new TemplateURLService(nullptr, 0)); | |
| 291 client_->set_template_url_service(template_url_service.Pass()); | |
| 292 } | |
| 293 | |
| 294 void AutocompleteProviderTest::TearDown() { | |
| 295 ASSERT_TRUE(client_owned_); | |
| 296 } | |
| 297 | |
| 243 void AutocompleteProviderTest::RegisterTemplateURL( | 298 void AutocompleteProviderTest::RegisterTemplateURL( |
| 244 const base::string16 keyword, | 299 const base::string16 keyword, |
| 245 const std::string& template_url) { | 300 const std::string& template_url) { |
| 246 if (TemplateURLServiceFactory::GetForProfile(&profile_) == NULL) { | |
| 247 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 248 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | |
| 249 } | |
| 250 TemplateURLData data; | 301 TemplateURLData data; |
| 251 data.SetURL(template_url); | 302 data.SetURL(template_url); |
| 252 data.SetShortName(keyword); | 303 data.SetShortName(keyword); |
| 253 data.SetKeyword(keyword); | 304 data.SetKeyword(keyword); |
| 254 TemplateURL* default_t_url = new TemplateURL(data); | 305 TemplateURL* default_t_url = new TemplateURL(data); |
| 255 TemplateURLService* turl_model = | 306 TemplateURLService* turl_model = client_->GetTemplateURLService(); |
| 256 TemplateURLServiceFactory::GetForProfile(&profile_); | |
| 257 turl_model->Add(default_t_url); | 307 turl_model->Add(default_t_url); |
| 258 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 308 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
| 259 turl_model->Load(); | 309 turl_model->Load(); |
| 260 TemplateURLID default_provider_id = default_t_url->id(); | 310 TemplateURLID default_provider_id = default_t_url->id(); |
| 261 ASSERT_NE(0, default_provider_id); | 311 ASSERT_NE(0, default_provider_id); |
| 262 } | 312 } |
| 263 | 313 |
| 264 void AutocompleteProviderTest::ResetControllerWithTestProviders( | 314 void AutocompleteProviderTest::ResetControllerWithTestProviders( |
| 265 bool same_destinations, | 315 bool same_destinations, |
| 266 TestProvider** provider1_ptr, | 316 TestProvider** provider1_ptr, |
| 267 TestProvider** provider2_ptr) { | 317 TestProvider** provider2_ptr) { |
| 268 // TODO: Move it outside this method, after refactoring the existing | 318 // TODO: Move it outside this method, after refactoring the existing |
| 269 // unit tests. Specifically: | 319 // unit tests. Specifically: |
| 270 // (1) Make sure that AutocompleteMatch.keyword is set iff there is | 320 // (1) Make sure that AutocompleteMatch.keyword is set iff there is |
| 271 // a corresponding call to RegisterTemplateURL; otherwise the | 321 // a corresponding call to RegisterTemplateURL; otherwise the |
| 272 // controller flow will crash; this practically means that | 322 // controller flow will crash; this practically means that |
| 273 // RunTests/ResetControllerXXX/RegisterTemplateURL should | 323 // RunTests/ResetControllerXXX/RegisterTemplateURL should |
| 274 // be coordinated with each other. | 324 // be coordinated with each other. |
| 275 // (2) Inject test arguments rather than rely on the hardcoded values, e.g. | 325 // (2) Inject test arguments rather than rely on the hardcoded values, e.g. |
| 276 // don't rely on kResultsPerProvided and default relevance ordering | 326 // don't rely on kResultsPerProvided and default relevance ordering |
| 277 // (B > A). | 327 // (B > A). |
| 278 RegisterTemplateURL(base::ASCIIToUTF16(kTestTemplateURLKeyword), | 328 RegisterTemplateURL(base::ASCIIToUTF16(kTestTemplateURLKeyword), |
| 279 "http://aqs/{searchTerms}/{google:assistedQueryStats}"); | 329 "http://aqs/{searchTerms}/{google:assistedQueryStats}"); |
| 280 | 330 |
| 281 AutocompleteController::Providers providers; | 331 AutocompleteController::Providers providers; |
| 282 | 332 |
| 283 // Construct two new providers, with either the same or different prefixes. | 333 // Construct two new providers, with either the same or different prefixes. |
| 284 TestProvider* provider1 = new TestProvider( | 334 TestProvider* provider1 = |
| 285 kResultsPerProvider, | 335 new TestProvider(kResultsPerProvider, base::ASCIIToUTF16("http://a"), |
| 286 base::ASCIIToUTF16("http://a"), | 336 base::ASCIIToUTF16(kTestTemplateURLKeyword), client_); |
| 287 &profile_, | |
| 288 base::ASCIIToUTF16(kTestTemplateURLKeyword)); | |
| 289 providers.push_back(provider1); | 337 providers.push_back(provider1); |
| 290 | 338 |
| 291 TestProvider* provider2 = new TestProvider( | 339 TestProvider* provider2 = new TestProvider( |
| 292 kResultsPerProvider * 2, | 340 kResultsPerProvider * 2, |
| 293 same_destinations ? base::ASCIIToUTF16("http://a") | 341 base::ASCIIToUTF16(same_destinations ? "http://a" : "http://b"), |
| 294 : base::ASCIIToUTF16("http://b"), | 342 base::string16(), client_); |
| 295 &profile_, | |
| 296 base::string16()); | |
| 297 providers.push_back(provider2); | 343 providers.push_back(provider2); |
| 298 | 344 |
| 299 // Reset the controller to contain our new providers. | 345 // Reset the controller to contain our new providers. |
| 300 controller_.reset(new AutocompleteController( | 346 ResetControllerWithType(0); |
| 301 | 347 |
| 302 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL, | |
| 303 0)); | |
| 304 // We're going to swap the providers vector, but the old vector should be | 348 // We're going to swap the providers vector, but the old vector should be |
| 305 // empty so no elements need to be freed at this point. | 349 // empty so no elements need to be freed at this point. |
| 306 EXPECT_TRUE(controller_->providers_.empty()); | 350 EXPECT_TRUE(controller_->providers_.empty()); |
| 307 controller_->providers_.swap(providers); | 351 controller_->providers_.swap(providers); |
| 308 provider1->set_listener(controller_.get()); | 352 provider1->set_listener(controller_.get()); |
| 309 provider2->set_listener(controller_.get()); | 353 provider2->set_listener(controller_.get()); |
| 310 | 354 |
| 311 // The providers don't complete synchronously, so listen for "result updated" | 355 client_->set_closure(base::Bind(&AutocompleteProviderTest::CopyResults, |
| 312 // notifications. | 356 base::Unretained(this))); |
| 313 registrar_.Add(this, | |
| 314 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | |
| 315 content::Source<AutocompleteController>(controller_.get())); | |
| 316 | 357 |
| 317 if (provider1_ptr) | 358 if (provider1_ptr) |
| 318 *provider1_ptr = provider1; | 359 *provider1_ptr = provider1; |
| 319 if (provider2_ptr) | 360 if (provider2_ptr) |
| 320 *provider2_ptr = provider2; | 361 *provider2_ptr = provider2; |
| 321 } | 362 } |
| 322 | 363 |
| 323 void AutocompleteProviderTest:: | 364 void AutocompleteProviderTest::ResetControllerWithKeywordAndSearchProviders() { |
| 324 ResetControllerWithKeywordAndSearchProviders() { | |
| 325 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | |
| 326 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | |
| 327 | |
| 328 // Reset the default TemplateURL. | 365 // Reset the default TemplateURL. |
| 329 TemplateURLData data; | 366 TemplateURLData data; |
| 330 data.SetShortName(base::ASCIIToUTF16("default")); | 367 data.SetShortName(base::ASCIIToUTF16("default")); |
| 331 data.SetKeyword(base::ASCIIToUTF16("default")); | 368 data.SetKeyword(base::ASCIIToUTF16("default")); |
| 332 data.SetURL("http://defaultturl/{searchTerms}"); | 369 data.SetURL("http://defaultturl/{searchTerms}"); |
| 333 TemplateURL* default_t_url = new TemplateURL(data); | 370 TemplateURL* default_t_url = new TemplateURL(data); |
| 334 TemplateURLService* turl_model = | 371 TemplateURLService* turl_model = client_->GetTemplateURLService(); |
| 335 TemplateURLServiceFactory::GetForProfile(&profile_); | |
| 336 turl_model->Add(default_t_url); | 372 turl_model->Add(default_t_url); |
| 337 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); | 373 turl_model->SetUserSelectedDefaultSearchProvider(default_t_url); |
| 338 TemplateURLID default_provider_id = default_t_url->id(); | 374 TemplateURLID default_provider_id = default_t_url->id(); |
| 339 ASSERT_NE(0, default_provider_id); | 375 ASSERT_NE(0, default_provider_id); |
| 340 | 376 |
| 341 // Create another TemplateURL for KeywordProvider. | 377 // Create another TemplateURL for KeywordProvider. |
| 342 TemplateURLData data2; | 378 TemplateURLData data2; |
| 343 data2.SetShortName(base::ASCIIToUTF16("k")); | 379 data2.SetShortName(base::ASCIIToUTF16("k")); |
| 344 data2.SetKeyword(base::ASCIIToUTF16("k")); | 380 data2.SetKeyword(base::ASCIIToUTF16("k")); |
| 345 data2.SetURL("http://keyword/{searchTerms}"); | 381 data2.SetURL("http://keyword/{searchTerms}"); |
| 346 TemplateURL* keyword_t_url = new TemplateURL(data2); | 382 TemplateURL* keyword_t_url = new TemplateURL(data2); |
| 347 turl_model->Add(keyword_t_url); | 383 turl_model->Add(keyword_t_url); |
| 348 ASSERT_NE(0, keyword_t_url->id()); | 384 ASSERT_NE(0, keyword_t_url->id()); |
| 349 | 385 |
| 350 controller_.reset(new AutocompleteController( | 386 ResetControllerWithType(AutocompleteProvider::TYPE_KEYWORD | |
| 351 | 387 AutocompleteProvider::TYPE_SEARCH); |
| 352 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL, | |
| 353 AutocompleteProvider::TYPE_KEYWORD | AutocompleteProvider::TYPE_SEARCH)); | |
| 354 } | 388 } |
| 355 | 389 |
| 356 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { | 390 void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { |
| 357 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 391 TemplateURLService* turl_model = client_->GetTemplateURLService(); |
| 358 &profile_, &TemplateURLServiceFactory::BuildInstanceFor); | |
| 359 | |
| 360 TemplateURLService* turl_model = | |
| 361 TemplateURLServiceFactory::GetForProfile(&profile_); | |
| 362 | 392 |
| 363 // Create a TemplateURL for KeywordProvider. | 393 // Create a TemplateURL for KeywordProvider. |
| 364 TemplateURLData data; | 394 TemplateURLData data; |
| 365 data.SetShortName(base::ASCIIToUTF16("foo.com")); | 395 data.SetShortName(base::ASCIIToUTF16("foo.com")); |
| 366 data.SetKeyword(base::ASCIIToUTF16("foo.com")); | 396 data.SetKeyword(base::ASCIIToUTF16("foo.com")); |
| 367 data.SetURL("http://foo.com/{searchTerms}"); | 397 data.SetURL("http://foo.com/{searchTerms}"); |
| 368 TemplateURL* keyword_t_url = new TemplateURL(data); | 398 TemplateURL* keyword_t_url = new TemplateURL(data); |
| 369 turl_model->Add(keyword_t_url); | 399 turl_model->Add(keyword_t_url); |
| 370 ASSERT_NE(0, keyword_t_url->id()); | 400 ASSERT_NE(0, keyword_t_url->id()); |
| 371 | 401 |
| 372 // Make a TemplateURL for KeywordProvider that a shorter version of the | 402 // Make a TemplateURL for KeywordProvider that a shorter version of the |
| 373 // first. | 403 // first. |
| 374 data.SetShortName(base::ASCIIToUTF16("f")); | 404 data.SetShortName(base::ASCIIToUTF16("f")); |
| 375 data.SetKeyword(base::ASCIIToUTF16("f")); | 405 data.SetKeyword(base::ASCIIToUTF16("f")); |
| 376 data.SetURL("http://f.com/{searchTerms}"); | 406 data.SetURL("http://f.com/{searchTerms}"); |
| 377 keyword_t_url = new TemplateURL(data); | 407 keyword_t_url = new TemplateURL(data); |
| 378 turl_model->Add(keyword_t_url); | 408 turl_model->Add(keyword_t_url); |
| 379 ASSERT_NE(0, keyword_t_url->id()); | 409 ASSERT_NE(0, keyword_t_url->id()); |
| 380 | 410 |
| 381 // Create another TemplateURL for KeywordProvider. | 411 // Create another TemplateURL for KeywordProvider. |
| 382 data.SetShortName(base::ASCIIToUTF16("bar.com")); | 412 data.SetShortName(base::ASCIIToUTF16("bar.com")); |
| 383 data.SetKeyword(base::ASCIIToUTF16("bar.com")); | 413 data.SetKeyword(base::ASCIIToUTF16("bar.com")); |
| 384 data.SetURL("http://bar.com/{searchTerms}"); | 414 data.SetURL("http://bar.com/{searchTerms}"); |
| 385 keyword_t_url = new TemplateURL(data); | 415 keyword_t_url = new TemplateURL(data); |
| 386 turl_model->Add(keyword_t_url); | 416 turl_model->Add(keyword_t_url); |
| 387 ASSERT_NE(0, keyword_t_url->id()); | 417 ASSERT_NE(0, keyword_t_url->id()); |
| 388 | 418 |
| 389 controller_.reset(new AutocompleteController( | 419 ResetControllerWithType(AutocompleteProvider::TYPE_KEYWORD); |
| 390 make_scoped_ptr(new ChromeAutocompleteProviderClient(&profile_)), NULL, | 420 } |
| 391 AutocompleteProvider::TYPE_KEYWORD)); | 421 |
| 422 void AutocompleteProviderTest::ResetControllerWithType(int type) { | |
| 423 ASSERT_FALSE(client_owned_); | |
|
Peter Kasting
2015/11/20 19:52:18
If the test won't otherwise crash if this fails, t
Abhishek
2015/11/21 12:11:20
Done.
| |
| 424 controller_.reset(new AutocompleteController(make_scoped_ptr(client_), | |
| 425 nullptr, type)); | |
| 426 client_owned_ = true; | |
| 392 } | 427 } |
| 393 | 428 |
| 394 void AutocompleteProviderTest::RunTest() { | 429 void AutocompleteProviderTest::RunTest() { |
| 395 RunQuery(base::ASCIIToUTF16("a")); | 430 RunQuery(base::ASCIIToUTF16("a")); |
| 396 } | 431 } |
| 397 | 432 |
| 398 void AutocompleteProviderTest::RunKeywordTest(const base::string16& input, | 433 void AutocompleteProviderTest::RunKeywordTest(const base::string16& input, |
| 399 const KeywordTestData* match_data, | 434 const KeywordTestData* match_data, |
| 400 size_t size) { | 435 size_t size) { |
| 401 ACMatches matches; | 436 ACMatches matches; |
| 402 for (size_t i = 0; i < size; ++i) { | 437 for (size_t i = 0; i < size; ++i) { |
| 403 AutocompleteMatch match; | 438 AutocompleteMatch match; |
| 404 match.relevance = 1000; // Arbitrary non-zero value. | 439 match.relevance = 1000; // Arbitrary non-zero value. |
| 405 match.allowed_to_be_default_match = true; | 440 match.allowed_to_be_default_match = true; |
| 406 match.fill_into_edit = match_data[i].fill_into_edit; | 441 match.fill_into_edit = match_data[i].fill_into_edit; |
| 407 match.transition = ui::PAGE_TRANSITION_KEYWORD; | 442 match.transition = ui::PAGE_TRANSITION_KEYWORD; |
| 408 match.keyword = match_data[i].keyword; | 443 match.keyword = match_data[i].keyword; |
| 409 matches.push_back(match); | 444 matches.push_back(match); |
| 410 } | 445 } |
| 411 | 446 |
| 412 controller_->input_ = AutocompleteInput( | 447 controller_->input_ = AutocompleteInput( |
| 413 input, base::string16::npos, std::string(), GURL(), | 448 input, base::string16::npos, std::string(), GURL(), |
| 414 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 449 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
| 415 false, true, true, true, false, | 450 false, true, true, true, false, TestingSchemeClassifier()); |
| 416 ChromeAutocompleteSchemeClassifier(&profile_)); | |
| 417 AutocompleteResult result; | 451 AutocompleteResult result; |
| 418 result.AppendMatches(controller_->input_, matches); | 452 result.AppendMatches(controller_->input_, matches); |
| 419 controller_->UpdateAssociatedKeywords(&result); | 453 controller_->UpdateAssociatedKeywords(&result); |
| 420 | |
| 421 for (size_t j = 0; j < result.size(); ++j) { | 454 for (size_t j = 0; j < result.size(); ++j) { |
| 422 EXPECT_EQ(match_data[j].expected_associated_keyword, | 455 EXPECT_EQ(match_data[j].expected_associated_keyword, |
| 423 result.match_at(j)->associated_keyword.get() ? | 456 result.match_at(j)->associated_keyword.get() |
| 424 result.match_at(j)->associated_keyword->keyword : | 457 ? result.match_at(j)->associated_keyword->keyword |
| 425 base::string16()); | 458 : base::string16()); |
| 426 } | 459 } |
| 427 } | 460 } |
| 428 | 461 |
| 429 void AutocompleteProviderTest::RunAssistedQueryStatsTest( | 462 void AutocompleteProviderTest::RunAssistedQueryStatsTest( |
| 430 const AssistedQueryStatsTestData* aqs_test_data, | 463 const AssistedQueryStatsTestData* aqs_test_data, |
| 431 size_t size) { | 464 size_t size) { |
| 432 // Prepare input. | 465 // Prepare input. |
| 433 const size_t kMaxRelevance = 1000; | 466 const size_t kMaxRelevance = 1000; |
| 434 ACMatches matches; | 467 ACMatches matches; |
| 435 for (size_t i = 0; i < size; ++i) { | 468 for (size_t i = 0; i < size; ++i) { |
| 436 AutocompleteMatch match(NULL, kMaxRelevance - i, false, | 469 AutocompleteMatch match(nullptr, kMaxRelevance - i, false, |
| 437 aqs_test_data[i].match_type); | 470 aqs_test_data[i].match_type); |
| 438 match.allowed_to_be_default_match = true; | 471 match.allowed_to_be_default_match = true; |
| 439 match.keyword = base::ASCIIToUTF16(kTestTemplateURLKeyword); | 472 match.keyword = base::ASCIIToUTF16(kTestTemplateURLKeyword); |
| 440 match.search_terms_args.reset( | 473 match.search_terms_args.reset( |
| 441 new TemplateURLRef::SearchTermsArgs(base::string16())); | 474 new TemplateURLRef::SearchTermsArgs(base::string16())); |
| 442 matches.push_back(match); | 475 matches.push_back(match); |
| 443 } | 476 } |
| 444 result_.Reset(); | 477 result_.Reset(); |
| 445 result_.AppendMatches(AutocompleteInput(), matches); | 478 result_.AppendMatches(AutocompleteInput(), matches); |
| 446 | 479 |
| 447 // Update AQS. | 480 // Update AQS. |
| 448 controller_->UpdateAssistedQueryStats(&result_); | 481 controller_->UpdateAssistedQueryStats(&result_); |
| 449 | 482 |
| 450 // Verify data. | 483 // Verify data. |
| 451 for (size_t i = 0; i < size; ++i) { | 484 for (size_t i = 0; i < size; ++i) { |
| 452 EXPECT_EQ(aqs_test_data[i].expected_aqs, | 485 EXPECT_EQ(aqs_test_data[i].expected_aqs, |
| 453 result_.match_at(i)->search_terms_args->assisted_query_stats); | 486 result_.match_at(i)->search_terms_args->assisted_query_stats); |
| 454 } | 487 } |
| 455 } | 488 } |
| 456 | 489 |
| 457 void AutocompleteProviderTest::RunQuery(const base::string16 query) { | 490 void AutocompleteProviderTest::RunQuery(const base::string16 query) { |
| 458 result_.Reset(); | 491 result_.Reset(); |
| 459 controller_->Start(AutocompleteInput( | 492 controller_->Start( |
| 460 query, base::string16::npos, std::string(), GURL(), | 493 AutocompleteInput(query, base::string16::npos, std::string(), GURL(), |
| 461 metrics::OmniboxEventProto::INVALID_SPEC, true, false, true, true, false, | 494 metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
| 462 ChromeAutocompleteSchemeClassifier(&profile_))); | 495 true, true, false, TestingSchemeClassifier())); |
| 463 | 496 |
| 464 if (!controller_->done()) | 497 if (!controller_->done()) |
| 465 // The message loop will terminate when all autocomplete input has been | 498 // The message loop will terminate when all autocomplete input has been |
| 466 // collected. | 499 // collected. |
| 467 base::MessageLoop::current()->Run(); | 500 base::MessageLoop::current()->Run(); |
| 468 } | 501 } |
| 469 | 502 |
| 470 void AutocompleteProviderTest::RunExactKeymatchTest( | 503 void AutocompleteProviderTest::RunExactKeymatchTest( |
| 471 bool allow_exact_keyword_match) { | 504 bool allow_exact_keyword_match) { |
| 472 // Send the controller input which exactly matches the keyword provider we | 505 // Send the controller input which exactly matches the keyword provider we |
| 473 // created in ResetControllerWithKeywordAndSearchProviders(). The default | 506 // created in ResetControllerWithKeywordAndSearchProviders(). The default |
| 474 // match should thus be a search-other-engine match iff | 507 // match should thus be a search-other-engine match iff |
| 475 // |allow_exact_keyword_match| is true. Regardless, the match should | 508 // |allow_exact_keyword_match| is true. Regardless, the match should |
| 476 // be from SearchProvider. (It provides all verbatim search matches, | 509 // be from SearchProvider. (It provides all verbatim search matches, |
| 477 // keyword or not.) | 510 // keyword or not.) |
| 478 controller_->Start(AutocompleteInput( | 511 controller_->Start(AutocompleteInput( |
| 479 base::ASCIIToUTF16("k test"), base::string16::npos, std::string(), GURL(), | 512 base::ASCIIToUTF16("k test"), base::string16::npos, std::string(), GURL(), |
| 480 metrics::OmniboxEventProto::INVALID_SPEC, true, false, | 513 metrics::OmniboxEventProto::INVALID_SPEC, true, false, |
| 481 allow_exact_keyword_match, false, false, | 514 allow_exact_keyword_match, false, false, TestingSchemeClassifier())); |
| 482 ChromeAutocompleteSchemeClassifier(&profile_))); | |
| 483 EXPECT_TRUE(controller_->done()); | 515 EXPECT_TRUE(controller_->done()); |
| 484 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH, | 516 EXPECT_EQ(AutocompleteProvider::TYPE_SEARCH, |
| 485 controller_->result().default_match()->provider->type()); | 517 controller_->result().default_match()->provider->type()); |
| 486 EXPECT_EQ(allow_exact_keyword_match ? | 518 EXPECT_EQ(allow_exact_keyword_match |
| 487 AutocompleteMatchType::SEARCH_OTHER_ENGINE : | 519 ? AutocompleteMatchType::SEARCH_OTHER_ENGINE |
| 488 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 520 : AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 489 controller_->result().default_match()->type); | 521 controller_->result().default_match()->type); |
| 490 } | 522 } |
| 491 | 523 |
| 492 void AutocompleteProviderTest::CopyResults() { | 524 void AutocompleteProviderTest::CopyResults() { |
| 493 result_.CopyFrom(controller_->result()); | 525 result_.CopyFrom(controller_->result()); |
| 494 } | 526 } |
| 495 | 527 |
| 496 GURL AutocompleteProviderTest::GetDestinationURL( | 528 GURL AutocompleteProviderTest::GetDestinationURL( |
| 497 AutocompleteMatch match, | 529 AutocompleteMatch match, |
| 498 base::TimeDelta query_formulation_time) const { | 530 base::TimeDelta query_formulation_time) const { |
| 499 controller_->UpdateMatchDestinationURLWithQueryFormulationTime( | 531 controller_->UpdateMatchDestinationURLWithQueryFormulationTime( |
| 500 query_formulation_time, &match); | 532 query_formulation_time, &match); |
| 501 return match.destination_url; | 533 return match.destination_url; |
| 502 } | 534 } |
| 503 | 535 |
| 504 void AutocompleteProviderTest::Observe( | |
| 505 int type, | |
| 506 const content::NotificationSource& source, | |
| 507 const content::NotificationDetails& details) { | |
| 508 if (controller_->done()) { | |
| 509 CopyResults(); | |
| 510 base::MessageLoop::current()->QuitWhenIdle(); | |
| 511 } | |
| 512 } | |
| 513 | |
| 514 // Tests that the default selection is set properly when updating results. | 536 // Tests that the default selection is set properly when updating results. |
| 515 TEST_F(AutocompleteProviderTest, Query) { | 537 TEST_F(AutocompleteProviderTest, Query) { |
| 516 TestProvider* provider1 = NULL; | 538 TestProvider* provider1 = nullptr; |
| 517 TestProvider* provider2 = NULL; | 539 TestProvider* provider2 = nullptr; |
| 518 ResetControllerWithTestProviders(false, &provider1, &provider2); | 540 ResetControllerWithTestProviders(false, &provider1, &provider2); |
| 519 RunTest(); | 541 RunTest(); |
| 520 | 542 |
| 521 // Make sure the default match gets set to the highest relevance match. The | 543 // Make sure the default match gets set to the highest relevance match. The |
| 522 // highest relevance matches should come from the second provider. | 544 // highest relevance matches should come from the second provider. |
| 523 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); | 545 EXPECT_EQ(kResultsPerProvider * 2, result_.size()); |
| 524 ASSERT_NE(result_.end(), result_.default_match()); | 546 ASSERT_NE(result_.end(), result_.default_match()); |
| 525 EXPECT_EQ(provider2, result_.default_match()->provider); | 547 EXPECT_EQ(provider2, result_.default_match()->provider); |
| 526 } | 548 } |
| 527 | 549 |
| 528 // Tests assisted query stats. | 550 // Tests assisted query stats. |
| 529 TEST_F(AutocompleteProviderTest, AssistedQueryStats) { | 551 TEST_F(AutocompleteProviderTest, AssistedQueryStats) { |
| 530 ResetControllerWithTestProviders(false, NULL, NULL); | 552 ResetControllerWithTestProviders(false, nullptr, nullptr); |
| 531 RunTest(); | 553 RunTest(); |
| 532 | 554 |
| 533 ASSERT_EQ(kResultsPerProvider * 2, result_.size()); | 555 ASSERT_EQ(kResultsPerProvider * 2, result_.size()); |
| 534 | 556 |
| 535 // Now, check the results from the second provider, as they should not have | 557 // Now, check the results from the second provider, as they should not have |
| 536 // assisted query stats set. | 558 // assisted query stats set. |
| 537 for (size_t i = 0; i < kResultsPerProvider; ++i) { | 559 for (size_t i = 0; i < kResultsPerProvider; ++i) { |
| 538 EXPECT_TRUE( | 560 EXPECT_TRUE( |
| 539 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); | 561 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); |
| 540 } | 562 } |
| 541 // The first provider has a test keyword, so AQS should be non-empty. | 563 // The first provider has a test keyword, so AQS should be non-empty. |
| 542 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) { | 564 for (size_t i = kResultsPerProvider; i < kResultsPerProvider * 2; ++i) { |
| 543 EXPECT_FALSE( | 565 EXPECT_FALSE( |
| 544 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); | 566 result_.match_at(i)->search_terms_args->assisted_query_stats.empty()); |
| 545 } | 567 } |
| 546 } | 568 } |
| 547 | 569 |
| 548 TEST_F(AutocompleteProviderTest, RemoveDuplicates) { | 570 TEST_F(AutocompleteProviderTest, RemoveDuplicates) { |
| 549 TestProvider* provider1 = NULL; | 571 TestProvider* provider1 = nullptr; |
| 550 TestProvider* provider2 = NULL; | 572 TestProvider* provider2 = nullptr; |
| 551 ResetControllerWithTestProviders(true, &provider1, &provider2); | 573 ResetControllerWithTestProviders(true, &provider1, &provider2); |
| 552 RunTest(); | 574 RunTest(); |
| 553 | 575 |
| 554 // Make sure all the first provider's results were eliminated by the second | 576 // Make sure all the first provider's results were eliminated by the second |
| 555 // provider's. | 577 // provider's. |
| 556 EXPECT_EQ(kResultsPerProvider, result_.size()); | 578 EXPECT_EQ(kResultsPerProvider, result_.size()); |
| 557 for (AutocompleteResult::const_iterator i(result_.begin()); | 579 for (AutocompleteResult::const_iterator i(result_.begin()); |
| 558 i != result_.end(); ++i) | 580 i != result_.end(); ++i) |
| 559 EXPECT_EQ(provider2, i->provider); | 581 EXPECT_EQ(provider2, i->provider); |
| 560 } | 582 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 base::ASCIIToUTF16("f") } | 673 base::ASCIIToUTF16("f") } |
| 652 }; | 674 }; |
| 653 | 675 |
| 654 SCOPED_TRACE("keyword exact match"); | 676 SCOPED_TRACE("keyword exact match"); |
| 655 RunKeywordTest(base::ASCIIToUTF16("f"), keyword_match, | 677 RunKeywordTest(base::ASCIIToUTF16("f"), keyword_match, |
| 656 arraysize(keyword_match)); | 678 arraysize(keyword_match)); |
| 657 } | 679 } |
| 658 } | 680 } |
| 659 | 681 |
| 660 TEST_F(AutocompleteProviderTest, UpdateAssistedQueryStats) { | 682 TEST_F(AutocompleteProviderTest, UpdateAssistedQueryStats) { |
| 661 ResetControllerWithTestProviders(false, NULL, NULL); | 683 ResetControllerWithTestProviders(false, nullptr, nullptr); |
| 662 | 684 |
| 663 { | 685 { |
| 664 AssistedQueryStatsTestData test_data[] = { | 686 AssistedQueryStatsTestData test_data[] = { |
| 665 // MSVC doesn't support zero-length arrays, so supply some dummy data. | 687 // MSVC doesn't support zero-length arrays, so supply some dummy data. |
| 666 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, "" } | 688 { AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, "" } |
| 667 }; | 689 }; |
| 668 SCOPED_TRACE("No matches"); | 690 SCOPED_TRACE("No matches"); |
| 669 // Note: We pass 0 here to ignore the dummy data above. | 691 // Note: We pass 0 here to ignore the dummy data above. |
| 670 RunAssistedQueryStatsTest(test_data, 0); | 692 RunAssistedQueryStatsTest(test_data, 0); |
| 671 } | 693 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 700 SCOPED_TRACE("Multiple matches"); | 722 SCOPED_TRACE("Multiple matches"); |
| 701 RunAssistedQueryStatsTest(test_data, arraysize(test_data)); | 723 RunAssistedQueryStatsTest(test_data, arraysize(test_data)); |
| 702 } | 724 } |
| 703 } | 725 } |
| 704 | 726 |
| 705 TEST_F(AutocompleteProviderTest, GetDestinationURL) { | 727 TEST_F(AutocompleteProviderTest, GetDestinationURL) { |
| 706 ResetControllerWithKeywordAndSearchProviders(); | 728 ResetControllerWithKeywordAndSearchProviders(); |
| 707 | 729 |
| 708 // For the destination URL to have aqs parameters for query formulation time | 730 // For the destination URL to have aqs parameters for query formulation time |
| 709 // and the field trial triggered bit, many conditions need to be satisfied. | 731 // and the field trial triggered bit, many conditions need to be satisfied. |
| 710 AutocompleteMatch match(NULL, 1100, false, | 732 AutocompleteMatch match(nullptr, 1100, false, |
| 711 AutocompleteMatchType::SEARCH_SUGGEST); | 733 AutocompleteMatchType::SEARCH_SUGGEST); |
| 712 GURL url(GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456))); | 734 GURL url(GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456))); |
| 713 EXPECT_TRUE(url.path().empty()); | 735 EXPECT_TRUE(url.path().empty()); |
| 714 | 736 |
| 715 // The protocol needs to be https. | 737 // The protocol needs to be https. |
| 716 RegisterTemplateURL(base::ASCIIToUTF16(kTestTemplateURLKeyword), | 738 RegisterTemplateURL(base::ASCIIToUTF16(kTestTemplateURLKeyword), |
| 717 "https://aqs/{searchTerms}/{google:assistedQueryStats}"); | 739 "https://aqs/{searchTerms}/{google:assistedQueryStats}"); |
| 718 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 740 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 719 EXPECT_TRUE(url.path().empty()); | 741 EXPECT_TRUE(url.path().empty()); |
| 720 | 742 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 747 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); | 769 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); |
| 748 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 770 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 749 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 771 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
| 750 | 772 |
| 751 // Test page classification and field trial triggered set. | 773 // Test page classification and field trial triggered set. |
| 752 set_search_provider_field_trial_triggered_in_session(true); | 774 set_search_provider_field_trial_triggered_in_session(true); |
| 753 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); | 775 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); |
| 754 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 776 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
| 755 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 777 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
| 756 } | 778 } |
| OLD | NEW |