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