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/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "components/autofill/core/browser/autocomplete_history_manager.h" | 28 #include "components/autofill/core/browser/autocomplete_history_manager.h" |
29 #include "components/autofill/core/browser/autofill_manager.h" | 29 #include "components/autofill/core/browser/autofill_manager.h" |
30 #include "components/autofill/core/browser/autofill_metrics.h" | 30 #include "components/autofill/core/browser/autofill_metrics.h" |
31 #include "components/autofill/core/browser/autofill_profile.h" | 31 #include "components/autofill/core/browser/autofill_profile.h" |
32 #include "components/autofill/core/browser/autofill_test_utils.h" | 32 #include "components/autofill/core/browser/autofill_test_utils.h" |
33 #include "components/autofill/core/browser/credit_card.h" | 33 #include "components/autofill/core/browser/credit_card.h" |
34 #include "components/autofill/core/browser/personal_data_manager.h" | 34 #include "components/autofill/core/browser/personal_data_manager.h" |
35 #include "components/autofill/core/browser/test_autofill_driver.h" | 35 #include "components/autofill/core/browser/test_autofill_driver.h" |
36 #include "components/autofill/core/browser/test_autofill_external_delegate.h" | 36 #include "components/autofill/core/browser/test_autofill_external_delegate.h" |
37 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" | 37 #include "components/autofill/core/browser/test_autofill_manager_delegate.h" |
38 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | |
38 #include "components/autofill/core/common/autofill_messages.h" | 39 #include "components/autofill/core/common/autofill_messages.h" |
39 #include "components/autofill/core/common/autofill_pref_names.h" | 40 #include "components/autofill/core/common/autofill_pref_names.h" |
40 #include "components/autofill/core/common/form_data.h" | 41 #include "components/autofill/core/common/form_data.h" |
41 #include "components/autofill/core/common/form_field_data.h" | 42 #include "components/autofill/core/common/form_field_data.h" |
42 #include "components/autofill/core/common/forms_seen_state.h" | 43 #include "components/autofill/core/common/forms_seen_state.h" |
43 #include "components/user_prefs/user_prefs.h" | 44 #include "components/user_prefs/user_prefs.h" |
44 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
45 #include "content/public/test/mock_render_process_host.h" | 46 #include "content/public/test/mock_render_process_host.h" |
46 #include "content/public/test/test_utils.h" | 47 #include "content/public/test/test_utils.h" |
47 #include "grit/component_strings.h" | 48 #include "grit/component_strings.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
68 // an IPC message back to the renderer. | 69 // an IPC message back to the renderer. |
69 const int kDefaultPageID = 137; | 70 const int kDefaultPageID = 137; |
70 | 71 |
71 class TestPersonalDataManager : public PersonalDataManager { | 72 class TestPersonalDataManager : public PersonalDataManager { |
72 public: | 73 public: |
73 TestPersonalDataManager() : PersonalDataManager("en-US") { | 74 TestPersonalDataManager() : PersonalDataManager("en-US") { |
74 CreateTestAutofillProfiles(&web_profiles_); | 75 CreateTestAutofillProfiles(&web_profiles_); |
75 CreateTestCreditCards(&credit_cards_); | 76 CreateTestCreditCards(&credit_cards_); |
76 } | 77 } |
77 | 78 |
78 void SetBrowserContext(content::BrowserContext* context) { | 79 void SetAutofillWebDataService( |
79 set_browser_context(context); | 80 scoped_refptr<AutofillWebDataService> webdata) { |
81 set_autofill_webdata_service(webdata); | |
80 } | 82 } |
Ilya Sherman
2013/11/14 02:22:02
nit: Why not just "using PersonalDataManager::set_
blundell
2013/11/14 16:46:30
Done.
| |
81 | 83 |
82 void SetPrefService(PrefService* pref_service) { | 84 void SetPrefService(PrefService* pref_service) { |
83 set_pref_service(pref_service); | 85 set_pref_service(pref_service); |
84 } | 86 } |
85 | 87 |
86 // Factory method for keyed service. PersonalDataManager is NULL for testing. | 88 // Factory method for keyed service. PersonalDataManager is NULL for testing. |
87 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { | 89 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { |
88 return NULL; | 90 return NULL; |
89 } | 91 } |
90 | 92 |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 public: | 635 public: |
634 virtual void SetUp() OVERRIDE { | 636 virtual void SetUp() OVERRIDE { |
635 ChromeRenderViewHostTestHarness::SetUp(); | 637 ChromeRenderViewHostTestHarness::SetUp(); |
636 | 638 |
637 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 639 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
638 profile(), TestPersonalDataManager::Build); | 640 profile(), TestPersonalDataManager::Build); |
639 | 641 |
640 | 642 |
641 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 643 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
642 | 644 |
643 personal_data_.SetBrowserContext(profile()); | 645 autofill::TabAutofillManagerDelegate* manager_delegate = |
646 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()); | |
647 personal_data_.SetAutofillWebDataService( | |
648 manager_delegate->GetAutofillWebDataService()); | |
644 personal_data_.SetPrefService(profile()->GetPrefs()); | 649 personal_data_.SetPrefService(profile()->GetPrefs()); |
645 autofill_driver_.reset(new MockAutofillDriver(web_contents())); | 650 autofill_driver_.reset(new MockAutofillDriver(web_contents())); |
646 autofill_manager_.reset(new TestAutofillManager( | 651 autofill_manager_.reset(new TestAutofillManager( |
647 autofill_driver_.get(), | 652 autofill_driver_.get(), manager_delegate, &personal_data_)); |
648 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | |
649 &personal_data_)); | |
650 | 653 |
651 external_delegate_.reset(new TestAutofillExternalDelegate( | 654 external_delegate_.reset(new TestAutofillExternalDelegate( |
652 web_contents(), | 655 web_contents(), |
653 autofill_manager_.get(), | 656 autofill_manager_.get(), |
654 autofill_driver_.get())); | 657 autofill_driver_.get())); |
655 autofill_manager_->SetExternalDelegate(external_delegate_.get()); | 658 autofill_manager_->SetExternalDelegate(external_delegate_.get()); |
656 } | 659 } |
657 | 660 |
658 virtual void TearDown() OVERRIDE { | 661 virtual void TearDown() OVERRIDE { |
659 // Order of destruction is important as AutofillManager relies on | 662 // Order of destruction is important as AutofillManager relies on |
660 // PersonalDataManager to be around when it gets destroyed. Also, a real | 663 // PersonalDataManager to be around when it gets destroyed. Also, a real |
661 // AutofillManager is tied to the lifetime of the WebContents, so it must | 664 // AutofillManager is tied to the lifetime of the WebContents, so it must |
662 // be destroyed at the destruction of the WebContents. | 665 // be destroyed at the destruction of the WebContents. |
663 autofill_manager_.reset(); | 666 autofill_manager_.reset(); |
664 autofill_driver_.reset(); | 667 autofill_driver_.reset(); |
665 ChromeRenderViewHostTestHarness::TearDown(); | 668 ChromeRenderViewHostTestHarness::TearDown(); |
666 | 669 |
667 // Remove the BrowserContext so TestPersonalDataManager does not need to | 670 // Remove the AutofillWebDataService so TestPersonalDataManager does not |
668 // care about removing self as an observer in destruction. | 671 // need to care about removing self as an observer in destruction. |
669 personal_data_.SetBrowserContext(NULL); | 672 personal_data_.SetAutofillWebDataService( |
673 scoped_refptr<AutofillWebDataService>(NULL)); | |
670 } | 674 } |
671 | 675 |
672 void GetAutofillSuggestions(int query_id, | 676 void GetAutofillSuggestions(int query_id, |
673 const FormData& form, | 677 const FormData& form, |
674 const FormFieldData& field) { | 678 const FormFieldData& field) { |
675 autofill_manager_->OnQueryFormFieldAutofill(query_id, | 679 autofill_manager_->OnQueryFormFieldAutofill(query_id, |
676 form, | 680 form, |
677 field, | 681 field, |
678 gfx::Rect(), | 682 gfx::Rect(), |
679 false); | 683 false); |
(...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2948 test::CreateTestAddressFormData(&form); | 2952 test::CreateTestAddressFormData(&form); |
2949 std::vector<FormData> forms(1, form); | 2953 std::vector<FormData> forms(1, form); |
2950 FormsSeen(forms); | 2954 FormsSeen(forms); |
2951 const FormFieldData& field = form.fields[0]; | 2955 const FormFieldData& field = form.fields[0]; |
2952 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 2956 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
2953 | 2957 |
2954 EXPECT_TRUE(external_delegate_->on_query_seen()); | 2958 EXPECT_TRUE(external_delegate_->on_query_seen()); |
2955 } | 2959 } |
2956 | 2960 |
2957 } // namespace autofill | 2961 } // namespace autofill |
OLD | NEW |