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

Side by Side Diff: chrome/renderer/autofill/form_autocomplete_browsertest.cc

Issue 2065303002: Modifying Autofill Agent to use synthetic form (i.e., formless elements) when no form is present on… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding more tests Created 4 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
« no previous file with comments | « no previous file | components/autofill/content/renderer/autofill_agent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <tuple> 5 #include <tuple>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/test/base/chrome_render_view_test.h" 10 #include "chrome/test/base/chrome_render_view_test.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 AutofillHostMsg_WillSubmitForm::ID); 42 AutofillHostMsg_WillSubmitForm::ID);
43 const IPC::Message* submitted_message = 43 const IPC::Message* submitted_message =
44 render_thread->sink().GetFirstMessageMatching( 44 render_thread->sink().GetFirstMessageMatching(
45 AutofillHostMsg_FormSubmitted::ID); 45 AutofillHostMsg_FormSubmitted::ID);
46 ASSERT_TRUE(will_submit_message != NULL); 46 ASSERT_TRUE(will_submit_message != NULL);
47 ASSERT_EQ(expect_submitted_message, submitted_message != NULL); 47 ASSERT_EQ(expect_submitted_message, submitted_message != NULL);
48 48
49 // The tuple also includes a timestamp, which is ignored. 49 // The tuple also includes a timestamp, which is ignored.
50 std::tuple<FormData, base::TimeTicks> will_submit_forms; 50 std::tuple<FormData, base::TimeTicks> will_submit_forms;
51 AutofillHostMsg_WillSubmitForm::Read(will_submit_message, &will_submit_forms); 51 AutofillHostMsg_WillSubmitForm::Read(will_submit_message, &will_submit_forms);
52 ASSERT_EQ(2U, std::get<0>(will_submit_forms).fields.size()); 52 ASSERT_LE(2U, std::get<0>(will_submit_forms).fields.size());
53 53
54 FormFieldData& will_submit_form_field = 54 FormFieldData& will_submit_form_field =
55 std::get<0>(will_submit_forms).fields[0]; 55 std::get<0>(will_submit_forms).fields[0];
56 EXPECT_EQ(WebString("fname"), will_submit_form_field.name); 56 EXPECT_EQ(WebString("fname"), will_submit_form_field.name);
57 EXPECT_EQ(WebString(base::UTF8ToUTF16(fname)), will_submit_form_field.value); 57 EXPECT_EQ(WebString(base::UTF8ToUTF16(fname)), will_submit_form_field.value);
58 will_submit_form_field = std::get<0>(will_submit_forms).fields[1]; 58 will_submit_form_field = std::get<0>(will_submit_forms).fields[1];
59 EXPECT_EQ(WebString("lname"), will_submit_form_field.name); 59 EXPECT_EQ(WebString("lname"), will_submit_form_field.name);
60 EXPECT_EQ(WebString(base::UTF8ToUTF16(lname)), will_submit_form_field.value); 60 EXPECT_EQ(WebString(base::UTF8ToUTF16(lname)), will_submit_form_field.value);
61 61
62 if (expect_submitted_message) { 62 if (expect_submitted_message) {
63 std::tuple<FormData> submitted_forms; 63 std::tuple<FormData> submitted_forms;
64 AutofillHostMsg_FormSubmitted::Read(submitted_message, &submitted_forms); 64 AutofillHostMsg_FormSubmitted::Read(submitted_message, &submitted_forms);
65 ASSERT_EQ(2U, std::get<0>(submitted_forms).fields.size()); 65 ASSERT_LE(2U, std::get<0>(submitted_forms).fields.size());
66 66
67 FormFieldData& submitted_field = std::get<0>(submitted_forms).fields[0]; 67 FormFieldData& submitted_field = std::get<0>(submitted_forms).fields[0];
68 EXPECT_EQ(WebString("fname"), submitted_field.name); 68 EXPECT_EQ(WebString("fname"), submitted_field.name);
69 EXPECT_EQ(WebString(base::UTF8ToUTF16(fname)), submitted_field.value); 69 EXPECT_EQ(WebString(base::UTF8ToUTF16(fname)), submitted_field.value);
70 submitted_field = std::get<0>(submitted_forms).fields[1]; 70 submitted_field = std::get<0>(submitted_forms).fields[1];
71 EXPECT_EQ(WebString("lname"), submitted_field.name); 71 EXPECT_EQ(WebString("lname"), submitted_field.name);
72 EXPECT_EQ(WebString(base::UTF8ToUTF16(lname)), submitted_field.value); 72 EXPECT_EQ(WebString(base::UTF8ToUTF16(lname)), submitted_field.value);
73 } 73 }
74 } 74 }
75 75
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // Form still visible. 383 // Form still visible.
384 384
385 // Simulate an Ajax request completing. 385 // Simulate an Ajax request completing.
386 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded(); 386 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded();
387 ProcessPendingMessages(); 387 ProcessPendingMessages();
388 388
389 // No submission messages sent. 389 // No submission messages sent.
390 VerifyNoSubmitMessagesReceived(render_thread_.get()); 390 VerifyNoSubmitMessagesReceived(render_thread_.get());
391 } 391 }
392 392
393 // Tests that completing an Ajax request without a form present will still
394 // trigger submission, if all the inputs the user has modified disappear.
395 TEST_F(FormAutocompleteTest, AjaxSucceeded_FormlessElements) {
396 // Load a "form." Note that kRequiredFieldsForUpload fields are required
397 // for the formless logic to trigger, so we add a throwaway third field.
398 LoadHTML(
399 "<head><title>Checkout</title></head>"
400 "<input type='text' name='fname' id='fname'/>"
401 "<input type='text' name='lname' value='Puckett'/>"
402 "<input type='number' name='number' value='34'/>");
403
404 // Simulate user input.
405 WebDocument document = GetMainFrame()->document();
406 WebElement element = document.getElementById(WebString::fromUTF8("fname"));
407 ASSERT_FALSE(element.isNull());
408 WebInputElement fname_element = element.to<WebInputElement>();
409 SimulateUserInputChangeForElement(&fname_element, std::string("Kirby"));
410
411 // Remove element from view.
412 ExecuteJavaScriptForTests(
413 "var element = document.getElementById('fname');"
414 "element.style.display = 'none';");
415
416 // Simulate AJAX request.
417 static_cast<blink::WebAutofillClient*>(autofill_agent_)->ajaxSucceeded();
418 ProcessPendingMessages();
419
420 VerifyReceivedRendererMessages(render_thread_.get(), "Kirby", "Puckett",
421 /* expect_submitted_message = */ true);
422 }
423
424 // Unit test for CollectFormlessElements.
425 TEST_F(FormAutocompleteTest, CollectFormlessElements) {
426 LoadHTML(
427 "<html><title>Checkout</title></head>"
428 "<input type='text' name='text_input'/>"
429 "<input type='checkbox' name='check_input'/>"
430 "<input type='number' name='number_input'/>"
431 "<select name='select_input'/>"
432 " <option value='option_1'></option>"
433 " <option value='option_2'></option>"
434 "</select>"
435 "<form><input type='text' name='excluded'/></form>"
436 "</html>");
437
438 FormData result;
439 autofill_agent_->CollectFormlessElements(&result);
440
441 // Asserting size 4 also ensures that 'excluded' field inside <form> is not
442 // collected.
443 ASSERT_EQ(4U, result.fields.size());
444 EXPECT_EQ(WebString("text_input"), result.fields[0].name);
445 EXPECT_EQ(WebString("check_input"), result.fields[1].name);
446 EXPECT_EQ(WebString("number_input"), result.fields[2].name);
447 EXPECT_EQ(WebString("select_input"), result.fields[3].name);
448 }
449
393 // Test that a FocusNoLongerOnForm message is sent if focus goes from an 450 // Test that a FocusNoLongerOnForm message is sent if focus goes from an
394 // interacted form to an element outside the form. 451 // interacted form to an element outside the form.
395 TEST_F(FormAutocompleteTest, 452 TEST_F(FormAutocompleteTest,
396 InteractedFormNoLongerFocused_FocusNoLongerOnForm) { 453 InteractedFormNoLongerFocused_FocusNoLongerOnForm) {
397 // Load a form. 454 // Load a form.
398 LoadHTML( 455 LoadHTML(
399 "<html><input type='text' id='different'/>" 456 "<html><input type='text' id='different'/>"
400 "<form id='myForm' action='http://example.com/blade.php'>" 457 "<form id='myForm' action='http://example.com/blade.php'>"
401 "<input name='fname' id='fname' value='Bob'/>" 458 "<input name='fname' id='fname' value='Bob'/>"
402 "<input name='lname' value='Deckard'/><input type=submit></form></html>"); 459 "<input name='lname' value='Deckard'/><input type=submit></form></html>");
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 564
508 // Submit the form. 565 // Submit the form.
509 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 566 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();");
510 ProcessPendingMessages(); 567 ProcessPendingMessages();
511 568
512 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard", 569 VerifyReceivedRendererMessages(render_thread_.get(), "Rick", "Deckard",
513 true /* expect_submitted_message */); 570 true /* expect_submitted_message */);
514 } 571 }
515 572
516 } // namespace autofill 573 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | components/autofill/content/renderer/autofill_agent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698