Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: components/autofill/core/browser/autofill_manager_unittest.cc

Issue 71683003: Have AutofillManagerDelegate supply the AutofillWebDataService to core code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unittests, respond to reviews Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 using PersonalDataManager::set_database;
79 set_browser_context(context); 80 using PersonalDataManager::set_pref_service;
80 }
81
82 void SetPrefService(PrefService* pref_service) {
83 set_pref_service(pref_service);
84 }
85 81
86 // Factory method for keyed service. PersonalDataManager is NULL for testing. 82 // Factory method for keyed service. PersonalDataManager is NULL for testing.
87 static BrowserContextKeyedService* Build(content::BrowserContext* profile) { 83 static BrowserContextKeyedService* Build(content::BrowserContext* profile) {
88 return NULL; 84 return NULL;
89 } 85 }
90 86
91 MOCK_METHOD1(SaveImportedProfile, std::string(const AutofillProfile&)); 87 MOCK_METHOD1(SaveImportedProfile, std::string(const AutofillProfile&));
92 88
93 AutofillProfile* GetProfileWithGUID(const char* guid) { 89 AutofillProfile* GetProfileWithGUID(const char* guid) {
94 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin(); 90 for (std::vector<AutofillProfile *>::iterator it = web_profiles_.begin();
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 } // namespace 626 } // namespace
631 627
632 class AutofillManagerTest : public ChromeRenderViewHostTestHarness { 628 class AutofillManagerTest : public ChromeRenderViewHostTestHarness {
633 public: 629 public:
634 virtual void SetUp() OVERRIDE { 630 virtual void SetUp() OVERRIDE {
635 ChromeRenderViewHostTestHarness::SetUp(); 631 ChromeRenderViewHostTestHarness::SetUp();
636 632
637 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( 633 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
638 profile(), TestPersonalDataManager::Build); 634 profile(), TestPersonalDataManager::Build);
639 635
640
641 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); 636 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents());
642 637
643 personal_data_.SetBrowserContext(profile()); 638 autofill::TabAutofillManagerDelegate* manager_delegate =
644 personal_data_.SetPrefService(profile()->GetPrefs()); 639 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents());
640 personal_data_.set_database(manager_delegate->GetDatabase());
641 personal_data_.set_pref_service(profile()->GetPrefs());
645 autofill_driver_.reset(new MockAutofillDriver(web_contents())); 642 autofill_driver_.reset(new MockAutofillDriver(web_contents()));
646 autofill_manager_.reset(new TestAutofillManager( 643 autofill_manager_.reset(new TestAutofillManager(
647 autofill_driver_.get(), 644 autofill_driver_.get(), manager_delegate, &personal_data_));
648 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()),
649 &personal_data_));
650 645
651 external_delegate_.reset(new TestAutofillExternalDelegate( 646 external_delegate_.reset(new TestAutofillExternalDelegate(
652 web_contents(), 647 web_contents(),
653 autofill_manager_.get(), 648 autofill_manager_.get(),
654 autofill_driver_.get())); 649 autofill_driver_.get()));
655 autofill_manager_->SetExternalDelegate(external_delegate_.get()); 650 autofill_manager_->SetExternalDelegate(external_delegate_.get());
656 } 651 }
657 652
658 virtual void TearDown() OVERRIDE { 653 virtual void TearDown() OVERRIDE {
659 // Order of destruction is important as AutofillManager relies on 654 // Order of destruction is important as AutofillManager relies on
660 // PersonalDataManager to be around when it gets destroyed. Also, a real 655 // PersonalDataManager to be around when it gets destroyed. Also, a real
661 // AutofillManager is tied to the lifetime of the WebContents, so it must 656 // AutofillManager is tied to the lifetime of the WebContents, so it must
662 // be destroyed at the destruction of the WebContents. 657 // be destroyed at the destruction of the WebContents.
663 autofill_manager_.reset(); 658 autofill_manager_.reset();
664 autofill_driver_.reset(); 659 autofill_driver_.reset();
665 ChromeRenderViewHostTestHarness::TearDown(); 660 ChromeRenderViewHostTestHarness::TearDown();
666 661
667 // Remove the BrowserContext so TestPersonalDataManager does not need to 662 // Remove the AutofillWebDataService so TestPersonalDataManager does not
668 // care about removing self as an observer in destruction. 663 // need to care about removing self as an observer in destruction.
669 personal_data_.SetBrowserContext(NULL); 664 personal_data_.set_database(scoped_refptr<AutofillWebDataService>(NULL));
670 } 665 }
671 666
672 void GetAutofillSuggestions(int query_id, 667 void GetAutofillSuggestions(int query_id,
673 const FormData& form, 668 const FormData& form,
674 const FormFieldData& field) { 669 const FormFieldData& field) {
675 autofill_manager_->OnQueryFormFieldAutofill(query_id, 670 autofill_manager_->OnQueryFormFieldAutofill(query_id,
676 form, 671 form,
677 field, 672 field,
678 gfx::Rect(), 673 gfx::Rect(),
679 false); 674 false);
(...skipping 2268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2948 test::CreateTestAddressFormData(&form); 2943 test::CreateTestAddressFormData(&form);
2949 std::vector<FormData> forms(1, form); 2944 std::vector<FormData> forms(1, form);
2950 FormsSeen(forms); 2945 FormsSeen(forms);
2951 const FormFieldData& field = form.fields[0]; 2946 const FormFieldData& field = form.fields[0];
2952 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() 2947 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery()
2953 2948
2954 EXPECT_TRUE(external_delegate_->on_query_seen()); 2949 EXPECT_TRUE(external_delegate_->on_query_seen());
2955 } 2950 }
2956 2951
2957 } // namespace autofill 2952 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698