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

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

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Nit Created 7 years, 6 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
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/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "chrome/browser/webdata/web_data_service_factory.h" 13 #include "chrome/browser/webdata/web_data_service_factory.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_browser_process.h" 15 #include "chrome/test/base/testing_browser_process.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "components/autofill/browser/autocomplete_history_manager.h" 17 #include "components/autofill/browser/autocomplete_history_manager.h"
18 #include "components/autofill/browser/autofill_external_delegate.h" 18 #include "components/autofill/browser/autofill_external_delegate.h"
19 #include "components/autofill/browser/autofill_manager.h" 19 #include "components/autofill/browser/autofill_manager.h"
20 #include "components/autofill/browser/test_autofill_driver.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/browser/webdata/autofill_webdata_service.h" 22 #include "components/autofill/browser/webdata/autofill_webdata_service.h"
22 #include "components/autofill/common/form_data.h" 23 #include "components/autofill/common/form_data.h"
23 #include "components/webdata/common/web_data_service_test_util.h" 24 #include "components/webdata/common/web_data_service_test_util.h"
24 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
25 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
29 30
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 } // namespace 94 } // namespace
94 95
95 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness { 96 class AutocompleteHistoryManagerTest : public ChromeRenderViewHostTestHarness {
96 protected: 97 protected:
97 virtual void SetUp() OVERRIDE { 98 virtual void SetUp() OVERRIDE {
98 ChromeRenderViewHostTestHarness::SetUp(); 99 ChromeRenderViewHostTestHarness::SetUp();
99 web_data_service_ = new MockWebDataService(); 100 web_data_service_ = new MockWebDataService();
100 WebDataServiceFactory::GetInstance()->SetTestingFactory( 101 WebDataServiceFactory::GetInstance()->SetTestingFactory(
101 profile(), MockWebDataServiceWrapperCurrent::Build); 102 profile(), MockWebDataServiceWrapperCurrent::Build);
102 autocomplete_manager_.reset(new AutocompleteHistoryManager(web_contents())); 103 autofill_driver_.reset(new TestAutofillDriver(web_contents()));
104 autocomplete_manager_.reset(
105 new AutocompleteHistoryManager(autofill_driver_.get()));
103 } 106 }
104 107
105 virtual void TearDown() OVERRIDE { 108 virtual void TearDown() OVERRIDE {
106 autocomplete_manager_.reset(); 109 autocomplete_manager_.reset();
107 web_data_service_ = NULL; 110 web_data_service_ = NULL;
108 ChromeRenderViewHostTestHarness::TearDown(); 111 ChromeRenderViewHostTestHarness::TearDown();
109 } 112 }
110 113
111 scoped_refptr<MockWebDataService> web_data_service_; 114 scoped_refptr<MockWebDataService> web_data_service_;
112 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_; 115 scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
116 scoped_ptr<AutofillDriver> autofill_driver_;
113 MockAutofillManagerDelegate manager_delegate; 117 MockAutofillManagerDelegate manager_delegate;
114 }; 118 };
115 119
116 // 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.
117 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) { 121 TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
118 FormData form; 122 FormData form;
119 form.name = ASCIIToUTF16("MyForm"); 123 form.name = ASCIIToUTF16("MyForm");
120 form.method = ASCIIToUTF16("POST"); 124 form.method = ASCIIToUTF16("POST");
121 form.origin = GURL("http://myform.com/form.html"); 125 form.origin = GURL("http://myform.com/form.html");
122 form.action = GURL("http://myform.com/submit.html"); 126 form.action = GURL("http://myform.com/submit.html");
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 void(int query_id, 215 void(int query_id,
212 const std::vector<base::string16>& autofill_values, 216 const std::vector<base::string16>& autofill_values,
213 const std::vector<base::string16>& autofill_labels, 217 const std::vector<base::string16>& autofill_labels,
214 const std::vector<base::string16>& autofill_icons, 218 const std::vector<base::string16>& autofill_icons,
215 const std::vector<int>& autofill_unique_ids)); 219 const std::vector<int>& autofill_unique_ids));
216 220
217 private: 221 private:
218 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); 222 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate);
219 }; 223 };
220 224
221 class AutocompleteHistoryManagerStubSend : public AutocompleteHistoryManager {
222 public:
223 explicit AutocompleteHistoryManagerStubSend(WebContents* web_contents)
224 : AutocompleteHistoryManager(web_contents) {}
225
226 // Increase visibility for testing.
227 void SendSuggestions(const std::vector<base::string16>* suggestions) {
228 AutocompleteHistoryManager::SendSuggestions(suggestions);
229 }
230
231 // Intentionally swallow the message.
232 virtual bool Send(IPC::Message* message) OVERRIDE {
233 delete message;
234 return true;
235 }
236 };
237
238 } // namespace 225 } // namespace
239 226
240 // Make sure our external delegate is called at the right time. 227 // Make sure our external delegate is called at the right time.
241 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) { 228 TEST_F(AutocompleteHistoryManagerTest, ExternalDelegate) {
242 // Local version with a stubbed out Send() 229 AutocompleteHistoryManager autocomplete_history_manager(
243 AutocompleteHistoryManagerStubSend autocomplete_history_manager( 230 autofill_driver_.get());
244 web_contents()); 231 autocomplete_history_manager.send_IPC_ = false;
245 232
246 AutofillManager::CreateForWebContentsAndDelegate( 233 AutofillManager::CreateForWebContentsAndDelegate(
247 web_contents(), 234 web_contents(),
235 autofill_driver_.get(),
248 &manager_delegate, 236 &manager_delegate,
249 "en-US", 237 "en-US",
250 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER); 238 AutofillManager::ENABLE_AUTOFILL_DOWNLOAD_MANAGER);
251 239
252 MockAutofillExternalDelegate external_delegate(web_contents()); 240 MockAutofillExternalDelegate external_delegate(web_contents());
253 autocomplete_history_manager.SetExternalDelegate(&external_delegate); 241 autocomplete_history_manager.SetExternalDelegate(&external_delegate);
254 242
255 // Should trigger a call to OnSuggestionsReturned, verified by the mock. 243 // Should trigger a call to OnSuggestionsReturned, verified by the mock.
256 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _)); 244 EXPECT_CALL(external_delegate, OnSuggestionsReturned(_, _, _, _, _));
257 autocomplete_history_manager.SendSuggestions(NULL); 245 autocomplete_history_manager.SendSuggestions(NULL);
258 } 246 }
259 247
260 } // namespace autofill 248 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698