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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "base/tuple.h" | 21 #include "base/tuple.h" |
22 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 22 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
23 #include "components/autofill/core/browser/autofill_manager.h" | 23 #include "components/autofill/core/browser/autofill_manager.h" |
24 #include "components/autofill/core/browser/autofill_metrics.h" | 24 #include "components/autofill/core/browser/autofill_metrics.h" |
25 #include "components/autofill/core/browser/autofill_profile.h" | 25 #include "components/autofill/core/browser/autofill_profile.h" |
26 #include "components/autofill/core/browser/autofill_test_utils.h" | 26 #include "components/autofill/core/browser/autofill_test_utils.h" |
27 #include "components/autofill/core/browser/credit_card.h" | 27 #include "components/autofill/core/browser/credit_card.h" |
28 #include "components/autofill/core/browser/personal_data_manager.h" | 28 #include "components/autofill/core/browser/personal_data_manager.h" |
29 #include "components/autofill/core/browser/popup_item_ids.h" | 29 #include "components/autofill/core/browser/popup_item_ids.h" |
| 30 #include "components/autofill/core/browser/test_autofill_client.h" |
30 #include "components/autofill/core/browser/test_autofill_driver.h" | 31 #include "components/autofill/core/browser/test_autofill_driver.h" |
31 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 32 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
32 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | |
33 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 33 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
34 #include "components/autofill/core/common/autofill_pref_names.h" | 34 #include "components/autofill/core/common/autofill_pref_names.h" |
35 #include "components/autofill/core/common/form_data.h" | 35 #include "components/autofill/core/common/form_data.h" |
36 #include "components/autofill/core/common/form_field_data.h" | 36 #include "components/autofill/core/common/form_field_data.h" |
37 #include "grit/components_strings.h" | 37 #include "grit/components_strings.h" |
38 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
41 #include "ui/gfx/rect.h" | 41 #include "ui/gfx/rect.h" |
42 #include "url/gurl.h" | 42 #include "url/gurl.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 const char* year, | 352 const char* year, |
353 const char* month) { | 353 const char* month) { |
354 ExpectFilledForm(page_id, filled_form, expected_page_id, | 354 ExpectFilledForm(page_id, filled_form, expected_page_id, |
355 "", "", "", "", "", "", "", "", "", "", "", | 355 "", "", "", "", "", "", "", "", "", "", "", |
356 "Miku Hatsune", "4234567890654321", month, year, | 356 "Miku Hatsune", "4234567890654321", month, year, |
357 has_address_fields, true, true); | 357 has_address_fields, true, true); |
358 } | 358 } |
359 | 359 |
360 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { | 360 class MockAutocompleteHistoryManager : public AutocompleteHistoryManager { |
361 public: | 361 public: |
362 MockAutocompleteHistoryManager(AutofillDriver* driver, | 362 MockAutocompleteHistoryManager(AutofillDriver* driver, AutofillClient* client) |
363 AutofillManagerDelegate* delegate) | 363 : AutocompleteHistoryManager(driver, client) {} |
364 : AutocompleteHistoryManager(driver, delegate) {} | |
365 | 364 |
366 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); | 365 MOCK_METHOD1(OnFormSubmitted, void(const FormData& form)); |
367 | 366 |
368 private: | 367 private: |
369 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); | 368 DISALLOW_COPY_AND_ASSIGN(MockAutocompleteHistoryManager); |
370 }; | 369 }; |
371 | 370 |
372 class MockAutofillDriver : public TestAutofillDriver { | 371 class MockAutofillDriver : public TestAutofillDriver { |
373 public: | 372 public: |
374 MockAutofillDriver() {} | 373 MockAutofillDriver() {} |
375 | 374 |
376 // Mock methods to enable testability. | 375 // Mock methods to enable testability. |
377 MOCK_METHOD3(SendFormDataToRenderer, void(int query_id, | 376 MOCK_METHOD3(SendFormDataToRenderer, void(int query_id, |
378 RendererFormDataAction action, | 377 RendererFormDataAction action, |
379 const FormData& data)); | 378 const FormData& data)); |
380 | 379 |
381 private: | 380 private: |
382 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); | 381 DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver); |
383 }; | 382 }; |
384 | 383 |
385 class TestAutofillManager : public AutofillManager { | 384 class TestAutofillManager : public AutofillManager { |
386 public: | 385 public: |
387 TestAutofillManager(AutofillDriver* driver, | 386 TestAutofillManager(AutofillDriver* driver, |
388 autofill::AutofillManagerDelegate* delegate, | 387 autofill::AutofillClient* client, |
389 TestPersonalDataManager* personal_data) | 388 TestPersonalDataManager* personal_data) |
390 : AutofillManager(driver, delegate, personal_data), | 389 : AutofillManager(driver, client, personal_data), |
391 personal_data_(personal_data), | 390 personal_data_(personal_data), |
392 autofill_enabled_(true) {} | 391 autofill_enabled_(true) {} |
393 virtual ~TestAutofillManager() {} | 392 virtual ~TestAutofillManager() {} |
394 | 393 |
395 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 394 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
396 | 395 |
397 void set_autofill_enabled(bool autofill_enabled) { | 396 void set_autofill_enabled(bool autofill_enabled) { |
398 autofill_enabled_ = autofill_enabled; | 397 autofill_enabled_ = autofill_enabled; |
399 } | 398 } |
400 | 399 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 std::vector<int> autofill_unique_ids_; | 579 std::vector<int> autofill_unique_ids_; |
581 | 580 |
582 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); | 581 DISALLOW_COPY_AND_ASSIGN(TestAutofillExternalDelegate); |
583 }; | 582 }; |
584 | 583 |
585 } // namespace | 584 } // namespace |
586 | 585 |
587 class AutofillManagerTest : public testing::Test { | 586 class AutofillManagerTest : public testing::Test { |
588 public: | 587 public: |
589 virtual void SetUp() OVERRIDE { | 588 virtual void SetUp() OVERRIDE { |
590 autofill_delegate_.SetPrefs(test::PrefServiceForTesting()); | 589 autofill_client_.SetPrefs(test::PrefServiceForTesting()); |
591 personal_data_.set_database(autofill_delegate_.GetDatabase()); | 590 personal_data_.set_database(autofill_client_.GetDatabase()); |
592 personal_data_.SetPrefService(autofill_delegate_.GetPrefs()); | 591 personal_data_.SetPrefService(autofill_client_.GetPrefs()); |
593 autofill_driver_.reset(new MockAutofillDriver()); | 592 autofill_driver_.reset(new MockAutofillDriver()); |
594 autofill_manager_.reset(new TestAutofillManager( | 593 autofill_manager_.reset(new TestAutofillManager( |
595 autofill_driver_.get(), &autofill_delegate_, &personal_data_)); | 594 autofill_driver_.get(), &autofill_client_, &personal_data_)); |
596 | 595 |
597 external_delegate_.reset(new TestAutofillExternalDelegate( | 596 external_delegate_.reset(new TestAutofillExternalDelegate( |
598 autofill_manager_.get(), | 597 autofill_manager_.get(), |
599 autofill_driver_.get())); | 598 autofill_driver_.get())); |
600 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 599 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
601 } | 600 } |
602 | 601 |
603 virtual void TearDown() OVERRIDE { | 602 virtual void TearDown() OVERRIDE { |
604 // Order of destruction is important as AutofillManager relies on | 603 // Order of destruction is important as AutofillManager relies on |
605 // PersonalDataManager to be around when it gets destroyed. | 604 // PersonalDataManager to be around when it gets destroyed. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 testing::SaveArg<2>(response_data)))); | 666 testing::SaveArg<2>(response_data)))); |
668 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); | 667 FillAutofillFormData(input_query_id, input_form, input_field, unique_id); |
669 } | 668 } |
670 | 669 |
671 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { | 670 int PackGUIDs(const GUIDPair& cc_guid, const GUIDPair& profile_guid) const { |
672 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); | 671 return autofill_manager_->PackGUIDs(cc_guid, profile_guid); |
673 } | 672 } |
674 | 673 |
675 protected: | 674 protected: |
676 base::MessageLoop message_loop_; | 675 base::MessageLoop message_loop_; |
677 TestAutofillManagerDelegate autofill_delegate_; | 676 TestAutofillClient autofill_client_; |
678 scoped_ptr<MockAutofillDriver> autofill_driver_; | 677 scoped_ptr<MockAutofillDriver> autofill_driver_; |
679 scoped_ptr<TestAutofillManager> autofill_manager_; | 678 scoped_ptr<TestAutofillManager> autofill_manager_; |
680 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; | 679 scoped_ptr<TestAutofillExternalDelegate> external_delegate_; |
681 TestPersonalDataManager personal_data_; | 680 TestPersonalDataManager personal_data_; |
682 }; | 681 }; |
683 | 682 |
684 class TestFormStructure : public FormStructure { | 683 class TestFormStructure : public FormStructure { |
685 public: | 684 public: |
686 explicit TestFormStructure(const FormData& form) | 685 explicit TestFormStructure(const FormData& form) |
687 : FormStructure(form) {} | 686 : FormStructure(form) {} |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], | 1545 FillAutofillFormDataAndSaveResults(kDefaultPageID, form, form.fields[0], |
1547 PackGUIDs(empty, guid), &response_page_id, &response_data); | 1546 PackGUIDs(empty, guid), &response_page_id, &response_data); |
1548 ExpectFilledAddressFormElvis( | 1547 ExpectFilledAddressFormElvis( |
1549 response_page_id, response_data, kDefaultPageID, false); | 1548 response_page_id, response_data, kDefaultPageID, false); |
1550 } | 1549 } |
1551 | 1550 |
1552 // Test that we correctly fill an address form from an auxiliary profile. | 1551 // Test that we correctly fill an address form from an auxiliary profile. |
1553 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { | 1552 TEST_F(AutofillManagerTest, FillAddressFormFromAuxiliaryProfile) { |
1554 personal_data_.ClearAutofillProfiles(); | 1553 personal_data_.ClearAutofillProfiles(); |
1555 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1554 #if defined(OS_MACOSX) && !defined(OS_IOS) |
1556 autofill_delegate_.GetPrefs()->SetBoolean( | 1555 autofill_client_.GetPrefs()->SetBoolean( |
1557 ::autofill::prefs::kAutofillUseMacAddressBook, true); | 1556 ::autofill::prefs::kAutofillUseMacAddressBook, true); |
1558 #else | 1557 #else |
1559 autofill_delegate_.GetPrefs()->SetBoolean( | 1558 autofill_client_.GetPrefs()->SetBoolean( |
1560 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); | 1559 ::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, true); |
1561 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1560 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
1562 | 1561 |
1563 personal_data_.CreateTestAuxiliaryProfiles(); | 1562 personal_data_.CreateTestAuxiliaryProfiles(); |
1564 | 1563 |
1565 // Set up our form data. | 1564 // Set up our form data. |
1566 FormData form; | 1565 FormData form; |
1567 test::CreateTestAddressFormData(&form); | 1566 test::CreateTestAddressFormData(&form); |
1568 std::vector<FormData> forms(1, form); | 1567 std::vector<FormData> forms(1, form); |
1569 FormsSeen(forms); | 1568 FormsSeen(forms); |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2307 | 2306 |
2308 // Simulate form submission. We should call into the PDM to try to save the | 2307 // Simulate form submission. We should call into the PDM to try to save the |
2309 // filled data. | 2308 // filled data. |
2310 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); | 2309 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(1); |
2311 FormSubmitted(response_data); | 2310 FormSubmitted(response_data); |
2312 } | 2311 } |
2313 | 2312 |
2314 // Test that when Autocomplete is enabled and Autofill is disabled, | 2313 // Test that when Autocomplete is enabled and Autofill is disabled, |
2315 // form submissions are still received by AutocompleteHistoryManager. | 2314 // form submissions are still received by AutocompleteHistoryManager. |
2316 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { | 2315 TEST_F(AutofillManagerTest, FormSubmittedAutocompleteEnabled) { |
2317 TestAutofillManagerDelegate delegate; | 2316 TestAutofillClient client; |
2318 autofill_manager_.reset(new TestAutofillManager( | 2317 autofill_manager_.reset( |
2319 autofill_driver_.get(), | 2318 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
2320 &delegate, | |
2321 NULL)); | |
2322 autofill_manager_->set_autofill_enabled(false); | 2319 autofill_manager_->set_autofill_enabled(false); |
2323 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; | 2320 scoped_ptr<MockAutocompleteHistoryManager> autocomplete_history_manager; |
2324 autocomplete_history_manager.reset( | 2321 autocomplete_history_manager.reset( |
2325 new MockAutocompleteHistoryManager(autofill_driver_.get(), &delegate)); | 2322 new MockAutocompleteHistoryManager(autofill_driver_.get(), &client)); |
2326 autofill_manager_->autocomplete_history_manager_ = | 2323 autofill_manager_->autocomplete_history_manager_ = |
2327 autocomplete_history_manager.Pass(); | 2324 autocomplete_history_manager.Pass(); |
2328 | 2325 |
2329 // Set up our form data. | 2326 // Set up our form data. |
2330 FormData form; | 2327 FormData form; |
2331 test::CreateTestAddressFormData(&form); | 2328 test::CreateTestAddressFormData(&form); |
2332 form.method = ASCIIToUTF16("GET"); | 2329 form.method = ASCIIToUTF16("GET"); |
2333 MockAutocompleteHistoryManager* m = static_cast< | 2330 MockAutocompleteHistoryManager* m = static_cast< |
2334 MockAutocompleteHistoryManager*>( | 2331 MockAutocompleteHistoryManager*>( |
2335 autofill_manager_->autocomplete_history_manager_.get()); | 2332 autofill_manager_->autocomplete_history_manager_.get()); |
2336 EXPECT_CALL(*m, | 2333 EXPECT_CALL(*m, |
2337 OnFormSubmitted(_)).Times(1); | 2334 OnFormSubmitted(_)).Times(1); |
2338 FormSubmitted(form); | 2335 FormSubmitted(form); |
2339 } | 2336 } |
2340 | 2337 |
2341 // Test that when Autocomplete is enabled and Autofill is disabled, | 2338 // Test that when Autocomplete is enabled and Autofill is disabled, |
2342 // Autocomplete suggestions are still received. | 2339 // Autocomplete suggestions are still received. |
2343 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { | 2340 TEST_F(AutofillManagerTest, AutocompleteSuggestionsWhenAutofillDisabled) { |
2344 TestAutofillManagerDelegate delegate; | 2341 TestAutofillClient client; |
2345 autofill_manager_.reset(new TestAutofillManager( | 2342 autofill_manager_.reset( |
2346 autofill_driver_.get(), | 2343 new TestAutofillManager(autofill_driver_.get(), &client, NULL)); |
2347 &delegate, | |
2348 NULL)); | |
2349 autofill_manager_->set_autofill_enabled(false); | 2344 autofill_manager_->set_autofill_enabled(false); |
2350 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 2345 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
2351 | 2346 |
2352 // Set up our form data. | 2347 // Set up our form data. |
2353 FormData form; | 2348 FormData form; |
2354 test::CreateTestAddressFormData(&form); | 2349 test::CreateTestAddressFormData(&form); |
2355 form.method = ASCIIToUTF16("GET"); | 2350 form.method = ASCIIToUTF16("GET"); |
2356 std::vector<FormData> forms(1, form); | 2351 std::vector<FormData> forms(1, form); |
2357 FormsSeen(forms); | 2352 FormsSeen(forms); |
2358 const FormFieldData& field = form.fields[0]; | 2353 const FormFieldData& field = form.fields[0]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 | 2470 |
2476 // Simulate form submission. We should not call into the PDM to try to save | 2471 // Simulate form submission. We should not call into the PDM to try to save |
2477 // the filled data, since the filled form is effectively missing an address. | 2472 // the filled data, since the filled form is effectively missing an address. |
2478 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); | 2473 EXPECT_CALL(personal_data_, SaveImportedProfile(::testing::_)).Times(0); |
2479 FormSubmitted(response_data); | 2474 FormSubmitted(response_data); |
2480 } | 2475 } |
2481 | 2476 |
2482 // Checks that resetting the auxiliary profile enabled preference does the right | 2477 // Checks that resetting the auxiliary profile enabled preference does the right |
2483 // thing on all platforms. | 2478 // thing on all platforms. |
2484 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { | 2479 TEST_F(AutofillManagerTest, AuxiliaryProfilesReset) { |
2485 PrefService* prefs = autofill_delegate_.GetPrefs(); | 2480 PrefService* prefs = autofill_client_.GetPrefs(); |
2486 #if defined(OS_MACOSX) || defined(OS_ANDROID) | 2481 #if defined(OS_MACOSX) || defined(OS_ANDROID) |
2487 // Auxiliary profiles is implemented on Mac and Android only. | 2482 // Auxiliary profiles is implemented on Mac and Android only. |
2488 // OSX: This preference exists for legacy reasons. It is no longer used. | 2483 // OSX: This preference exists for legacy reasons. It is no longer used. |
2489 // Android: enables integration with user's contact profile. | 2484 // Android: enables integration with user's contact profile. |
2490 ASSERT_TRUE( | 2485 ASSERT_TRUE( |
2491 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); | 2486 prefs->GetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled)); |
2492 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, | 2487 prefs->SetBoolean(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled, |
2493 false); | 2488 false); |
2494 prefs->ClearPref(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled); | 2489 prefs->ClearPref(::autofill::prefs::kAutofillAuxiliaryProfilesEnabled); |
2495 ASSERT_TRUE( | 2490 ASSERT_TRUE( |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2835 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); | 2830 autofill_manager_->RemoveAutofillProfileOrCreditCard(id); |
2836 | 2831 |
2837 // TODO(csharp): Currently variants should not be deleted, but once they are | 2832 // TODO(csharp): Currently variants should not be deleted, but once they are |
2838 // update these expectations. | 2833 // update these expectations. |
2839 // http://crbug.com/124211 | 2834 // http://crbug.com/124211 |
2840 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); | 2835 EXPECT_TRUE(autofill_manager_->GetProfileWithGUID(guid.c_str())); |
2841 } | 2836 } |
2842 | 2837 |
2843 namespace { | 2838 namespace { |
2844 | 2839 |
2845 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate { | 2840 class MockAutofillClient : public TestAutofillClient { |
2846 public: | 2841 public: |
2847 MockAutofillManagerDelegate() {} | 2842 MockAutofillClient() {} |
2848 | 2843 |
2849 virtual ~MockAutofillManagerDelegate() {} | 2844 virtual ~MockAutofillClient() {} |
2850 | 2845 |
2851 virtual void ShowRequestAutocompleteDialog( | 2846 virtual void ShowRequestAutocompleteDialog( |
2852 const FormData& form, | 2847 const FormData& form, |
2853 const GURL& source_url, | 2848 const GURL& source_url, |
2854 const ResultCallback& callback) OVERRIDE { | 2849 const ResultCallback& callback) OVERRIDE { |
2855 callback.Run(user_supplied_data_ ? AutocompleteResultSuccess : | 2850 callback.Run(user_supplied_data_ ? AutocompleteResultSuccess : |
2856 AutocompleteResultErrorDisabled, | 2851 AutocompleteResultErrorDisabled, |
2857 base::string16(), | 2852 base::string16(), |
2858 user_supplied_data_.get()); | 2853 user_supplied_data_.get()); |
2859 } | 2854 } |
2860 | 2855 |
2861 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { | 2856 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { |
2862 user_supplied_data_.reset(user_supplied_data.release()); | 2857 user_supplied_data_.reset(user_supplied_data.release()); |
2863 } | 2858 } |
2864 | 2859 |
2865 private: | 2860 private: |
2866 scoped_ptr<FormStructure> user_supplied_data_; | 2861 scoped_ptr<FormStructure> user_supplied_data_; |
2867 | 2862 |
2868 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); | 2863 DISALLOW_COPY_AND_ASSIGN(MockAutofillClient); |
2869 }; | 2864 }; |
2870 | 2865 |
2871 } // namespace | 2866 } // namespace |
2872 | 2867 |
2873 // Test our external delegate is called at the right time. | 2868 // Test our external delegate is called at the right time. |
2874 TEST_F(AutofillManagerTest, TestExternalDelegate) { | 2869 TEST_F(AutofillManagerTest, TestExternalDelegate) { |
2875 FormData form; | 2870 FormData form; |
2876 test::CreateTestAddressFormData(&form); | 2871 test::CreateTestAddressFormData(&form); |
2877 std::vector<FormData> forms(1, form); | 2872 std::vector<FormData> forms(1, form); |
2878 FormsSeen(forms); | 2873 FormsSeen(forms); |
2879 const FormFieldData& field = form.fields[0]; | 2874 const FormFieldData& field = form.fields[0]; |
2880 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2875 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2881 | 2876 |
2882 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2877 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2883 } | 2878 } |
2884 | 2879 |
2885 } // namespace autofill | 2880 } // namespace autofill |
OLD | NEW |