Chromium Code Reviews| 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: test_case#1 | |
| 685 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectStyle) { | |
| 686 LoadHTML("<STYLE>input{direction:rtl}</STYLE>" | |
| 687 "<FORM>" | |
| 688 " <INPUT type='text' id='element'>" | |
| 689 "</FORM>"); | |
| 690 | |
| 691 WebFrame* frame = GetMainFrame(); | |
| 692 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 693 | |
| 694 WebElement web_element = frame->document().getElementById("element"); | |
| 695 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 696 | |
| 697 FormFieldData result; | |
| 698 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 699 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | |
| 700 } | |
| 701 | |
| 702 // Both text input and autocomplete should have same direction: test_case#2 | |
| 703 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectDIRAttribute) { | |
| 704 LoadHTML("<FORM>" | |
| 705 " <INPUT dir='rtl' type='text' id='element'/>" | |
| 706 "</FORM>"); | |
| 707 | |
| 708 WebFrame* frame = GetMainFrame(); | |
| 709 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 710 | |
| 711 WebElement web_element = frame->document().getElementById("element"); | |
| 712 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 713 | |
| 714 FormFieldData result; | |
| 715 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 716 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | |
| 717 } | |
| 718 | |
| 719 // Both text input and autocomplete should have same direction: test_case#3 | |
| 720 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectParentStyle) { | |
|
Ilya Sherman
2014/08/08 04:59:31
nit: "DirectParent" -> "Parent"
Sunil Ratnu
2014/08/08 05:06:24
Done.
| |
| 721 LoadHTML("<STYLE>form{direction:rtl}</STYLE>" | |
| 722 "<FORM>" | |
| 723 " <INPUT type='text' id='element'/>" | |
| 724 "</FORM>"); | |
| 725 | |
| 726 WebFrame* frame = GetMainFrame(); | |
| 727 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 728 | |
| 729 WebElement web_element = frame->document().getElementById("element"); | |
| 730 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 731 | |
| 732 FormFieldData result; | |
| 733 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 734 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | |
| 735 } | |
| 736 | |
| 737 // Both text input and autocomplete should have same direction: test_case#4 | |
| 738 TEST_F(FormAutofillTest, DetectTextDirectionFromDirectParentDIRAttribute) { | |
|
Ilya Sherman
2014/08/08 04:59:31
nit: Ditto
Sunil Ratnu
2014/08/08 05:06:24
Done.
| |
| 739 LoadHTML("<FORM dir='rtl'>" | |
| 740 " <INPUT type='text' id='element'/>" | |
| 741 "</FORM>"); | |
| 742 | |
| 743 WebFrame* frame = GetMainFrame(); | |
| 744 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 745 | |
| 746 WebElement web_element = frame->document().getElementById("element"); | |
| 747 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 748 | |
| 749 FormFieldData result; | |
| 750 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 751 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | |
| 752 } | |
| 753 | |
| 754 // Both text input and autocomplete should have same direction: test_case#5 | |
| 755 TEST_F(FormAutofillTest, DetectTextDirectionWhenStyleAndDIRAttributMixed) { | |
| 756 LoadHTML("<STYLE>input{direction:ltr}</STYLE>" | |
| 757 "<FORM dir='rtl'>" | |
| 758 " <INPUT type='text' id='element'/>" | |
| 759 "</FORM>"); | |
| 760 | |
| 761 WebFrame* frame = GetMainFrame(); | |
| 762 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 763 | |
| 764 WebElement web_element = frame->document().getElementById("element"); | |
| 765 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 766 | |
| 767 FormFieldData result; | |
| 768 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 769 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | |
| 770 } | |
| 771 | |
| 772 // Both text input and autocomplete should have same direction: test_case#6 | |
|
Ilya Sherman
2014/08/08 04:59:32
nit: I'd either expand these comments to be more s
Sunil Ratnu
2014/08/08 05:06:24
Removing them entirely as the names are self expla
| |
| 773 TEST_F(FormAutofillTest, | |
| 774 DetectTextDirectionWhenParentHaveBothDIRAttributeAndStyle) { | |
|
Ilya Sherman
2014/08/08 04:59:31
nit: "Have" -> "Has"
Sunil Ratnu
2014/08/08 05:06:24
Done.
| |
| 775 LoadHTML("<STYLE>form{direction:ltr}</STYLE>" | |
| 776 "<FORM dir='rtl'>" | |
| 777 " <INPUT type='text' id='element'/>" | |
| 778 "</FORM>"); | |
| 779 | |
| 780 WebFrame* frame = GetMainFrame(); | |
| 781 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 782 | |
| 783 WebElement web_element = frame->document().getElementById("element"); | |
| 784 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 785 | |
| 786 FormFieldData result; | |
| 787 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 788 EXPECT_EQ(base::i18n::LEFT_TO_RIGHT, result.text_direction); | |
| 789 } | |
| 790 | |
| 791 // Both text input and autocomplete should have same direction: test_case#7 | |
| 792 TEST_F(FormAutofillTest, DetectTextDirectionWhenAncestorHaveInlineStyle) { | |
|
Ilya Sherman
2014/08/08 04:59:32
nit: "Have" -> "Has"
Sunil Ratnu
2014/08/08 05:06:24
Done.
| |
| 793 LoadHTML("<FORM style='direction:ltr'>" | |
| 794 " <SPAN dir='rtl'>" | |
| 795 " <INPUT type='text' id='element'/>" | |
| 796 " </SPAN>" | |
| 797 "</FORM>"); | |
| 798 | |
| 799 WebFrame* frame = GetMainFrame(); | |
| 800 ASSERT_NE(static_cast<WebFrame*>(NULL), frame); | |
| 801 | |
| 802 WebElement web_element = frame->document().getElementById("element"); | |
| 803 WebFormControlElement element = web_element.to<WebFormControlElement>(); | |
| 804 | |
| 805 FormFieldData result; | |
| 806 WebFormControlElementToFormField(element, autofill::EXTRACT_VALUE, &result); | |
| 807 EXPECT_EQ(base::i18n::RIGHT_TO_LEFT, result.text_direction); | |
| 808 } | |
| 809 | |
| 684 TEST_F(FormAutofillTest, WebFormElementToFormData) { | 810 TEST_F(FormAutofillTest, WebFormElementToFormData) { |
| 685 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" | 811 LoadHTML("<FORM name=\"TestForm\" action=\"http://cnn.com\" method=\"post\">" |
| 686 " <LABEL for=\"firstname\">First name:</LABEL>" | 812 " <LABEL for=\"firstname\">First name:</LABEL>" |
| 687 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" | 813 " <INPUT type=\"text\" id=\"firstname\" value=\"John\"/>" |
| 688 " <LABEL for=\"lastname\">Last name:</LABEL>" | 814 " <LABEL for=\"lastname\">Last name:</LABEL>" |
| 689 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" | 815 " <INPUT type=\"text\" id=\"lastname\" value=\"Smith\"/>" |
| 690 " <LABEL for=\"street-address\">Address:</LABEL>" | 816 " <LABEL for=\"street-address\">Address:</LABEL>" |
| 691 " <TEXTAREA id=\"street-address\">" | 817 " <TEXTAREA id=\"street-address\">" |
| 692 "123 Fantasy Ln. " | 818 "123 Fantasy Ln. " |
| 693 "Apt. 42" | 819 "Apt. 42" |
| (...skipping 2868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3562 expected.max_length = WebInputElement::defaultMaxLength(); | 3688 expected.max_length = WebInputElement::defaultMaxLength(); |
| 3563 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); | 3689 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[1]); |
| 3564 | 3690 |
| 3565 expected.name = ASCIIToUTF16("country"); | 3691 expected.name = ASCIIToUTF16("country"); |
| 3566 expected.value = ASCIIToUTF16("AL"); | 3692 expected.value = ASCIIToUTF16("AL"); |
| 3567 expected.form_control_type = "select-one"; | 3693 expected.form_control_type = "select-one"; |
| 3568 expected.max_length = 0; | 3694 expected.max_length = 0; |
| 3569 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); | 3695 EXPECT_FORM_FIELD_DATA_EQUALS(expected, fields[2]); |
| 3570 } | 3696 } |
| 3571 } // namespace autofill | 3697 } // namespace autofill |
| OLD | NEW |