OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 namespace { | 190 namespace { |
191 | 191 |
192 class MockAutofillExternalDelegate : public AutofillExternalDelegate { | 192 class MockAutofillExternalDelegate : public AutofillExternalDelegate { |
193 public: | 193 public: |
194 MockAutofillExternalDelegate(AutofillManager* autofill_manager, | 194 MockAutofillExternalDelegate(AutofillManager* autofill_manager, |
195 AutofillDriver* autofill_driver) | 195 AutofillDriver* autofill_driver) |
196 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} | 196 : AutofillExternalDelegate(autofill_manager, autofill_driver) {} |
197 virtual ~MockAutofillExternalDelegate() {} | 197 virtual ~MockAutofillExternalDelegate() {} |
198 | 198 |
199 MOCK_METHOD5(OnSuggestionsReturned, | 199 MOCK_METHOD2(OnSuggestionsReturned, |
200 void(int query_id, | 200 void(int query_id, |
201 const std::vector<base::string16>& autofill_values, | 201 const std::vector<Suggestion>& suggestions)); |
202 const std::vector<base::string16>& autofill_labels, | |
203 const std::vector<base::string16>& autofill_icons, | |
204 const std::vector<int>& autofill_unique_ids)); | |
205 | 202 |
206 private: | 203 private: |
207 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 204 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
208 }; | 205 }; |
209 | 206 |
210 class TestAutocompleteHistoryManager : public AutocompleteHistoryManager { | 207 class TestAutocompleteHistoryManager : public AutocompleteHistoryManager { |
211 public: | 208 public: |
212 TestAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) | 209 TestAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) |
213 : AutocompleteHistoryManager(driver, client) {} | 210 : AutocompleteHistoryManager(driver, client) {} |
214 | 211 |
215 using AutocompleteHistoryManager::SendSuggestions; | 212 using AutocompleteHistoryManager::SendSuggestions; |
216 }; | 213 }; |
217 | 214 |
| 215 // Predicate for GMock. |
| 216 bool IsEmptySuggestionVector(const std::vector<Suggestion>& suggestions) { |
| 217 return suggestions.empty(); |
| 218 } |
| 219 |
218 } // namespace | 220 } // namespace |
219 | 221 |
220 // Make sure our external delegate is called at the right time. | 222 // Make sure our external delegate is called at the right time. |
221 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { | 223 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { |
222 TestAutocompleteHistoryManager autocomplete_history_manager( | 224 TestAutocompleteHistoryManager autocomplete_history_manager( |
223 autofill_driver_.get(), autofill_client_.get()); | 225 autofill_driver_.get(), autofill_client_.get()); |
224 | 226 |
225 scoped_ptr<AutofillManager> autofill_manager( | 227 scoped_ptr<AutofillManager> autofill_manager( |
226 new AutofillManager(autofill_driver_.get(), | 228 new AutofillManager(autofill_driver_.get(), |
227 autofill_client_.get(), | 229 autofill_client_.get(), |
228 "en-US", | 230 "en-US", |
229 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER)); | 231 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER)); |
230 | 232 |
231 MockAutofillExternalDelegate external_delegate(autofill_manager.get(), | 233 MockAutofillExternalDelegate external_delegate(autofill_manager.get(), |
232 autofill_driver_.get()); | 234 autofill_driver_.get()); |
233 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 235 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
234 | 236 |
235 // Should trigger a call to OnSuggestionsReturned, verified by the mock. | 237 // Should trigger a call to OnSuggestionsReturned, verified by the mock. |
236 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); | 238 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _)); |
237 autocomplete_history_manager.SendSuggestions(NULL); | 239 autocomplete_history_manager.SendSuggestions(NULL); |
238 } | 240 } |
239 | 241 |
240 // Verify that no autocomplete suggestion is returned for textarea. | 242 // Verify that no autocomplete suggestion is returned for textarea. |
241 TEST_F(AutocompleteHistoryManagerTest, NoAutocompleteSuggestionsForTextarea) { | 243 TEST_F(AutocompleteHistoryManagerTest, NoAutocompleteSuggestionsForTextarea) { |
242 TestAutocompleteHistoryManager autocomplete_history_manager( | 244 TestAutocompleteHistoryManager autocomplete_history_manager( |
243 autofill_driver_.get(), autofill_client_.get()); | 245 autofill_driver_.get(), autofill_client_.get()); |
244 | 246 |
245 scoped_ptr<AutofillManager> autofill_manager( | 247 scoped_ptr<AutofillManager> autofill_manager( |
246 new AutofillManager(autofill_driver_.get(), | 248 new AutofillManager(autofill_driver_.get(), |
247 autofill_client_.get(), | 249 autofill_client_.get(), |
248 "en-US", | 250 "en-US", |
249 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER)); | 251 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER)); |
250 | 252 |
251 MockAutofillExternalDelegate external_delegate(autofill_manager.get(), | 253 MockAutofillExternalDelegate external_delegate(autofill_manager.get(), |
252 autofill_driver_.get()); | 254 autofill_driver_.get()); |
253 autocomplete_history_manager.SetExternalDelegate(&external_delegate); | 255 autocomplete_history_manager.SetExternalDelegate(&external_delegate); |
254 | 256 |
255 FormData form; | 257 FormData form; |
256 form.name = ASCIIToUTF16("MyForm"); | 258 form.name = ASCIIToUTF16("MyForm"); |
257 form.origin = GURL("http://myform.com/form.html"); | 259 form.origin = GURL("http://myform.com/form.html"); |
258 form.action = GURL("http://myform.com/submit.html"); | 260 form.action = GURL("http://myform.com/submit.html"); |
259 form.user_submitted = true; | 261 form.user_submitted = true; |
260 | 262 |
261 FormFieldData field; | 263 FormFieldData field; |
262 test::CreateTestFormField("Address", "address", "", "textarea", &field); | 264 test::CreateTestFormField("Address", "address", "", "textarea", &field); |
263 | 265 |
264 EXPECT_CALL(external_delegate, | 266 EXPECT_CALL(external_delegate, |
265 OnSuggestionsReturned(0, | 267 OnSuggestionsReturned(0, |
266 std::vector<base::string16>(), | 268 testing::Truly(IsEmptySuggestionVector))); |
267 std::vector<base::string16>(), | |
268 std::vector<base::string16>(), | |
269 std::vector<int>())); | |
270 autocomplete_history_manager.OnGetAutocompleteSuggestions( | 269 autocomplete_history_manager.OnGetAutocompleteSuggestions( |
271 0, | 270 0, |
272 field.name, | 271 field.name, |
273 field.value, | 272 field.value, |
274 field.form_control_type, | 273 field.form_control_type, |
275 std::vector<base::string16>(), | 274 std::vector<Suggestion>()); |
276 std::vector<base::string16>(), | |
277 std::vector<base::string16>(), | |
278 std::vector<int>()); | |
279 } | 275 } |
280 | 276 |
281 } // namespace autofill | 277 } // namespace autofill |
OLD | NEW |