OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/tuple.h" | |
6 #include "base/utf_string_conversions.h" | |
7 #include "chrome/browser/autofill/autocheckout_manager.h" | |
8 #include "chrome/browser/autofill/autofill_common_test.h" | |
9 #include "chrome/browser/autofill/autofill_manager.h" | |
10 #include "chrome/browser/autofill/form_structure.h" | |
11 #include "chrome/browser/autofill/test_autofill_manager_delegate.h" | |
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
13 #include "components/autofill/common/autofill_messages.h" | |
14 #include "components/autofill/common/form_data.h" | |
15 #include "content/public/browser/browser_thread.h" | |
16 #include "content/public/test/mock_render_process_host.h" | |
17 #include "content/public/test/test_browser_thread.h" | |
18 #include "ipc/ipc_test_sink.h" | |
19 #include "testing/gmock/include/gmock/gmock.h" | |
20 #include "testing/gtest/include/gtest/gtest.h" | |
21 | |
22 | |
23 using content::BrowserThread; | |
24 | |
25 namespace autofill { | |
26 | |
27 namespace { | |
28 | |
29 typedef Tuple2<std::vector<FormData>, WebElementDescriptor> AutofillParam; | |
30 | |
31 FormFieldData BuildFieldWithValue( | |
32 const std::string& autocomplete_attribute, | |
33 const std::string& value) { | |
34 FormFieldData field; | |
35 field.name = ASCIIToUTF16(autocomplete_attribute); | |
36 field.value = ASCIIToUTF16(value); | |
37 field.autocomplete_attribute = autocomplete_attribute; | |
38 field.form_control_type = "text"; | |
39 return field; | |
40 } | |
41 | |
42 FormFieldData BuildField(const std::string& autocomplete_attribute) { | |
43 return BuildFieldWithValue(autocomplete_attribute, autocomplete_attribute); | |
44 } | |
45 | |
46 scoped_ptr<FormStructure> CreateTestFormStructure( | |
47 const std::vector<AutofillFieldType>& autofill_types) { | |
48 FormData form; | |
49 form.name = ASCIIToUTF16("MyForm"); | |
50 form.method = ASCIIToUTF16("POST"); | |
51 form.origin = GURL("https://myform.com/form.html"); | |
52 form.action = GURL("https://myform.com/submit.html"); | |
53 form.user_submitted = true; | |
54 | |
55 // Add some fields, autocomplete_attribute is not important and we | |
56 // fake that server sends authoritative field mappings. | |
57 for (size_t i = 0; i < autofill_types.size(); ++i) | |
58 form.fields.push_back(BuildField("SomeField")); | |
59 | |
60 scoped_ptr<FormStructure> form_structure( | |
61 new FormStructure(form, std::string())); | |
62 | |
63 // Set mocked Autofill server field types. | |
64 for (size_t i = 0; i < autofill_types.size(); ++i) | |
65 form_structure->field(i)->set_server_type(autofill_types[i]); | |
66 | |
67 return form_structure.Pass(); | |
68 } | |
69 | |
70 scoped_ptr<FormStructure> CreateTestAddressFormStructure() { | |
71 std::vector<AutofillFieldType> autofill_types; | |
72 autofill_types.push_back(NAME_FULL); | |
73 autofill_types.push_back(PHONE_HOME_WHOLE_NUMBER); | |
74 autofill_types.push_back(EMAIL_ADDRESS); | |
75 | |
76 return CreateTestFormStructure(autofill_types); | |
77 } | |
78 | |
79 scoped_ptr<FormStructure> CreateTestCreditCardFormStructure() { | |
80 std::vector<AutofillFieldType> autofill_types; | |
81 autofill_types.push_back(CREDIT_CARD_NAME); | |
82 autofill_types.push_back(CREDIT_CARD_NUMBER); | |
83 autofill_types.push_back(CREDIT_CARD_EXP_MONTH); | |
84 autofill_types.push_back(CREDIT_CARD_EXP_4_DIGIT_YEAR); | |
85 autofill_types.push_back(CREDIT_CARD_VERIFICATION_CODE); | |
86 autofill_types.push_back(ADDRESS_HOME_LINE1); | |
87 autofill_types.push_back(ADDRESS_HOME_CITY); | |
88 autofill_types.push_back(ADDRESS_HOME_STATE); | |
89 autofill_types.push_back(ADDRESS_HOME_COUNTRY); | |
90 autofill_types.push_back(ADDRESS_HOME_ZIP); | |
91 return CreateTestFormStructure(autofill_types); | |
92 } | |
93 | |
94 scoped_ptr<FormStructure> CreateTestFormStructureWithDefaultValues() { | |
95 FormData form; | |
96 form.name = ASCIIToUTF16("MyForm"); | |
97 form.method = ASCIIToUTF16("POST"); | |
98 form.origin = GURL("https://myform.com/form.html"); | |
99 form.action = GURL("https://myform.com/submit.html"); | |
100 form.user_submitted = true; | |
101 | |
102 // Add two radio button fields. | |
103 FormFieldData male = BuildFieldWithValue("sex", "male"); | |
104 male.is_checkable = true; | |
105 form.fields.push_back(male); | |
106 FormFieldData female = BuildFieldWithValue("sex", "female"); | |
107 female.is_checkable = true; | |
108 form.fields.push_back(female); | |
109 | |
110 scoped_ptr<FormStructure> form_structure( | |
111 new FormStructure(form, std::string())); | |
112 | |
113 // Fake server response. Set all fields as fields with default value. | |
114 form_structure->field(0)->set_server_type(FIELD_WITH_DEFAULT_VALUE); | |
115 form_structure->field(0)->set_default_value("female"); | |
116 form_structure->field(1)->set_server_type(FIELD_WITH_DEFAULT_VALUE); | |
117 form_structure->field(1)->set_default_value("female"); | |
118 | |
119 return form_structure.Pass(); | |
120 } | |
121 | |
122 scoped_ptr<WebElementDescriptor> CreateProceedElement() { | |
123 scoped_ptr<WebElementDescriptor> proceed_element(new WebElementDescriptor()); | |
124 proceed_element->descriptor = "#foo"; | |
125 proceed_element->retrieval_method = WebElementDescriptor::ID; | |
126 return proceed_element.Pass(); | |
127 } | |
128 | |
129 scoped_ptr<AutocheckoutPageMetaData> CreateStartOfFlowMetaData() { | |
130 scoped_ptr<AutocheckoutPageMetaData> start_of_flow( | |
131 new AutocheckoutPageMetaData()); | |
132 start_of_flow->current_page_number = 0; | |
133 start_of_flow->total_pages = 3; | |
134 start_of_flow->proceed_element_descriptor = CreateProceedElement().Pass(); | |
135 return start_of_flow.Pass(); | |
136 } | |
137 | |
138 scoped_ptr<AutocheckoutPageMetaData> CreateInFlowMetaData() { | |
139 scoped_ptr<AutocheckoutPageMetaData> in_flow(new AutocheckoutPageMetaData()); | |
140 in_flow->current_page_number = 1; | |
141 in_flow->total_pages = 3; | |
142 in_flow->proceed_element_descriptor = CreateProceedElement().Pass(); | |
143 return in_flow.Pass(); | |
144 } | |
145 | |
146 scoped_ptr<AutocheckoutPageMetaData> CreateEndOfFlowMetaData() { | |
147 scoped_ptr<AutocheckoutPageMetaData> end_of_flow( | |
148 new AutocheckoutPageMetaData()); | |
149 end_of_flow->current_page_number = 2; | |
150 end_of_flow->total_pages = 3; | |
151 return end_of_flow.Pass(); | |
152 } | |
153 | |
154 scoped_ptr<AutocheckoutPageMetaData> CreateMissingProceedMetaData() { | |
155 scoped_ptr<AutocheckoutPageMetaData> missing_proceed( | |
156 new AutocheckoutPageMetaData()); | |
157 missing_proceed->current_page_number = 1; | |
158 missing_proceed->total_pages = 3; | |
159 return missing_proceed.Pass(); | |
160 } | |
161 | |
162 struct TestField { | |
163 const char* const field_type; | |
164 const char* const field_value; | |
165 AutofillFieldType autofill_type; | |
166 }; | |
167 | |
168 const TestField kTestFields[] = { | |
169 {"name", "Test User", NAME_FULL}, | |
170 {"tel", "650-123-9909", PHONE_HOME_WHOLE_NUMBER}, | |
171 {"email", "blah@blah.com", EMAIL_ADDRESS}, | |
172 {"cc-name", "Test User", CREDIT_CARD_NAME}, | |
173 {"cc-number", "4444444444444448", CREDIT_CARD_NUMBER}, | |
174 {"cc-exp-month", "10", CREDIT_CARD_EXP_MONTH}, | |
175 {"cc-exp-year", "2020", CREDIT_CARD_EXP_4_DIGIT_YEAR}, | |
176 {"cc-csc", "123", CREDIT_CARD_VERIFICATION_CODE}, | |
177 {"street-address", "Fake Street", ADDRESS_HOME_LINE1}, | |
178 {"locality", "Mocked City", ADDRESS_HOME_CITY}, | |
179 {"region", "California", ADDRESS_HOME_STATE}, | |
180 {"country", "USA", ADDRESS_HOME_COUNTRY}, | |
181 {"postal-code", "49012", ADDRESS_HOME_ZIP} | |
182 }; | |
183 | |
184 // Build Autocheckout specific form data to be consumed by | |
185 // AutofillDialogController to show the Autocheckout specific UI. | |
186 scoped_ptr<FormStructure> FakeUserSubmittedFormStructure() { | |
187 FormData formdata; | |
188 for (size_t i = 0; i < arraysize(kTestFields); i++) { | |
189 formdata.fields.push_back( | |
190 BuildFieldWithValue(kTestFields[i].field_type, | |
191 kTestFields[i].field_value)); | |
192 } | |
193 scoped_ptr<FormStructure> form_structure; | |
194 form_structure.reset(new FormStructure(formdata, std::string())); | |
195 for (size_t i = 0; i < arraysize(kTestFields); ++i) | |
196 form_structure->field(i)->set_server_type(kTestFields[i].autofill_type); | |
197 | |
198 return form_structure.Pass(); | |
199 } | |
200 | |
201 class MockAutofillManagerDelegate : public TestAutofillManagerDelegate { | |
202 public: | |
203 MockAutofillManagerDelegate() | |
204 : request_autocomplete_dialog_open_(false), | |
205 autocheckout_bubble_shown_(false) {} | |
206 | |
207 virtual ~MockAutofillManagerDelegate() {} | |
208 | |
209 virtual void HideRequestAutocompleteDialog() OVERRIDE { | |
210 request_autocomplete_dialog_open_ = false; | |
211 } | |
212 | |
213 MOCK_METHOD0(OnAutocheckoutError, void()); | |
214 | |
215 virtual void ShowAutocheckoutBubble( | |
216 const gfx::RectF& bounds, | |
217 const gfx::NativeView& native_view, | |
218 const base::Closure& callback) OVERRIDE { | |
219 autocheckout_bubble_shown_ = true; | |
220 callback.Run(); | |
221 } | |
222 | |
223 virtual void ShowRequestAutocompleteDialog( | |
224 const FormData& form, | |
225 const GURL& source_url, | |
226 const content::SSLStatus& ssl_status, | |
227 const AutofillMetrics& metric_logger, | |
228 DialogType dialog_type, | |
229 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { | |
230 request_autocomplete_dialog_open_ = true; | |
231 callback.Run(user_supplied_data_.get()); | |
232 } | |
233 | |
234 MOCK_METHOD1(UpdateProgressBar, void(double value)); | |
235 | |
236 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { | |
237 user_supplied_data_.reset(user_supplied_data.release()); | |
238 } | |
239 | |
240 bool autocheckout_bubble_shown() const { | |
241 return autocheckout_bubble_shown_; | |
242 } | |
243 | |
244 void set_autocheckout_bubble_shown(bool autocheckout_bubble_shown) { | |
245 autocheckout_bubble_shown_ = autocheckout_bubble_shown; | |
246 } | |
247 | |
248 bool request_autocomplete_dialog_open() const { | |
249 return request_autocomplete_dialog_open_; | |
250 } | |
251 | |
252 private: | |
253 bool request_autocomplete_dialog_open_; | |
254 bool autocheckout_bubble_shown_; | |
255 scoped_ptr<FormStructure> user_supplied_data_; | |
256 }; | |
257 | |
258 class TestAutofillManager : public AutofillManager { | |
259 public: | |
260 explicit TestAutofillManager(content::WebContents* contents, | |
261 AutofillManagerDelegate* delegate) | |
262 : AutofillManager(contents, delegate, NULL) { | |
263 } | |
264 virtual ~TestAutofillManager() {} | |
265 | |
266 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { | |
267 form_structures()->clear(); | |
268 form_structures()->push_back(form_structure.release()); | |
269 } | |
270 }; | |
271 | |
272 | |
273 class TestAutocheckoutManager: public AutocheckoutManager { | |
274 public: | |
275 explicit TestAutocheckoutManager(AutofillManager* autofill_manager) | |
276 : AutocheckoutManager(autofill_manager) {} | |
277 | |
278 using AutocheckoutManager::in_autocheckout_flow; | |
279 using AutocheckoutManager::autocheckout_bubble_shown; | |
280 }; | |
281 | |
282 } // namespace | |
283 | |
284 class AutocheckoutManagerTest : public ChromeRenderViewHostTestHarness { | |
285 public: | |
286 AutocheckoutManagerTest() | |
287 : ChromeRenderViewHostTestHarness(), | |
288 ui_thread_(BrowserThread::UI, &message_loop_) { | |
289 } | |
290 | |
291 std::vector<FormData> ReadFilledForms() { | |
292 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | |
293 const IPC::Message* message = | |
294 process()->sink().GetFirstMessageMatching(kMsgID); | |
295 AutofillParam autofill_param; | |
296 AutofillMsg_FillFormsAndClick::Read(message, &autofill_param); | |
297 return autofill_param.a; | |
298 } | |
299 | |
300 void CheckIpcMessageSent() { | |
301 EXPECT_EQ(1U, process()->sink().message_count()); | |
302 uint32 kMsgID = AutofillMsg_FillFormsAndClick::ID; | |
303 const IPC::Message* message = | |
304 process()->sink().GetFirstMessageMatching(kMsgID); | |
305 EXPECT_TRUE(message); | |
306 ClearIpcSink(); | |
307 } | |
308 | |
309 void ClearIpcSink() { | |
310 process()->sink().ClearMessages(); | |
311 } | |
312 | |
313 void OpenRequestAutocompleteDialog() { | |
314 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
315 EXPECT_FALSE( | |
316 autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
317 autocheckout_manager_->OnLoadedPageMetaData(CreateStartOfFlowMetaData()); | |
318 // Simulate the user submitting some data via the requestAutocomplete UI. | |
319 autofill_manager_delegate_->SetUserSuppliedData( | |
320 FakeUserSubmittedFormStructure()); | |
321 GURL frame_url; | |
322 content::SSLStatus ssl_status; | |
323 EXPECT_CALL(*autofill_manager_delegate_, | |
324 UpdateProgressBar(testing::DoubleEq(1.0/3.0))).Times(1); | |
325 autocheckout_manager_->ShowAutocheckoutDialog(frame_url, ssl_status); | |
326 CheckIpcMessageSent(); | |
327 EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); | |
328 EXPECT_TRUE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
329 } | |
330 | |
331 void HideRequestAutocompleteDialog() { | |
332 EXPECT_TRUE( | |
333 autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
334 autofill_manager_delegate_->HideRequestAutocompleteDialog(); | |
335 EXPECT_FALSE( | |
336 autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
337 } | |
338 | |
339 protected: | |
340 content::TestBrowserThread ui_thread_; | |
341 scoped_ptr<TestAutofillManager> autofill_manager_; | |
342 scoped_ptr<TestAutocheckoutManager> autocheckout_manager_; | |
343 scoped_ptr<MockAutofillManagerDelegate> autofill_manager_delegate_; | |
344 | |
345 private: | |
346 virtual void SetUp() OVERRIDE { | |
347 ChromeRenderViewHostTestHarness::SetUp(); | |
348 autofill_manager_delegate_.reset(new MockAutofillManagerDelegate()); | |
349 autofill_manager_.reset(new TestAutofillManager( | |
350 web_contents(), | |
351 autofill_manager_delegate_.get())); | |
352 autocheckout_manager_.reset( | |
353 new TestAutocheckoutManager(autofill_manager_.get())); | |
354 } | |
355 | |
356 virtual void TearDown() OVERRIDE { | |
357 autocheckout_manager_.reset(); | |
358 autofill_manager_delegate_.reset(); | |
359 autofill_manager_.reset(); | |
360 ChromeRenderViewHostTestHarness::TearDown(); | |
361 } | |
362 | |
363 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); | |
364 }; | |
365 | |
366 TEST_F(AutocheckoutManagerTest, TestFillForms) { | |
367 OpenRequestAutocompleteDialog(); | |
368 | |
369 // Test if autocheckout manager can fill the first page. | |
370 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); | |
371 | |
372 autocheckout_manager_->FillForms(); | |
373 | |
374 std::vector<FormData> filled_forms = ReadFilledForms(); | |
375 ASSERT_EQ(1U, filled_forms.size()); | |
376 ASSERT_EQ(3U, filled_forms[0].fields.size()); | |
377 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); | |
378 EXPECT_EQ(ASCIIToUTF16("650-123-9909"), filled_forms[0].fields[1].value); | |
379 EXPECT_EQ(ASCIIToUTF16("blah@blah.com"), filled_forms[0].fields[2].value); | |
380 | |
381 filled_forms.clear(); | |
382 ClearIpcSink(); | |
383 | |
384 // Test if autocheckout manager can fill form on second page. | |
385 autofill_manager_->SetFormStructure(CreateTestCreditCardFormStructure()); | |
386 | |
387 autocheckout_manager_->FillForms(); | |
388 | |
389 filled_forms = ReadFilledForms(); | |
390 ASSERT_EQ(1U, filled_forms.size()); | |
391 ASSERT_EQ(10U, filled_forms[0].fields.size()); | |
392 EXPECT_EQ(ASCIIToUTF16("Test User"), filled_forms[0].fields[0].value); | |
393 EXPECT_EQ(ASCIIToUTF16("4444444444444448"), filled_forms[0].fields[1].value); | |
394 EXPECT_EQ(ASCIIToUTF16("10"), filled_forms[0].fields[2].value); | |
395 EXPECT_EQ(ASCIIToUTF16("2020"), filled_forms[0].fields[3].value); | |
396 EXPECT_EQ(ASCIIToUTF16("123"), filled_forms[0].fields[4].value); | |
397 EXPECT_EQ(ASCIIToUTF16("Fake Street"), filled_forms[0].fields[5].value); | |
398 EXPECT_EQ(ASCIIToUTF16("Mocked City"), filled_forms[0].fields[6].value); | |
399 EXPECT_EQ(ASCIIToUTF16("California"), filled_forms[0].fields[7].value); | |
400 EXPECT_EQ(ASCIIToUTF16("United States"), filled_forms[0].fields[8].value); | |
401 EXPECT_EQ(ASCIIToUTF16("49012"), filled_forms[0].fields[9].value); | |
402 | |
403 filled_forms.clear(); | |
404 ClearIpcSink(); | |
405 | |
406 // Test form with default values. | |
407 autofill_manager_->SetFormStructure( | |
408 CreateTestFormStructureWithDefaultValues()); | |
409 | |
410 autocheckout_manager_->FillForms(); | |
411 | |
412 filled_forms = ReadFilledForms(); | |
413 ASSERT_EQ(1U, filled_forms.size()); | |
414 ASSERT_EQ(2U, filled_forms[0].fields.size()); | |
415 EXPECT_FALSE(filled_forms[0].fields[0].is_checked); | |
416 EXPECT_EQ(ASCIIToUTF16("male"), filled_forms[0].fields[0].value); | |
417 EXPECT_TRUE(filled_forms[0].fields[1].is_checked); | |
418 EXPECT_EQ(ASCIIToUTF16("female"), filled_forms[0].fields[1].value); | |
419 } | |
420 | |
421 TEST_F(AutocheckoutManagerTest, OnFormsSeenTest) { | |
422 GURL frame_url; | |
423 content::SSLStatus ssl_status; | |
424 gfx::NativeView native_view; | |
425 gfx::RectF bounding_box; | |
426 EXPECT_TRUE(autocheckout_manager_->MaybeShowAutocheckoutBubble(frame_url, | |
427 ssl_status, | |
428 native_view, | |
429 bounding_box)); | |
430 EXPECT_TRUE(autocheckout_manager_->autocheckout_bubble_shown()); | |
431 // OnFormsSeen resets whether or not the bubble was shown. | |
432 autocheckout_manager_->OnFormsSeen(); | |
433 EXPECT_FALSE(autocheckout_manager_->autocheckout_bubble_shown()); | |
434 } | |
435 | |
436 TEST_F(AutocheckoutManagerTest, MaybeShowAutocheckoutBubbleTest) { | |
437 GURL frame_url; | |
438 content::SSLStatus ssl_status; | |
439 gfx::NativeView native_view; | |
440 gfx::RectF bounding_box; | |
441 // MaybeShowAutocheckoutBubble shows bubble if it has not been shown. | |
442 EXPECT_TRUE(autocheckout_manager_->MaybeShowAutocheckoutBubble(frame_url, | |
443 ssl_status, | |
444 native_view, | |
445 bounding_box)); | |
446 EXPECT_TRUE(autocheckout_manager_->autocheckout_bubble_shown()); | |
447 EXPECT_TRUE(autofill_manager_delegate_->autocheckout_bubble_shown()); | |
448 | |
449 // Reset |autofill_manager_delegate_|. | |
450 HideRequestAutocompleteDialog(); | |
451 autofill_manager_delegate_->set_autocheckout_bubble_shown(false); | |
452 | |
453 // MaybeShowAutocheckoutBubble does nothing if the bubble was already shown | |
454 // for the current page. | |
455 EXPECT_FALSE(autocheckout_manager_->MaybeShowAutocheckoutBubble( | |
456 frame_url, | |
457 ssl_status, | |
458 native_view, | |
459 bounding_box)); | |
460 EXPECT_TRUE(autocheckout_manager_->autocheckout_bubble_shown()); | |
461 EXPECT_FALSE(autofill_manager_delegate_->autocheckout_bubble_shown()); | |
462 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
463 } | |
464 | |
465 TEST_F(AutocheckoutManagerTest, OnLoadedPageMetaDataTest) { | |
466 // Gettting no meta data after any autocheckout page is an error. | |
467 OpenRequestAutocompleteDialog(); | |
468 EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); | |
469 autocheckout_manager_->OnLoadedPageMetaData( | |
470 scoped_ptr<AutocheckoutPageMetaData>()); | |
471 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
472 EXPECT_EQ(0U, process()->sink().message_count()); | |
473 HideRequestAutocompleteDialog(); | |
474 | |
475 // Getting start page twice in a row is an error. | |
476 OpenRequestAutocompleteDialog(); | |
477 EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); | |
478 autocheckout_manager_->OnLoadedPageMetaData(CreateStartOfFlowMetaData()); | |
479 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
480 EXPECT_EQ(0U, process()->sink().message_count()); | |
481 HideRequestAutocompleteDialog(); | |
482 | |
483 // A missing proceed element when not at the end of a flow is an error. | |
484 OpenRequestAutocompleteDialog(); | |
485 EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); | |
486 autocheckout_manager_->OnLoadedPageMetaData(CreateMissingProceedMetaData()); | |
487 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
488 EXPECT_EQ(0U, process()->sink().message_count()); | |
489 HideRequestAutocompleteDialog(); | |
490 | |
491 // Repeating a page is an error. | |
492 OpenRequestAutocompleteDialog(); | |
493 // Go to second page. | |
494 EXPECT_CALL(*autofill_manager_delegate_, | |
495 UpdateProgressBar(testing::DoubleEq(2.0/3.0))).Times(1); | |
496 autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); | |
497 EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); | |
498 CheckIpcMessageSent(); | |
499 EXPECT_CALL(*autofill_manager_delegate_, OnAutocheckoutError()).Times(1); | |
500 autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); | |
501 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
502 EXPECT_EQ(0U, process()->sink().message_count()); | |
503 HideRequestAutocompleteDialog(); | |
504 | |
505 // If not in flow, OnLoadedPageMetaData does not fill forms. | |
506 autocheckout_manager_->OnLoadedPageMetaData(CreateStartOfFlowMetaData()); | |
507 // Go to second page. | |
508 EXPECT_CALL(*autofill_manager_delegate_, | |
509 UpdateProgressBar(testing::_)).Times(0); | |
510 autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); | |
511 EXPECT_EQ(0U, process()->sink().message_count()); | |
512 | |
513 // Test for progression through last page. | |
514 OpenRequestAutocompleteDialog(); | |
515 // Go to second page. | |
516 EXPECT_CALL(*autofill_manager_delegate_, | |
517 UpdateProgressBar(testing::DoubleEq(2.0/3.0))).Times(1); | |
518 autocheckout_manager_->OnLoadedPageMetaData(CreateInFlowMetaData()); | |
519 EXPECT_TRUE(autocheckout_manager_->in_autocheckout_flow()); | |
520 CheckIpcMessageSent(); | |
521 // Go to third page. | |
522 EXPECT_CALL(*autofill_manager_delegate_, UpdateProgressBar(1)).Times(1); | |
523 autocheckout_manager_->OnLoadedPageMetaData(CreateEndOfFlowMetaData()); | |
524 CheckIpcMessageSent(); | |
525 EXPECT_FALSE(autocheckout_manager_->in_autocheckout_flow()); | |
526 EXPECT_FALSE(autofill_manager_delegate_->request_autocomplete_dialog_open()); | |
527 } | |
528 | |
529 } // namespace autofill | |
OLD | NEW |