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

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

Issue 12805007: wd5-syncableServices for try only (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wd5-syncableServices with debug test fix 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"
11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" 11 #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
12 #include "chrome/browser/webdata/web_data_service.h" 12 #include "chrome/browser/webdata/web_data_service.h"
13 #include "chrome/browser/webdata/web_data_service_factory.h" 13 #include "chrome/browser/webdata/web_data_service_factory.h"
14 #include "chrome/browser/webdata/web_data_service_test_util.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_browser_process.h" 16 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "components/autofill/browser/autocomplete_history_manager.h" 18 #include "components/autofill/browser/autocomplete_history_manager.h"
18 #include "components/autofill/browser/autofill_external_delegate.h" 19 #include "components/autofill/browser/autofill_external_delegate.h"
19 #include "components/autofill/browser/autofill_manager.h" 20 #include "components/autofill/browser/autofill_manager.h"
20 #include "components/autofill/browser/test_autofill_manager_delegate.h" 21 #include "components/autofill/browser/test_autofill_manager_delegate.h"
21 #include "components/autofill/common/form_data.h" 22 #include "components/autofill/common/form_data.h"
22 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "ui/gfx/rect.h" 26 #include "ui/gfx/rect.h"
26 27
27 using content::BrowserThread; 28 using content::BrowserThread;
28 using content::WebContents; 29 using content::WebContents;
29 using testing::_; 30 using testing::_;
30 31
31 namespace { 32 namespace {
32 33
33 class MockWebDataService : public WebDataService { 34 class MockWebDataService : public WebDataService {
34 public: 35 public:
35 MockWebDataService() { 36 MockWebDataService() {
36 current_mock_web_data_service_ = this; 37 current_mock_web_data_service_ = this;
37 } 38 }
38 39
39 static scoped_refptr<RefcountedProfileKeyedService> Build(Profile* profile) { 40 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
41
42 static scoped_refptr<MockWebDataService> GetCurrent() {
43 if (!current_mock_web_data_service_) {
44 return new MockWebDataService();
45 }
40 return current_mock_web_data_service_; 46 return current_mock_web_data_service_;
41 } 47 }
42 48
43 virtual void ShutdownOnUIThread() OVERRIDE {}
44
45 MOCK_METHOD1(AddFormFields, void(const std::vector<FormFieldData>&));
46
47 protected: 49 protected:
48 virtual ~MockWebDataService() {} 50 virtual ~MockWebDataService() {}
49 51
50 private: 52 private:
51 // Keep track of the most recently created instance, so that it can be 53 // Keep track of the most recently created instance, so that it can be
52 // associated with the current profile when Build() is called. 54 // associated with the current profile when Build() is called.
53 static MockWebDataService* current_mock_web_data_service_; 55 static MockWebDataService* current_mock_web_data_service_;
54 }; 56 };
55 57
56 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL; 58 MockWebDataService* MockWebDataService::current_mock_web_data_service_ = NULL;
57 59
60 class MockWebDataServiceWrapperCurrent : public MockWebDataServiceWrapperBase {
61 public:
62 static ProfileKeyedService* Build(Profile* profile) {
63 return new MockWebDataServiceWrapperCurrent();
64 }
65
66 MockWebDataServiceWrapperCurrent() {}
67
68 scoped_refptr<WebDataService> GetWebData() OVERRIDE {
69 return MockWebDataService::GetCurrent();
70 }
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(MockWebDataServiceWrapperCurrent);
74 };
75
58 class MockAutofillManagerDelegate 76 class MockAutofillManagerDelegate
59 : public autofill::TestAutofillManagerDelegate { 77 : public autofill::TestAutofillManagerDelegate {
60 public: 78 public:
61 MockAutofillManagerDelegate() {} 79 MockAutofillManagerDelegate() {}
62 virtual ~MockAutofillManagerDelegate() {} 80 virtual ~MockAutofillManagerDelegate() {}
63 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } 81 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; }
64 82
65 private: 83 private:
66 TestingPrefServiceSimple prefs_; 84 TestingPrefServiceSimple prefs_;
67 85
68 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate); 86 DISALLOW_COPY_AND_ASSIGN(MockAutofillManagerDelegate);
69 }; 87 };
70 88
71 } // namespace 89 } // namespace
72 90
73 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { 91 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
74 protected: 92 protected:
75 AutocompleteHistoryManagerTest() 93 AutocompleteHistoryManagerTest()
76 : db_thread_(BrowserThread::DB) { 94 : ui_thread_(BrowserThread::UI, &message_loop_),
95 db_thread_(BrowserThread::DB) {
77 } 96 }
78 97
79 virtual void SetUp() OVERRIDE { 98 virtual void SetUp() OVERRIDE {
80 ChromeRenderViewHostTestHarness::SetUp(); 99 ChromeRenderViewHostTestHarness::SetUp();
81 web_data_service_ = new MockWebDataService(); 100 web_data_service_ = new MockWebDataService();
82 WebDataServiceFactory::GetInstance()->SetTestingFactory( 101 WebDataServiceFactory::GetInstance()->SetTestingFactory(
83 profile(), MockWebDataService::Build); 102 profile(), MockWebDataServiceWrapperCurrent::Build);
84 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); 103 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents()));
85 } 104 }
86 105
87 virtual void TearDown() OVERRIDE { 106 virtual void TearDown() OVERRIDE {
88 autocomplete_manager_.reset(); 107 autocomplete_manager_.reset();
89 web_data_service_ = NULL; 108 web_data_service_ = NULL;
90 ChromeRenderViewHostTestHarness::TearDown(); 109 ChromeRenderViewHostTestHarness::TearDown();
110 message_loop_.RunUntilIdle();
111
91 } 112 }
92 113
114 content::TestBrowserThread ui_thread_;
93 content::TestBrowserThread db_thread_; 115 content::TestBrowserThread db_thread_;
94 scoped_refptr<MockWebDataService> web_data_service_; 116 scoped_refptr<MockWebDataService> web_data_service_;
95 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; 117 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
96 MockAutofillManagerDelegate manager_delegate; 118 MockAutofillManagerDelegate manager_delegate;
97 }; 119 };
98 120
99 // Tests that credit card numbers are not sent to the WebDatabase to be saved. 121 // Tests that credit card numbers are not sent to the WebDatabase to be saved.
100 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { 122 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
101 FormData form; 123 FormData form;
102 form.name = ASCIIToUTF16("MyForm"); 124 form.name = ASCIIToUTF16("MyForm");
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 AutofillManager::CreateForWebContentsAndDelegate( 251 AutofillManager::CreateForWebContentsAndDelegate(
230 web_contents(), &manager_delegate); 252 web_contents(), &manager_delegate);
231 253
232 MockAutofillExternalDelegate external_delegate(web_contents()); 254 MockAutofillExternalDelegate external_delegate(web_contents());
233 autocomplete_history_manager.SetExternalDelegate(&external_delegate); 255 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
234 256
235 // Should trigger a call to OnSuggestionsReturned, verified by the mock. 257 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
236 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); 258 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
237 autocomplete_history_manager.SendSuggestions(NULL); 259 autocomplete_history_manager.SendSuggestions(NULL);
238 } 260 }
OLDNEW
« no previous file with comments | « components/autofill/browser/autocomplete_history_manager.h ('k') | components/autofill/browser/personal_data_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698