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

Side by Side Diff: components/autofill/browser/autocomplete_history_manager_unittest.cc

Issue 12491017: Make WebDataService no longer depend on ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/prefs/testing_pref_service.h" 8 #include "base/prefs/testing_pref_service.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 18 matching lines...) Expand all
29 using testing::_; 29 using testing::_;
30 30
31 namespace { 31 namespace {
32 32
33 class MockWebDataService : public WebDataService { 33 class MockWebDataService : public WebDataService {
34 public: 34 public:
35 MockWebDataService() { 35 MockWebDataService() {
36 current_mock_web_data_service_ = this; 36 current_mock_web_data_service_ = this;
37 } 37 }
38 38
39 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { 39 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
40
41 static scoped_refptr<MockWebDataService> GetCurrent() {
42 if (!current_mock_web_data_service_) {
43 return new MockWebDataService();
44 }
40 return current_mock_web_data_service_; 45 return current_mock_web_data_service_;
41 } 46 }
42 47
43 virtual void ShutdownOnUIThread() OVERRIDE {}
44
45 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
46
47 protected: 48 protected:
48 virtual ~MockWebDataService() {} 49 virtual ~MockWebDataService() {}
49 50
50 private: 51 private:
51 // Keep track of the most recently created instance, so that it can be 52 // Keep track of the most recently created instance, so that it can be
52 // associated with the current profile when Build() is called. 53 // associated with the current profile when Build() is called.
53 static MockWebDataService* current_mock_web_data_service_; 54 static MockWebDataService* current_mock_web_data_service_;
54 }; 55 };
55 56
56 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; 57 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL;
57 58
59 class MockWebDataServiceWrapper : public WebDataServiceWrapper {
60 public:
61 static ProfileKeyedService* Build(Profile* profile) {
62 return new MockWebDataServiceWrapper();
63 }
64
65 MockWebDataServiceWrapper() {
66 }
67
68 void Shutdown() OVERRIDE {}
69
70 ~MockWebDataServiceWrapper() {}
71
72 scoped_refptr<WebDataService> GetWebData() OVERRIDE {
73 return MockWebDataService::GetCurrent();
74 }
75
76 };
77
58 class MockAutofillManagerDelegate 78 class MockAutofillManagerDelegate
59 : public autofill::TestAutofillManagerDelegate { 79 : public autofill::TestAutofillManagerDelegate {
60 public: 80 public:
61 MockAutofillManagerDelegate() {} 81 MockAutofillManagerDelegate() {}
62 virtual ~MockAutofillManagerDelegate() {} 82 virtual ~MockAutofillManagerDelegate() {}
63 virtual PrefService* GetPrefs() { return &prefs_; } 83 virtual PrefService* GetPrefs() { return &prefs_; }
64 84
65 private: 85 private:
66 TestingPrefServiceSimple prefs_; 86 TestingPrefServiceSimple prefs_;
67 87
68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 88 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
69 }; 89 };
70 90
71 } // namespace 91 } // namespace
72 92
73 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { 93 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
74 protected: 94 protected:
75 AutocompleteHistoryManagerTest() 95 AutocompleteHistoryManagerTest()
76 : db_thread_(BrowserThread::DB) { 96 : db_thread_(BrowserThread::DB) {
77 } 97 }
78 98
79 virtual void SetUp() OVERRIDE { 99 virtual void SetUp() OVERRIDE {
80 ChromeRenderViewHostTestHarness::SetUp(); 100 ChromeRenderViewHostTestHarness::SetUp();
81 web_data_service_ = new MockWebDataService(); 101 web_data_service_ = new MockWebDataService();
82 WebDataServiceFactory::GetInstance()->SetTestingFactory( 102 WebDataServiceFactory::GetInstance()->SetTestingFactory(
83 profile(), MockWebDataService::Build); 103 profile(), MockWebDataServiceWrapper::Build);
84 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); 104 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents()));
85 } 105 }
86 106
87 virtual void TearDown() OVERRIDE { 107 virtual void TearDown() OVERRIDE {
88 autocomplete_manager_.reset(); 108 autocomplete_manager_.reset();
89 web_data_service_ = NULL; 109 web_data_service_ = NULL;
90 ChromeRenderViewHostTestHarness::TearDown(); 110 ChromeRenderViewHostTestHarness::TearDown();
111
91 } 112 }
92 113
93 content::TestBrowserThread db_thread_; 114 content::TestBrowserThread db_thread_;
94 scoped_refptr<MockWebDataService> web_data_service_; 115 scoped_refptr<MockWebDataService> web_data_service_;
95 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; 116 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
96 MockAutofillManagerDelegate manager_delegate; 117 MockAutofillManagerDelegate manager_delegate;
97 }; 118 };
98 119
99 // Tests that credit card numbers are not sent to the WebDatabase to be saved. 120 // Tests that credit card numbers are not sent to the WebDatabase to be saved.
100 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { 121 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 AutofillManager::CreateForWebContentsAndDelegate( 250 AutofillManager::CreateForWebContentsAndDelegate(
230 web_contents(), &manager_delegate); 251 web_contents(), &manager_delegate);
231 252
232 MockAutofillExternalDelegate external_delegate(web_contents()); 253 MockAutofillExternalDelegate external_delegate(web_contents());
233 autocomplete_history_manager.SetExternalDelegate(&external_delegate); 254 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
234 255
235 // Should trigger a call to OnSuggestionsReturned, verified by the mock. 256 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
236 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); 257 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
237 autocomplete_history_manager.SendSuggestions(NULL); 258 autocomplete_history_manager.SendSuggestions(NULL);
238 } 259 }
OLDNEW
« chrome/browser/webdata/web_data_service_factory.h ('K') | « chrome/test/base/testing_profile.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698