OLD | NEW |
---|---|
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/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 if (test_cases[i].form_control_type == "text") | 674 if (test_cases[i].form_control_type == "text") |
675 expected.max_length = WebInputElement::defaultMaxLength(); | 675 expected.max_length = WebInputElement::defaultMaxLength(); |
676 else | 676 else |
677 expected.max_length = 0; | 677 expected.max_length = 0; |
678 | 678 |
679 SCOPED_TRACE(test_cases[i].element_id); | 679 SCOPED_TRACE(test_cases[i].element_id); |
680 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); | 680 EXPECT_FORM_FIELD_DATA_EQUALS(expected, result); |
681 } | 681 } |
682 } | 682 } |
683 | 683 |
684 // Both text input and autocomplete should have same direction. | |
685 TEST_F(FormAutofillTest, | |
686 WebFormControlElementToFormFieldAutocompleteDirection) { | |
Ilya Sherman
2014/08/06 20:45:21
nit: This line should be indented more, like so:
| |
687 WebFrame* frame = NULL; | |
688 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" | |
689 "<FORM autocomplete=\"on\">" | |
690 " <INPUT type=\"text\" id=\"element\" value=\"RTL\"/>" | |
Ilya Sherman
2014/08/06 20:45:21
nit: It might be cleaner to use single quotes to s
Ilya Sherman
2014/08/06 20:45:21
nit: Please indent by two spaces, rather than by o
| |
691 "</FORM>"); | |
692 | |
693 frame = GetMainFrame(); | |
694 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
695 | |
696 WebElement web_element = frame->document().getElementById("element"); | |
697 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
698 | |
699 FormFieldData result1; | |
700 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result1); | |
701 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result1.text_direction); | |
702 | |
703 LoadHTML("<STYLE>span{direction:rtl}</STYLE>" | |
704 "<FORM autocomplete=\"on\">" | |
705 " <SPAN>" | |
706 " <INPUT type=\"text\" id=\"element\" value=\"RTL\"/>" | |
707 " </SPAN>" | |
708 "</FORM>"); | |
Ilya Sherman
2014/08/06 20:45:21
Please write separate TEST_F test cases for each H
| |
709 | |
710 frame = GetMainFrame(); | |
711 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
712 | |
713 web_element = frame->document().getElementById("element"); | |
714 element = web_element.to<WebFormControlElement>(); | |
715 FormFieldData result2; | |
716 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result2); | |
717 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result2.text_direction); | |
718 | |
719 LoadHTML("<FORM autocomplete=\"on\">" | |
720 " <SPAN>" | |
721 " <INPUT dir=\"rtl\" type=\"text\" id=\"element\" value=\"RTL\"/>" | |
722 " </SPAN>" | |
723 "</FORM>"); | |
724 | |
725 frame = GetMainFrame(); | |
726 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
727 | |
728 web_element = frame->document().getElementById("element"); | |
729 element = web_element.to<WebFormControlElement>(); | |
730 FormFieldData result3; | |
731 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result3); | |
732 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result3.text_direction); | |
733 | |
734 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" | |
735 "<FORM dir=\"rtl\" autocomplete=\"on\">" | |
736 " <INPUT type=\"text\" id=\"element\" value=\"LTR\"/>" | |
737 "</FORM>"); | |
738 | |
739 frame = GetMainFrame(); | |
740 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
741 | |
742 web_element = frame->document().getElementById("element"); | |
743 element = web_element.to<WebFormControlElement>(); | |
744 FormFieldData result4; | |
745 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result4); | |
746 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result4.text_direction); | |
747 | |
748 LoadHTML("<STYLE>span{direction:ltr}</STYLE>" | |
749 "<FORM autocomplete=\"on\">" | |
750 " <SPAN dir=\"rtl\">" | |
751 " <INPUT type=\"text\" id=\"element\" value=\"LTR\"/>" | |
752 " </SPAN>" | |
753 "</FORM>"); | |
754 | |
755 frame = GetMainFrame(); | |
756 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
757 | |
758 web_element = frame->document().getElementById("element"); | |
759 element = web_element.to<WebFormControlElement>(); | |
760 FormFieldData result5; | |
761 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result5); | |
762 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result5.text_direction); | |
763 | |
764 LoadHTML("<BODY dir=\"rtl\">" | |
765 "<FORM style=\"direction:ltr\" autocomplete=\"on\">" | |
766 " <SPAN dir=\"rtl\">" | |
767 " <INPUT dir=\"ltr\" type=\"text\" id=\"element\" value=\"LTR\"/>" | |
768 " </SPAN>" | |
769 "</FORM>"); | |
770 | |
771 frame = GetMainFrame(); | |
772 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
773 | |
774 web_element = frame->document().getElementById("element"); | |
775 element = web_element.to<WebFormControlElement>(); | |
776 FormFieldData result6; | |
777 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result6); | |
778 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result6.text_direction); | |
779 } | |
780 | |
684 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 781 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
685 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 782 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
686 " <LABEL for=\"firstname\">First name:</LABEL>" | 783 " <LABEL for=\"firstname\">First name:</LABEL>" |
687 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 784 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
688 " <LABEL for=\"lastname\">Last name:</LABEL>" | 785 " <LABEL for=\"lastname\">Last name:</LABEL>" |
689 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 786 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
690 " <LABEL for=\"street-address\">Address:</LABEL>" | 787 " <LABEL for=\"street-address\">Address:</LABEL>" |
691 " <TEXTAREA id=\"street-address\">" | 788 " <TEXTAREA id=\"street-address\">" |
692 "123 Fantasy Ln. " | 789 "123 Fantasy Ln. " |
693 "Apt. 42" | 790 "Apt. 42" |
(...skipping 2868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3562 expected.max_length = WebInputElement::defaultMaxLength(); | 3659 expected.max_length = WebInputElement::defaultMaxLength(); |
3563 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3660 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3564 | 3661 |
3565 expected.name = ASCIIToUTF16("country"); | 3662 expected.name = ASCIIToUTF16("country"); |
3566 expected.value = ASCIIToUTF16("AL"); | 3663 expected.value = ASCIIToUTF16("AL"); |
3567 expected.form_control_type = "select-one"; | 3664 expected.form_control_type = "select-one"; |
3568 expected.max_length = 0; | 3665 expected.max_length = 0; |
3569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3666 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3570 } | 3667 } |
3571 } // namespace autofill | 3668 } // namespace autofill |
OLD | NEW |