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 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { |
| 685 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" |
| 686 "<FORM>" |
| 687 " <INPUT type='text' id='element'>" |
| 688 "</FORM>"); |
| 689 |
| 690 WebFrame* frame = GetMainFrame(); |
| 691 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 692 |
| 693 WebElement web_element = frame->document().getElementById("element"); |
| 694 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 695 |
| 696 FormFieldData result; |
| 697 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 698 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 699 } |
| 700 |
| 701 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { |
| 702 LoadHTML("<FORM>" |
| 703 " <INPUT dir='rtl' type='text' id='element'/>" |
| 704 "</FORM>"); |
| 705 |
| 706 WebFrame* frame = GetMainFrame(); |
| 707 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 708 |
| 709 WebElement web_element = frame->document().getElementById("element"); |
| 710 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 711 |
| 712 FormFieldData result; |
| 713 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 714 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 715 } |
| 716 |
| 717 TEST_F(FormAutofillTest, DetectTextDirectionFromParentStyle) { |
| 718 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" |
| 719 "<FORM>" |
| 720 " <INPUT type='text' id='element'/>" |
| 721 "</FORM>"); |
| 722 |
| 723 WebFrame* frame = GetMainFrame(); |
| 724 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 725 |
| 726 WebElement web_element = frame->document().getElementById("element"); |
| 727 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 728 |
| 729 FormFieldData result; |
| 730 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 731 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 732 } |
| 733 |
| 734 TEST_F(FormAutofillTest, DetectTextDirectionFromParentDIRAttribute) { |
| 735 LoadHTML("<FORM dir='rtl'>" |
| 736 " <INPUT type='text' id='element'/>" |
| 737 "</FORM>"); |
| 738 |
| 739 WebFrame* frame = GetMainFrame(); |
| 740 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 741 |
| 742 WebElement web_element = frame->document().getElementById("element"); |
| 743 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 744 |
| 745 FormFieldData result; |
| 746 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 747 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 748 } |
| 749 |
| 750 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { |
| 751 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" |
| 752 "<FORM dir='rtl'>" |
| 753 " <INPUT type='text' id='element'/>" |
| 754 "</FORM>"); |
| 755 |
| 756 WebFrame* frame = GetMainFrame(); |
| 757 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 758 |
| 759 WebElement web_element = frame->document().getElementById("element"); |
| 760 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 761 |
| 762 FormFieldData result; |
| 763 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 764 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 765 } |
| 766 |
| 767 TEST_F(FormAutofillTest, |
| 768 DetectTextDirectionWhenParentHasBothDIRAttributeAndStyle) { |
| 769 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" |
| 770 "<FORM dir='rtl'>" |
| 771 " <INPUT type='text' id='element'/>" |
| 772 "</FORM>"); |
| 773 |
| 774 WebFrame* frame = GetMainFrame(); |
| 775 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 776 |
| 777 WebElement web_element = frame->document().getElementById("element"); |
| 778 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 779 |
| 780 FormFieldData result; |
| 781 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 782 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); |
| 783 } |
| 784 |
| 785 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHasInlineStyle) { |
| 786 LoadHTML("<FORM style='direction:ltr'>" |
| 787 " <SPAN dir='rtl'>" |
| 788 " <INPUT type='text' id='element'/>" |
| 789 " </SPAN>" |
| 790 "</FORM>"); |
| 791 |
| 792 WebFrame* frame = GetMainFrame(); |
| 793 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); |
| 794 |
| 795 WebElement web_element = frame->document().getElementById("element"); |
| 796 WebFormControlElement element = web_element.to<WebFormControlElement>(); |
| 797 |
| 798 FormFieldData result; |
| 799 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); |
| 800 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); |
| 801 } |
| 802 |
684 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 803 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
685 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 804 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
686 " <LABEL for=\"firstname\">First name:</LABEL>" | 805 " <LABEL for=\"firstname\">First name:</LABEL>" |
687 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 806 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
688 " <LABEL for=\"lastname\">Last name:</LABEL>" | 807 " <LABEL for=\"lastname\">Last name:</LABEL>" |
689 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 808 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
690 " <LABEL for=\"street-address\">Address:</LABEL>" | 809 " <LABEL for=\"street-address\">Address:</LABEL>" |
691 " <TEXTAREA id=\"street-address\">" | 810 " <TEXTAREA id=\"street-address\">" |
692 "123 Fantasy Ln. " | 811 "123 Fantasy Ln. " |
693 "Apt. 42" | 812 "Apt. 42" |
(...skipping 2868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3562 expected.max_length = WebInputElement::defaultMaxLength(); | 3681 expected.max_length = WebInputElement::defaultMaxLength(); |
3563 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3682 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
3564 | 3683 |
3565 expected.name = ASCIIToUTF16("country"); | 3684 expected.name = ASCIIToUTF16("country"); |
3566 expected.value = ASCIIToUTF16("AL"); | 3685 expected.value = ASCIIToUTF16("AL"); |
3567 expected.form_control_type = "select-one"; | 3686 expected.form_control_type = "select-one"; |
3568 expected.max_length = 0; | 3687 expected.max_length = 0; |
3569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3688 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
3570 } | 3689 } |
3571 } // namespace autofill | 3690 } // namespace autofill |
OLD | NEW |