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/autocomplete_provider.h" | 5 #include "components/omnibox/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/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
17 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 17 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 18 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 19 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/search_engines/template_url_service_factory.h" | 21 #include "chrome/browser/search_engines/template_url_service_factory.h" |
22 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
24 #include "components/metrics/proto/omnibox_event.pb.h" | 24 #include "components/metrics/proto/omnibox_event.pb.h" |
25 #include "components/omnibox/autocomplete_input.h" | 25 #include "components/omnibox/autocomplete_input.h" |
26 #include "components/omnibox/autocomplete_match.h" | 26 #include "components/omnibox/autocomplete_match.h" |
27 #include "components/omnibox/autocomplete_provider_listener.h" | 27 #include "components/omnibox/autocomplete_provider_listener.h" |
28 #include "components/omnibox/keyword_provider.h" | 28 #include "components/omnibox/keyword_provider.h" |
29 #include "components/omnibox/mock_autocomplete_provider_client.h" | |
29 #include "components/omnibox/search_provider.h" | 30 #include "components/omnibox/search_provider.h" |
30 #include "components/search_engines/search_engines_switches.h" | 31 #include "components/search_engines/search_engines_switches.h" |
31 #include "components/search_engines/template_url.h" | 32 #include "components/search_engines/template_url.h" |
32 #include "components/search_engines/template_url_service.h" | 33 #include "components/search_engines/template_url_service.h" |
33 #include "content/public/browser/notification_observer.h" | 34 #include "content/public/browser/notification_observer.h" |
34 #include "content/public/browser/notification_registrar.h" | 35 #include "content/public/browser/notification_registrar.h" |
35 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
36 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
38 | 39 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 const base::string16 keyword; | 170 const base::string16 keyword; |
170 const base::string16 expected_associated_keyword; | 171 const base::string16 expected_associated_keyword; |
171 }; | 172 }; |
172 | 173 |
173 struct AssistedQueryStatsTestData { | 174 struct AssistedQueryStatsTestData { |
174 const AutocompleteMatch::Type match_type; | 175 const AutocompleteMatch::Type match_type; |
175 const std::string expected_aqs; | 176 const std::string expected_aqs; |
176 }; | 177 }; |
177 | 178 |
178 protected: | 179 protected: |
180 AutocompleteProviderTest(): | |
181 client_(new MockAutocompleteProviderClient()), | |
182 result_(client_.get()) { } | |
183 | |
179 // Registers a test TemplateURL under the given keyword. | 184 // Registers a test TemplateURL under the given keyword. |
180 void RegisterTemplateURL(const base::string16 keyword, | 185 void RegisterTemplateURL(const base::string16 keyword, |
181 const std::string& template_url); | 186 const std::string& template_url); |
182 | 187 |
183 // Resets |controller_| with two TestProviders. |provider1_ptr| and | 188 // Resets |controller_| with two TestProviders. |provider1_ptr| and |
184 // |provider2_ptr| are updated to point to the new providers if non-NULL. | 189 // |provider2_ptr| are updated to point to the new providers if non-NULL. |
185 void ResetControllerWithTestProviders(bool same_destinations, | 190 void ResetControllerWithTestProviders(bool same_destinations, |
186 TestProvider** provider1_ptr, | 191 TestProvider** provider1_ptr, |
187 TestProvider** provider2_ptr); | 192 TestProvider** provider2_ptr); |
188 | 193 |
(...skipping 30 matching lines...) Expand all Loading... | |
219 controller_->search_provider_->set_field_trial_triggered_in_session(val); | 224 controller_->search_provider_->set_field_trial_triggered_in_session(val); |
220 } | 225 } |
221 bool search_provider_field_trial_triggered_in_session() { | 226 bool search_provider_field_trial_triggered_in_session() { |
222 return controller_->search_provider_->field_trial_triggered_in_session(); | 227 return controller_->search_provider_->field_trial_triggered_in_session(); |
223 } | 228 } |
224 void set_current_page_classification( | 229 void set_current_page_classification( |
225 metrics::OmniboxEventProto::PageClassification classification) { | 230 metrics::OmniboxEventProto::PageClassification classification) { |
226 controller_->input_.current_page_classification_ = classification; | 231 controller_->input_.current_page_classification_ = classification; |
227 } | 232 } |
228 | 233 |
234 scoped_ptr<AutocompleteProviderClient> client_; | |
Peter Kasting
2015/06/29 05:04:58
Nit: Does this need to be a scoped_ptr? Can it ju
Mark P
2015/06/30 04:23:16
Now moot.
| |
229 AutocompleteResult result_; | 235 AutocompleteResult result_; |
230 | 236 |
231 private: | 237 private: |
232 // content::NotificationObserver: | 238 // content::NotificationObserver: |
233 void Observe(int type, | 239 void Observe(int type, |
234 const content::NotificationSource& source, | 240 const content::NotificationSource& source, |
235 const content::NotificationDetails& details) override; | 241 const content::NotificationDetails& details) override; |
236 | 242 |
237 content::TestBrowserThreadBundle thread_bundle_; | 243 content::TestBrowserThreadBundle thread_bundle_; |
238 content::NotificationRegistrar registrar_; | 244 content::NotificationRegistrar registrar_; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 match.transition = ui::PAGE_TRANSITION_KEYWORD; | 413 match.transition = ui::PAGE_TRANSITION_KEYWORD; |
408 match.keyword = match_data[i].keyword; | 414 match.keyword = match_data[i].keyword; |
409 matches.push_back(match); | 415 matches.push_back(match); |
410 } | 416 } |
411 | 417 |
412 controller_->input_ = AutocompleteInput( | 418 controller_->input_ = AutocompleteInput( |
413 input, base::string16::npos, std::string(), GURL(), | 419 input, base::string16::npos, std::string(), GURL(), |
414 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, | 420 metrics::OmniboxEventProto::INSTANT_NTP_WITH_OMNIBOX_AS_STARTING_FOCUS, |
415 false, true, true, true, false, | 421 false, true, true, true, false, |
416 ChromeAutocompleteSchemeClassifier(&profile_)); | 422 ChromeAutocompleteSchemeClassifier(&profile_)); |
417 AutocompleteResult result; | 423 AutocompleteResult result(client_.get()); |
418 result.AppendMatches(controller_->input_, matches); | 424 result.AppendMatches(controller_->input_, matches); |
419 controller_->UpdateAssociatedKeywords(&result); | 425 controller_->UpdateAssociatedKeywords(&result); |
420 | 426 |
421 for (size_t j = 0; j < result.size(); ++j) { | 427 for (size_t j = 0; j < result.size(); ++j) { |
422 EXPECT_EQ(match_data[j].expected_associated_keyword, | 428 EXPECT_EQ(match_data[j].expected_associated_keyword, |
423 result.match_at(j)->associated_keyword.get() ? | 429 result.match_at(j)->associated_keyword.get() ? |
424 result.match_at(j)->associated_keyword->keyword : | 430 result.match_at(j)->associated_keyword->keyword : |
425 base::string16()); | 431 base::string16()); |
426 } | 432 } |
427 } | 433 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); | 753 EXPECT_FALSE(search_provider_field_trial_triggered_in_session()); |
748 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 754 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
749 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); | 755 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j0j4&", url.path()); |
750 | 756 |
751 // Test page classification and field trial triggered set. | 757 // Test page classification and field trial triggered set. |
752 set_search_provider_field_trial_triggered_in_session(true); | 758 set_search_provider_field_trial_triggered_in_session(true); |
753 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); | 759 EXPECT_TRUE(search_provider_field_trial_triggered_in_session()); |
754 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); | 760 url = GetDestinationURL(match, base::TimeDelta::FromMilliseconds(2456)); |
755 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); | 761 EXPECT_EQ("//aqs=chrome.0.69i57j69i58j5l2j0l3j69i59.2456j1j4&", url.path()); |
756 } | 762 } |
OLD | NEW |