OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "base/tuple.h" | 6 #include "base/tuple.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autofill/autocheckout_manager.h" | 8 #include "chrome/browser/autofill/autocheckout_manager.h" |
9 #include "chrome/browser/autofill/autofill_common_test.h" | 9 #include "chrome/browser/autofill/autofill_common_test.h" |
10 #include "chrome/browser/autofill/autofill_manager.h" | 10 #include "chrome/browser/autofill/autofill_manager.h" |
11 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 11 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
12 #include "chrome/browser/autofill/form_structure.h" | 12 #include "chrome/browser/autofill/form_structure.h" |
13 #include "chrome/common/autofill_messages.h" | 13 #include "chrome/common/autofill_messages.h" |
14 #include "chrome/common/form_data.h" | 14 #include "chrome/common/form_data.h" |
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/test/mock_render_process_host.h" | 17 #include "content/public/test/mock_render_process_host.h" |
18 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
19 #include "ipc/ipc_test_sink.h" | 19 #include "ipc/ipc_test_sink.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 | 23 |
24 using content::BrowserThread; | 24 using content::BrowserThread; |
25 | 25 |
| 26 namespace autofill { |
| 27 |
26 namespace { | 28 namespace { |
27 | 29 |
28 typedef Tuple2<std::vector<FormData>, | 30 typedef Tuple2<std::vector<FormData>, WebElementDescriptor> AutofillParam; |
29 autofill::WebElementDescriptor> AutofillParam; | |
30 | 31 |
31 FormFieldData BuildFieldWithValue( | 32 FormFieldData BuildFieldWithValue( |
32 const std::string& autocomplete_attribute, | 33 const std::string& autocomplete_attribute, |
33 const std::string& value) { | 34 const std::string& value) { |
34 FormFieldData field; | 35 FormFieldData field; |
35 field.name = ASCIIToUTF16(autocomplete_attribute); | 36 field.name = ASCIIToUTF16(autocomplete_attribute); |
36 field.value = ASCIIToUTF16(value); | 37 field.value = ASCIIToUTF16(value); |
37 field.autocomplete_attribute = autocomplete_attribute; | 38 field.autocomplete_attribute = autocomplete_attribute; |
38 field.form_control_type = "text"; | 39 field.form_control_type = "text"; |
39 return field; | 40 return field; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 kTestFields[i].field_value)); | 123 kTestFields[i].field_value)); |
123 } | 124 } |
124 scoped_ptr<FormStructure> form_structure; | 125 scoped_ptr<FormStructure> form_structure; |
125 form_structure.reset(new FormStructure(formdata)); | 126 form_structure.reset(new FormStructure(formdata)); |
126 for (size_t i = 0; i < arraysize(kTestFields); ++i) | 127 for (size_t i = 0; i < arraysize(kTestFields); ++i) |
127 form_structure->field(i)->set_server_type(kTestFields[i].autofill_type); | 128 form_structure->field(i)->set_server_type(kTestFields[i].autofill_type); |
128 | 129 |
129 return form_structure.Pass(); | 130 return form_structure.Pass(); |
130 } | 131 } |
131 | 132 |
132 class TestAutofillManagerDelegate : public autofill::AutofillManagerDelegate { | 133 class TestAutofillManagerDelegate : public AutofillManagerDelegate { |
133 public: | 134 public: |
134 explicit TestAutofillManagerDelegate( | 135 explicit TestAutofillManagerDelegate( |
135 content::BrowserContext* browser_context) | 136 content::BrowserContext* browser_context) |
136 : browser_context_(browser_context) { | 137 : browser_context_(browser_context) { |
137 } | 138 } |
138 | 139 |
139 virtual ~TestAutofillManagerDelegate() { | 140 virtual ~TestAutofillManagerDelegate() { |
140 } | 141 } |
141 | 142 |
142 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { | 143 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { |
(...skipping 23 matching lines...) Expand all Loading... |
166 virtual bool IsSavingPasswordsEnabled() const OVERRIDE { | 167 virtual bool IsSavingPasswordsEnabled() const OVERRIDE { |
167 return false; | 168 return false; |
168 } | 169 } |
169 | 170 |
170 virtual void ShowAutofillSettings() OVERRIDE { | 171 virtual void ShowAutofillSettings() OVERRIDE { |
171 } | 172 } |
172 | 173 |
173 virtual void ShowPasswordGenerationBubble( | 174 virtual void ShowPasswordGenerationBubble( |
174 const gfx::Rect& bounds, | 175 const gfx::Rect& bounds, |
175 const content::PasswordForm& form, | 176 const content::PasswordForm& form, |
176 autofill::PasswordGenerator* generator) OVERRIDE { | 177 PasswordGenerator* generator) OVERRIDE { |
177 } | 178 } |
178 | 179 |
179 virtual void ShowRequestAutocompleteDialog( | 180 virtual void ShowRequestAutocompleteDialog( |
180 const FormData& form, | 181 const FormData& form, |
181 const GURL& source_url, | 182 const GURL& source_url, |
182 const content::SSLStatus& ssl_status, | 183 const content::SSLStatus& ssl_status, |
| 184 const AutofillMetrics& metric_logger, |
| 185 DialogType dialog_type, |
183 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { | 186 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { |
184 } | 187 } |
185 | 188 |
186 virtual void RequestAutocompleteDialogClosed() OVERRIDE { | 189 virtual void RequestAutocompleteDialogClosed() OVERRIDE { |
187 } | 190 } |
188 | 191 |
189 private: | 192 private: |
190 content::BrowserContext* browser_context_; | 193 content::BrowserContext* browser_context_; |
191 }; | 194 }; |
192 | 195 |
193 class TestAutofillManager : public AutofillManager { | 196 class TestAutofillManager : public AutofillManager { |
194 public: | 197 public: |
195 explicit TestAutofillManager(content::WebContents* contents, | 198 explicit TestAutofillManager(content::WebContents* contents, |
196 autofill::AutofillManagerDelegate* delegate) | 199 AutofillManagerDelegate* delegate) |
197 : AutofillManager(contents, delegate, NULL) { | 200 : AutofillManager(contents, delegate, NULL) { |
198 } | 201 } |
199 | 202 |
200 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { | 203 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { |
201 user_supplied_data_.reset(user_supplied_data.release()); | 204 user_supplied_data_.reset(user_supplied_data.release()); |
202 } | 205 } |
203 | 206 |
204 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { | 207 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { |
205 form_structures()->clear(); | 208 form_structures()->clear(); |
206 form_structures()->push_back(form_structure.release()); | 209 form_structures()->push_back(form_structure.release()); |
207 } | 210 } |
208 | 211 |
209 virtual void ShowRequestAutocompleteDialog( | 212 virtual void ShowRequestAutocompleteDialog( |
210 const FormData& form, | 213 const FormData& form, |
211 const GURL& source_url, | 214 const GURL& source_url, |
212 const content::SSLStatus& ssl_status, | 215 const content::SSLStatus& ssl_status, |
| 216 DialogType dialog_type, |
213 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { | 217 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { |
214 callback.Run(user_supplied_data_.get()); | 218 callback.Run(user_supplied_data_.get()); |
215 } | 219 } |
216 | 220 |
217 private: | 221 private: |
218 scoped_ptr<FormStructure> user_supplied_data_; | 222 scoped_ptr<FormStructure> user_supplied_data_; |
219 virtual ~TestAutofillManager() {} | 223 virtual ~TestAutofillManager() {} |
220 }; | 224 }; |
221 | 225 |
222 } // namespace | 226 } // namespace |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 ChromeRenderViewHostTestHarness::TearDown(); | 269 ChromeRenderViewHostTestHarness::TearDown(); |
266 } | 270 } |
267 | 271 |
268 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); | 272 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); |
269 }; | 273 }; |
270 | 274 |
271 TEST_F(AutocheckoutManagerTest, TestFillForms) { | 275 TEST_F(AutocheckoutManagerTest, TestFillForms) { |
272 // Simulate the user submitting some data via the requestAutocomplete UI. | 276 // Simulate the user submitting some data via the requestAutocomplete UI. |
273 autofill_manager_->SetUserSuppliedData(FakeUserSubmittedFormStructure()); | 277 autofill_manager_->SetUserSuppliedData(FakeUserSubmittedFormStructure()); |
274 autocheckout_manager_->SetProceedElementDescriptor( | 278 autocheckout_manager_->SetProceedElementDescriptor( |
275 autofill::WebElementDescriptor()); | 279 WebElementDescriptor()); |
276 GURL frame_url; | 280 GURL frame_url; |
277 content::SSLStatus ssl_status; | 281 content::SSLStatus ssl_status; |
278 autocheckout_manager_->ShowAutocheckoutDialog(frame_url, ssl_status); | 282 autocheckout_manager_->ShowAutocheckoutDialog(frame_url, ssl_status); |
279 | 283 |
280 ClearIpcSink(); | 284 ClearIpcSink(); |
281 | 285 |
282 // Test if autocheckout manager can fill the first page. | 286 // Test if autocheckout manager can fill the first page. |
283 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | 287 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); |
284 | 288 |
285 autocheckout_manager_->FillForms(); | 289 autocheckout_manager_->FillForms(); |
286 | 290 |
287 std::vector<FormData> filled_forms = ReadFilledForms(); | 291 std::vector<FormData> filled_forms = ReadFilledForms(); |
288 ASSERT_EQ(1U, filled_forms.size()); | 292 ASSERT_EQ(1U, filled_forms.size()); |
289 ASSERT_EQ(3U, filled_forms[0].fields.size()); | 293 ASSERT_EQ(3U, filled_forms[0].fields.size()); |
290 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); | 294 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); |
291 EXPECT_EQ(ASCIIToUTF16("650-123-9909"), filled_forms[0].fields[1].value); | 295 EXPECT_EQ(ASCIIToUTF16("650-123-9909"), filled_forms[0].fields[1].value); |
292 EXPECT_EQ(ASCIIToUTF16("blah@blah.com"), filled_forms[0].fields[2].value); | 296 EXPECT_EQ(ASCIIToUTF16("blah@blah.com"), filled_forms[0].fields[2].value); |
293 | 297 |
294 filled_forms.clear(); | 298 filled_forms.clear(); |
295 ClearIpcSink(); | 299 ClearIpcSink(); |
296 | 300 |
297 // Test if autocheckout manager can fill form on second page. | 301 // Test if autocheckout manager can fill form on second page. |
298 autofill_manager_->SetFormStructure(CreateTestCreditCardFormStructure()); | 302 autofill_manager_->SetFormStructure(CreateTestCreditCardFormStructure()); |
299 autocheckout_manager_->SetProceedElementDescriptor( | 303 autocheckout_manager_->SetProceedElementDescriptor( |
300 autofill::WebElementDescriptor()); | 304 WebElementDescriptor()); |
301 | 305 |
302 autocheckout_manager_->FillForms(); | 306 autocheckout_manager_->FillForms(); |
303 | 307 |
304 filled_forms = ReadFilledForms(); | 308 filled_forms = ReadFilledForms(); |
305 ASSERT_EQ(1U, filled_forms.size()); | 309 ASSERT_EQ(1U, filled_forms.size()); |
306 ASSERT_EQ(10U, filled_forms[0].fields.size()); | 310 ASSERT_EQ(10U, filled_forms[0].fields.size()); |
307 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); | 311 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); |
308 EXPECT_EQ(ASCIIToUTF16("4444444444444448"), filled_forms[0].fields[1].value); | 312 EXPECT_EQ(ASCIIToUTF16("4444444444444448"), filled_forms[0].fields[1].value); |
309 EXPECT_EQ(ASCIIToUTF16("10"), filled_forms[0].fields[2].value); | 313 EXPECT_EQ(ASCIIToUTF16("10"), filled_forms[0].fields[2].value); |
310 EXPECT_EQ(ASCIIToUTF16("2020"), filled_forms[0].fields[3].value); | 314 EXPECT_EQ(ASCIIToUTF16("2020"), filled_forms[0].fields[3].value); |
311 EXPECT_EQ(ASCIIToUTF16("123"), filled_forms[0].fields[4].value); | 315 EXPECT_EQ(ASCIIToUTF16("123"), filled_forms[0].fields[4].value); |
312 EXPECT_EQ(ASCIIToUTF16("Fake Street"), filled_forms[0].fields[5].value); | 316 EXPECT_EQ(ASCIIToUTF16("Fake Street"), filled_forms[0].fields[5].value); |
313 EXPECT_EQ(ASCIIToUTF16("Mocked City"), filled_forms[0].fields[6].value); | 317 EXPECT_EQ(ASCIIToUTF16("Mocked City"), filled_forms[0].fields[6].value); |
314 EXPECT_EQ(ASCIIToUTF16("California"), filled_forms[0].fields[7].value); | 318 EXPECT_EQ(ASCIIToUTF16("California"), filled_forms[0].fields[7].value); |
315 EXPECT_EQ(ASCIIToUTF16("United States"), filled_forms[0].fields[8].value); | 319 EXPECT_EQ(ASCIIToUTF16("United States"), filled_forms[0].fields[8].value); |
316 EXPECT_EQ(ASCIIToUTF16("49012"), filled_forms[0].fields[9].value); | 320 EXPECT_EQ(ASCIIToUTF16("49012"), filled_forms[0].fields[9].value); |
317 } | 321 } |
| 322 |
| 323 } // namespace autofill |
OLD | NEW |