| OLD | NEW |
| 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/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 FakeContentAutofillDriver fake_driver_; | 199 FakeContentAutofillDriver fake_driver_; |
| 200 | 200 |
| 201 private: | 201 private: |
| 202 DISALLOW_COPY_AND_ASSIGN(FormAutocompleteTest); | 202 DISALLOW_COPY_AND_ASSIGN(FormAutocompleteTest); |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 // Tests that submitting a form generates WillSubmitForm and FormSubmitted | 205 // Tests that submitting a form generates WillSubmitForm and FormSubmitted |
| 206 // messages with the form fields. | 206 // messages with the form fields. |
| 207 TEST_F(FormAutocompleteTest, NormalFormSubmit) { | 207 TEST_F(FormAutocompleteTest, NormalFormSubmit) { |
| 208 // Load a form. | 208 // Load a form. |
| 209 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 209 LoadHTML( |
| 210 "<input name='lname' value='Deckard'/></form></html>"); | 210 "<html><form id='myForm' action='about:blank'>" |
| 211 "<input name='fname' value='Rick'/>" |
| 212 "<input name='lname' value='Deckard'/></form></html>"); |
| 211 | 213 |
| 212 // Submit the form. | 214 // Submit the form. |
| 213 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 215 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 214 ProcessPendingMessages(); | 216 ProcessPendingMessages(); |
| 215 | 217 |
| 216 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 218 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 217 true /* expect_submitted_message */); | 219 true /* expect_submitted_message */); |
| 218 } | 220 } |
| 219 | 221 |
| 220 // Tests that submitting a form that prevents the submit event from propagating | 222 // Tests that submitting a form that prevents the submit event from propagating |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 base::RunLoop run_loop; | 588 base::RunLoop run_loop; |
| 587 run_loop.RunUntilIdle(); | 589 run_loop.RunUntilIdle(); |
| 588 | 590 |
| 589 EXPECT_TRUE(fake_driver_.did_unfocus_form()); | 591 EXPECT_TRUE(fake_driver_.did_unfocus_form()); |
| 590 } | 592 } |
| 591 | 593 |
| 592 // Tests that submitting a form that has autocomplete="off" generates | 594 // Tests that submitting a form that has autocomplete="off" generates |
| 593 // WillSubmitForm and FormSubmitted messages. | 595 // WillSubmitForm and FormSubmitted messages. |
| 594 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { | 596 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |
| 595 // Load a form. | 597 // Load a form. |
| 596 LoadHTML("<html><form id='myForm' autocomplete='off'>" | 598 LoadHTML( |
| 597 "<input name='fname' value='Rick'/>" | 599 "<html><form id='myForm' autocomplete='off' action='about:blank'>" |
| 598 "<input name='lname' value='Deckard'/>" | 600 "<input name='fname' value='Rick'/>" |
| 599 "</form></html>"); | 601 "<input name='lname' value='Deckard'/>" |
| 602 "</form></html>"); |
| 600 | 603 |
| 601 // Submit the form. | 604 // Submit the form. |
| 602 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 605 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 603 ProcessPendingMessages(); | 606 ProcessPendingMessages(); |
| 604 | 607 |
| 605 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 608 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 606 true /* expect_submitted_message */); | 609 true /* expect_submitted_message */); |
| 607 } | 610 } |
| 608 | 611 |
| 609 // Tests that fields with autocomplete off are submitted. | 612 // Tests that fields with autocomplete off are submitted. |
| 610 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { | 613 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { |
| 611 // Load a form. | 614 // Load a form. |
| 612 LoadHTML("<html><form id='myForm'>" | 615 LoadHTML( |
| 613 "<input name='fname' value='Rick'/>" | 616 "<html><form id='myForm' action='about:blank'>" |
| 614 "<input name='lname' value='Deckard' autocomplete='off'/>" | 617 "<input name='fname' value='Rick'/>" |
| 615 "</form></html>"); | 618 "<input name='lname' value='Deckard' autocomplete='off'/>" |
| 619 "</form></html>"); |
| 616 | 620 |
| 617 // Submit the form. | 621 // Submit the form. |
| 618 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 622 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 619 ProcessPendingMessages(); | 623 ProcessPendingMessages(); |
| 620 | 624 |
| 621 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 625 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 622 true /* expect_submitted_message */); | 626 true /* expect_submitted_message */); |
| 623 } | 627 } |
| 624 | 628 |
| 625 // Tests that submitting a form that has been dynamically set as autocomplete | 629 // Tests that submitting a form that has been dynamically set as autocomplete |
| 626 // off generates WillSubmitForm and FormSubmitted messages. | 630 // off generates WillSubmitForm and FormSubmitted messages. |
| 627 // Note: We previously did the opposite, for bug http://crbug.com/36520 | 631 // Note: We previously did the opposite, for bug http://crbug.com/36520 |
| 628 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { | 632 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { |
| 629 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 633 LoadHTML( |
| 630 "<input name='lname' value='Deckard'/></form></html>"); | 634 "<html><form id='myForm' action='about:blank'>" |
| 635 "<input name='fname' value='Rick'/>" |
| 636 "<input name='lname' value='Deckard'/></form></html>"); |
| 631 | 637 |
| 632 WebElement element = | 638 WebElement element = |
| 633 GetMainFrame()->document().getElementById(blink::WebString("myForm")); | 639 GetMainFrame()->document().getElementById(blink::WebString("myForm")); |
| 634 ASSERT_FALSE(element.isNull()); | 640 ASSERT_FALSE(element.isNull()); |
| 635 blink::WebFormElement form = element.to<blink::WebFormElement>(); | 641 blink::WebFormElement form = element.to<blink::WebFormElement>(); |
| 636 EXPECT_TRUE(form.autoComplete()); | 642 EXPECT_TRUE(form.autoComplete()); |
| 637 | 643 |
| 638 // Dynamically mark the form as autocomplete off. | 644 // Dynamically mark the form as autocomplete off. |
| 639 ExecuteJavaScriptForTests( | 645 ExecuteJavaScriptForTests( |
| 640 "document.getElementById('myForm')." | 646 "document.getElementById('myForm')." |
| 641 "setAttribute('autocomplete', 'off');"); | 647 "setAttribute('autocomplete', 'off');"); |
| 642 ProcessPendingMessages(); | 648 ProcessPendingMessages(); |
| 643 EXPECT_FALSE(form.autoComplete()); | 649 EXPECT_FALSE(form.autoComplete()); |
| 644 | 650 |
| 645 // Submit the form. | 651 // Submit the form. |
| 646 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); | 652 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); |
| 647 ProcessPendingMessages(); | 653 ProcessPendingMessages(); |
| 648 | 654 |
| 649 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", | 655 VerifyReceivedRendererMessages(fake_driver_, "Rick", "Deckard", |
| 650 true /* expect_submitted_message */); | 656 true /* expect_submitted_message */); |
| 651 } | 657 } |
| 652 | 658 |
| 653 } // namespace autofill | 659 } // namespace autofill |
| OLD | NEW |