OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 // Add checkable field. | 1476 // Add checkable field. |
1477 FormFieldData checkable_field; | 1477 FormFieldData checkable_field; |
1478 checkable_field.is_checkable = true; | 1478 checkable_field.is_checkable = true; |
1479 checkable_field.label = ASCIIToUTF16("Checkable1"); | 1479 checkable_field.label = ASCIIToUTF16("Checkable1"); |
1480 checkable_field.name = ASCIIToUTF16("Checkable1"); | 1480 checkable_field.name = ASCIIToUTF16("Checkable1"); |
1481 form.fields.push_back(checkable_field); | 1481 form.fields.push_back(checkable_field); |
1482 | 1482 |
1483 ScopedVector<FormStructure> forms; | 1483 ScopedVector<FormStructure> forms; |
1484 forms.push_back(new FormStructure(form)); | 1484 forms.push_back(new FormStructure(form)); |
1485 std::vector<std::string> encoded_signatures; | 1485 std::vector<std::string> encoded_signatures; |
1486 std::vector<FormStructure*> queried_forms; | |
1487 std::string encoded_xml; | 1486 std::string encoded_xml; |
1488 const char kSignature1[] = "11337937696949187602"; | 1487 const char kSignature1[] = "11337937696949187602"; |
1489 const char kResponse1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 1488 const char kResponse1[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
1490 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 1489 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
1491 "<form signature=\"11337937696949187602\">" | 1490 "<form signature=\"11337937696949187602\">" |
1492 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"" | 1491 "<field signature=\"412125936\" name=\"name_on_card\" type=\"text\"" |
1493 " label=\"Name on Card\"/><field signature=\"1917667676\"" | 1492 " label=\"Name on Card\"/><field signature=\"1917667676\"" |
1494 " name=\"billing_address\" type=\"text\" label=\"Address\"/>" | 1493 " name=\"billing_address\" type=\"text\" label=\"Address\"/>" |
1495 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"" | 1494 "<field signature=\"2226358947\" name=\"card_number\" type=\"text\"" |
1496 " label=\"Card Number\"/><field signature=\"747221617\"" | 1495 " label=\"Card Number\"/><field signature=\"747221617\"" |
1497 " name=\"expiration_month\" type=\"text\" label=\"Expiration Date\"/>" | 1496 " name=\"expiration_month\" type=\"text\" label=\"Expiration Date\"/>" |
1498 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"" | 1497 "<field signature=\"4108155786\" name=\"expiration_year\" type=\"text\"" |
1499 " label=\"Expiration Year\"/></form></autofillquery>"; | 1498 " label=\"Expiration Year\"/></form></autofillquery>"; |
1500 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 1499 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
1501 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 1500 forms.get(), &encoded_signatures, &encoded_xml)); |
1502 ASSERT_EQ(1U, encoded_signatures.size()); | 1501 ASSERT_EQ(1U, encoded_signatures.size()); |
1503 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1502 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1504 EXPECT_EQ(forms[0], queried_forms[0]); | |
1505 EXPECT_EQ(kResponse1, encoded_xml); | 1503 EXPECT_EQ(kResponse1, encoded_xml); |
1506 | 1504 |
1507 // Add the same form, only one will be encoded, so EncodeQueryRequest() should | 1505 // Add the same form, only one will be encoded, so EncodeQueryRequest() should |
1508 // return the same data. | 1506 // return the same data. |
1509 forms.push_back(new FormStructure(form)); | 1507 forms.push_back(new FormStructure(form)); |
1510 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 1508 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
1511 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 1509 forms.get(), &encoded_signatures, &encoded_xml)); |
1512 ASSERT_EQ(1U, encoded_signatures.size()); | 1510 ASSERT_EQ(1U, encoded_signatures.size()); |
1513 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1511 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1514 ASSERT_EQ(1U, queried_forms.size()); | |
1515 EXPECT_EQ(forms[0], queried_forms[0]); | |
1516 EXPECT_EQ(kResponse1, encoded_xml); | 1512 EXPECT_EQ(kResponse1, encoded_xml); |
1517 // Add 5 address fields - this should be still a valid form. | 1513 // Add 5 address fields - this should be still a valid form. |
1518 for (size_t i = 0; i < 5; ++i) { | 1514 for (size_t i = 0; i < 5; ++i) { |
1519 field.label = ASCIIToUTF16("Address"); | 1515 field.label = ASCIIToUTF16("Address"); |
1520 field.name = ASCIIToUTF16("address"); | 1516 field.name = ASCIIToUTF16("address"); |
1521 form.fields.push_back(field); | 1517 form.fields.push_back(field); |
1522 } | 1518 } |
1523 | 1519 |
1524 forms.push_back(new FormStructure(form)); | 1520 forms.push_back(new FormStructure(form)); |
1525 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 1521 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
1526 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 1522 forms.get(), &encoded_signatures, &encoded_xml)); |
1527 ASSERT_EQ(2U, encoded_signatures.size()); | 1523 ASSERT_EQ(2U, encoded_signatures.size()); |
1528 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1524 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1529 const char kSignature2[] = "8308881815906226214"; | 1525 const char kSignature2[] = "8308881815906226214"; |
1530 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1526 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
1531 const char kResponse2[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 1527 const char kResponse2[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
1532 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 1528 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
1533 "<form signature=\"11337937696949187602\"><field signature=\"412125936\"" | 1529 "<form signature=\"11337937696949187602\"><field signature=\"412125936\"" |
1534 " name=\"name_on_card\" type=\"text\" label=\"Name on Card\"/>" | 1530 " name=\"name_on_card\" type=\"text\" label=\"Name on Card\"/>" |
1535 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"" | 1531 "<field signature=\"1917667676\" name=\"billing_address\" type=\"text\"" |
1536 " label=\"Address\"/><field signature=\"2226358947\" name=\"card_number\"" | 1532 " label=\"Address\"/><field signature=\"2226358947\" name=\"card_number\"" |
(...skipping 23 matching lines...) Expand all Loading... |
1560 // Add 50 address fields - the form is not valid anymore, but previous ones | 1556 // Add 50 address fields - the form is not valid anymore, but previous ones |
1561 // are. The result should be the same as in previous test. | 1557 // are. The result should be the same as in previous test. |
1562 for (size_t i = 0; i < 50; ++i) { | 1558 for (size_t i = 0; i < 50; ++i) { |
1563 field.label = ASCIIToUTF16("Address"); | 1559 field.label = ASCIIToUTF16("Address"); |
1564 field.name = ASCIIToUTF16("address"); | 1560 field.name = ASCIIToUTF16("address"); |
1565 malformed_form.fields.push_back(field); | 1561 malformed_form.fields.push_back(field); |
1566 } | 1562 } |
1567 | 1563 |
1568 forms.push_back(new FormStructure(malformed_form)); | 1564 forms.push_back(new FormStructure(malformed_form)); |
1569 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 1565 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
1570 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 1566 forms.get(), &encoded_signatures, &encoded_xml)); |
1571 ASSERT_EQ(2U, encoded_signatures.size()); | 1567 ASSERT_EQ(2U, encoded_signatures.size()); |
1572 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1568 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1573 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1569 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
1574 ASSERT_EQ(2U, queried_forms.size()); | |
1575 EXPECT_EQ(forms[0], queried_forms[0]); | |
1576 EXPECT_EQ(forms[2], queried_forms[1]); | |
1577 EXPECT_EQ(kResponse2, encoded_xml); | 1570 EXPECT_EQ(kResponse2, encoded_xml); |
1578 | 1571 |
1579 // Check that we fail if there are only bad form(s). | 1572 // Check that we fail if there are only bad form(s). |
1580 ScopedVector<FormStructure> bad_forms; | 1573 ScopedVector<FormStructure> bad_forms; |
1581 bad_forms.push_back(new FormStructure(malformed_form)); | 1574 bad_forms.push_back(new FormStructure(malformed_form)); |
1582 EXPECT_FALSE(FormStructure::EncodeQueryRequest( | 1575 EXPECT_FALSE(FormStructure::EncodeQueryRequest( |
1583 bad_forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 1576 bad_forms.get(), &encoded_signatures, &encoded_xml)); |
1584 EXPECT_EQ(0U, encoded_signatures.size()); | 1577 EXPECT_EQ(0U, encoded_signatures.size()); |
1585 EXPECT_EQ(0U, queried_forms.size()); | |
1586 EXPECT_EQ("", encoded_xml); | 1578 EXPECT_EQ("", encoded_xml); |
1587 } | 1579 } |
1588 | 1580 |
1589 TEST_F(FormStructureTest, EncodeUploadRequest) { | 1581 TEST_F(FormStructureTest, EncodeUploadRequest) { |
1590 scoped_ptr<FormStructure> form_structure; | 1582 scoped_ptr<FormStructure> form_structure; |
1591 std::vector<ServerFieldTypeSet> possible_field_types; | 1583 std::vector<ServerFieldTypeSet> possible_field_types; |
1592 FormData form; | 1584 FormData form; |
1593 form_structure.reset(new FormStructure(form)); | 1585 form_structure.reset(new FormStructure(form)); |
1594 form_structure->DetermineHeuristicTypes(); | 1586 form_structure->DetermineHeuristicTypes(); |
1595 | 1587 |
(...skipping 1166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2762 | 2754 |
2763 field.label = base::string16(); | 2755 field.label = base::string16(); |
2764 field.name = ASCIIToUTF16("email"); | 2756 field.name = ASCIIToUTF16("email"); |
2765 field.form_control_type = "text"; | 2757 field.form_control_type = "text"; |
2766 field.is_checkable = false; | 2758 field.is_checkable = false; |
2767 form.fields.push_back(field); | 2759 form.fields.push_back(field); |
2768 | 2760 |
2769 ScopedVector<FormStructure> forms; | 2761 ScopedVector<FormStructure> forms; |
2770 forms.push_back(new FormStructure(form)); | 2762 forms.push_back(new FormStructure(form)); |
2771 std::vector<std::string> encoded_signatures; | 2763 std::vector<std::string> encoded_signatures; |
2772 std::vector<FormStructure*> queried_forms; | |
2773 std::string encoded_xml; | 2764 std::string encoded_xml; |
2774 | 2765 |
2775 const char kSignature[] = "18006745212084723782"; | 2766 const char kSignature[] = "18006745212084723782"; |
2776 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2767 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
2777 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2768 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
2778 "<form signature=\"18006745212084723782\">" | 2769 "<form signature=\"18006745212084723782\">" |
2779 "<field signature=\"239111655\" name=\"username\" type=\"text\"" | 2770 "<field signature=\"239111655\" name=\"username\" type=\"text\"" |
2780 " label=\"username\"/>" | 2771 " label=\"username\"/>" |
2781 "<field signature=\"420638584\" name=\"email\" type=\"text\"/>" | 2772 "<field signature=\"420638584\" name=\"email\" type=\"text\"/>" |
2782 "</form></autofillquery>"; | 2773 "</form></autofillquery>"; |
2783 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 2774 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
2784 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 2775 forms.get(), &encoded_signatures, &encoded_xml)); |
2785 ASSERT_EQ(1U, encoded_signatures.size()); | 2776 ASSERT_EQ(1U, encoded_signatures.size()); |
2786 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2777 EXPECT_EQ(kSignature, encoded_signatures[0]); |
2787 EXPECT_EQ(forms[0], queried_forms[0]); | |
2788 EXPECT_EQ(kResponse, encoded_xml); | 2778 EXPECT_EQ(kResponse, encoded_xml); |
2789 } | 2779 } |
2790 | 2780 |
2791 TEST_F(FormStructureTest, EncodeQueryRequest_WithLabels) { | 2781 TEST_F(FormStructureTest, EncodeQueryRequest_WithLabels) { |
2792 FormData form; | 2782 FormData form; |
2793 form.name = ASCIIToUTF16("the-name"); | 2783 form.name = ASCIIToUTF16("the-name"); |
2794 form.origin = GURL("http://cool.com"); | 2784 form.origin = GURL("http://cool.com"); |
2795 form.action = form.origin.Resolve("/login"); | 2785 form.action = form.origin.Resolve("/login"); |
2796 | 2786 |
2797 FormFieldData field; | 2787 FormFieldData field; |
2798 // No label on the first field. | 2788 // No label on the first field. |
2799 field.name = ASCIIToUTF16("username"); | 2789 field.name = ASCIIToUTF16("username"); |
2800 field.form_control_type = "text"; | 2790 field.form_control_type = "text"; |
2801 form.fields.push_back(field); | 2791 form.fields.push_back(field); |
2802 | 2792 |
2803 field.label = ASCIIToUTF16("Enter your Email address"); | 2793 field.label = ASCIIToUTF16("Enter your Email address"); |
2804 field.name = ASCIIToUTF16("email"); | 2794 field.name = ASCIIToUTF16("email"); |
2805 field.form_control_type = "text"; | 2795 field.form_control_type = "text"; |
2806 form.fields.push_back(field); | 2796 form.fields.push_back(field); |
2807 | 2797 |
2808 field.label = ASCIIToUTF16("Enter your Password"); | 2798 field.label = ASCIIToUTF16("Enter your Password"); |
2809 field.name = ASCIIToUTF16("password"); | 2799 field.name = ASCIIToUTF16("password"); |
2810 field.form_control_type = "password"; | 2800 field.form_control_type = "password"; |
2811 form.fields.push_back(field); | 2801 form.fields.push_back(field); |
2812 | 2802 |
2813 ScopedVector<FormStructure> forms; | 2803 ScopedVector<FormStructure> forms; |
2814 forms.push_back(new FormStructure(form)); | 2804 forms.push_back(new FormStructure(form)); |
2815 std::vector<std::string> encoded_signatures; | 2805 std::vector<std::string> encoded_signatures; |
2816 std::vector<FormStructure*> queried_forms; | |
2817 std::string encoded_xml; | 2806 std::string encoded_xml; |
2818 | 2807 |
2819 const char kRequest[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2808 const char kRequest[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
2820 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2809 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
2821 "<form signature=\"13906559713264665730\">" | 2810 "<form signature=\"13906559713264665730\">" |
2822 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" | 2811 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" |
2823 "<field signature=\"420638584\" name=\"email\" type=\"text\"" | 2812 "<field signature=\"420638584\" name=\"email\" type=\"text\"" |
2824 " label=\"Enter your Email address\"/>" | 2813 " label=\"Enter your Email address\"/>" |
2825 "<field signature=\"2051817934\" name=\"password\" type=\"password\"" | 2814 "<field signature=\"2051817934\" name=\"password\" type=\"password\"" |
2826 " label=\"Enter your Password\"/></form></autofillquery>"; | 2815 " label=\"Enter your Password\"/></form></autofillquery>"; |
2827 EXPECT_TRUE(FormStructure::EncodeQueryRequest( | 2816 EXPECT_TRUE(FormStructure::EncodeQueryRequest( |
2828 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 2817 forms.get(), &encoded_signatures, &encoded_xml)); |
2829 EXPECT_EQ(kRequest, encoded_xml); | 2818 EXPECT_EQ(kRequest, encoded_xml); |
2830 } | 2819 } |
2831 | 2820 |
2832 TEST_F(FormStructureTest, EncodeQueryRequest_WithLongLabels) { | 2821 TEST_F(FormStructureTest, EncodeQueryRequest_WithLongLabels) { |
2833 FormData form; | 2822 FormData form; |
2834 form.name = ASCIIToUTF16("the-name"); | 2823 form.name = ASCIIToUTF16("the-name"); |
2835 form.origin = GURL("http://cool.com"); | 2824 form.origin = GURL("http://cool.com"); |
2836 form.action = form.origin.Resolve("/login"); | 2825 form.action = form.origin.Resolve("/login"); |
2837 | 2826 |
2838 FormFieldData field; | 2827 FormFieldData field; |
(...skipping 13 matching lines...) Expand all Loading... |
2852 form.fields.push_back(field); | 2841 form.fields.push_back(field); |
2853 | 2842 |
2854 field.label = ASCIIToUTF16("Enter your Password"); | 2843 field.label = ASCIIToUTF16("Enter your Password"); |
2855 field.name = ASCIIToUTF16("password"); | 2844 field.name = ASCIIToUTF16("password"); |
2856 field.form_control_type = "password"; | 2845 field.form_control_type = "password"; |
2857 form.fields.push_back(field); | 2846 form.fields.push_back(field); |
2858 | 2847 |
2859 ScopedVector<FormStructure> forms; | 2848 ScopedVector<FormStructure> forms; |
2860 forms.push_back(new FormStructure(form)); | 2849 forms.push_back(new FormStructure(form)); |
2861 std::vector<std::string> encoded_signatures; | 2850 std::vector<std::string> encoded_signatures; |
2862 std::vector<FormStructure*> queried_forms; | |
2863 std::string encoded_xml; | 2851 std::string encoded_xml; |
2864 | 2852 |
2865 const char kRequest[] = | 2853 const char kRequest[] = |
2866 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2854 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
2867 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2855 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
2868 "<form signature=\"13906559713264665730\">" | 2856 "<form signature=\"13906559713264665730\">" |
2869 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" | 2857 "<field signature=\"239111655\" name=\"username\" type=\"text\"/>" |
2870 "<field signature=\"420638584\" name=\"email\" type=\"text\"" | 2858 "<field signature=\"420638584\" name=\"email\" type=\"text\"" |
2871 " label=\"Enter Your Really Really Really (Really!) Long Email Address" | 2859 " label=\"Enter Your Really Really Really (Really!) Long Email Address" |
2872 " Which We Hope To Get In Order To Send You Unwanted Publicity Because" | 2860 " Which We Hope To Get In Order To Send You Unwanted Publicity Because" |
2873 " That's What Marketers Do! We Know That Your Email Address Has The" | 2861 " That's What Marketers Do! We Know That Your Email Address Has The" |
2874 " Poss\"/>" | 2862 " Poss\"/>" |
2875 "<field signature=\"2051817934\" name=\"password\" type=\"password\"" | 2863 "<field signature=\"2051817934\" name=\"password\" type=\"password\"" |
2876 " label=\"Enter your Password\"/></form></autofillquery>"; | 2864 " label=\"Enter your Password\"/></form></autofillquery>"; |
2877 EXPECT_TRUE(FormStructure::EncodeQueryRequest( | 2865 EXPECT_TRUE(FormStructure::EncodeQueryRequest( |
2878 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 2866 forms.get(), &encoded_signatures, &encoded_xml)); |
2879 EXPECT_EQ(kRequest, encoded_xml); | 2867 EXPECT_EQ(kRequest, encoded_xml); |
2880 } | 2868 } |
2881 | 2869 |
2882 // One name is missing from one field. | 2870 // One name is missing from one field. |
2883 TEST_F(FormStructureTest, EncodeQueryRequest_MissingNames) { | 2871 TEST_F(FormStructureTest, EncodeQueryRequest_MissingNames) { |
2884 FormData form; | 2872 FormData form; |
2885 // No name set for the form. | 2873 // No name set for the form. |
2886 form.origin = GURL("http://cool.com"); | 2874 form.origin = GURL("http://cool.com"); |
2887 form.action = form.origin.Resolve("/login"); | 2875 form.action = form.origin.Resolve("/login"); |
2888 | 2876 |
2889 FormFieldData field; | 2877 FormFieldData field; |
2890 field.label = ASCIIToUTF16("username"); | 2878 field.label = ASCIIToUTF16("username"); |
2891 field.name = ASCIIToUTF16("username"); | 2879 field.name = ASCIIToUTF16("username"); |
2892 field.form_control_type = "text"; | 2880 field.form_control_type = "text"; |
2893 form.fields.push_back(field); | 2881 form.fields.push_back(field); |
2894 | 2882 |
2895 field.label = base::string16(); | 2883 field.label = base::string16(); |
2896 // No name set for this field. | 2884 // No name set for this field. |
2897 field.name = ASCIIToUTF16(""); | 2885 field.name = ASCIIToUTF16(""); |
2898 field.form_control_type = "text"; | 2886 field.form_control_type = "text"; |
2899 field.is_checkable = false; | 2887 field.is_checkable = false; |
2900 form.fields.push_back(field); | 2888 form.fields.push_back(field); |
2901 | 2889 |
2902 ScopedVector<FormStructure> forms; | 2890 ScopedVector<FormStructure> forms; |
2903 forms.push_back(new FormStructure(form)); | 2891 forms.push_back(new FormStructure(form)); |
2904 std::vector<std::string> encoded_signatures; | 2892 std::vector<std::string> encoded_signatures; |
2905 std::vector<FormStructure*> queried_forms; | |
2906 std::string encoded_xml; | 2893 std::string encoded_xml; |
2907 | 2894 |
2908 const char kSignature[] = "16416961345885087496"; | 2895 const char kSignature[] = "16416961345885087496"; |
2909 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2896 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
2910 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2897 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
2911 "<form signature=\"16416961345885087496\">" | 2898 "<form signature=\"16416961345885087496\">" |
2912 "<field signature=\"239111655\" name=\"username\" type=\"text\"" | 2899 "<field signature=\"239111655\" name=\"username\" type=\"text\"" |
2913 " label=\"username\"/><field signature=\"1318412689\" type=\"text\"/>" | 2900 " label=\"username\"/><field signature=\"1318412689\" type=\"text\"/>" |
2914 "</form></autofillquery>"; | 2901 "</form></autofillquery>"; |
2915 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 2902 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
2916 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 2903 forms.get(), &encoded_signatures, &encoded_xml)); |
2917 ASSERT_EQ(1U, encoded_signatures.size()); | 2904 ASSERT_EQ(1U, encoded_signatures.size()); |
2918 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2905 EXPECT_EQ(kSignature, encoded_signatures[0]); |
2919 EXPECT_EQ(forms[0], queried_forms[0]); | |
2920 EXPECT_EQ(kResponse, encoded_xml); | 2906 EXPECT_EQ(kResponse, encoded_xml); |
2921 } | 2907 } |
2922 | 2908 |
2923 // Sending field metadata to the server is disabled. | 2909 // Sending field metadata to the server is disabled. |
2924 TEST_F(FormStructureTest, EncodeQueryRequest_DisabledMetadataTrial) { | 2910 TEST_F(FormStructureTest, EncodeQueryRequest_DisabledMetadataTrial) { |
2925 DisableAutofillMetadataFieldTrial(); | 2911 DisableAutofillMetadataFieldTrial(); |
2926 | 2912 |
2927 FormData form; | 2913 FormData form; |
2928 // No name set for the form. | 2914 // No name set for the form. |
2929 form.origin = GURL("http://cool.com"); | 2915 form.origin = GURL("http://cool.com"); |
2930 form.action = form.origin.Resolve("/login"); | 2916 form.action = form.origin.Resolve("/login"); |
2931 | 2917 |
2932 FormFieldData field; | 2918 FormFieldData field; |
2933 field.label = ASCIIToUTF16("username"); | 2919 field.label = ASCIIToUTF16("username"); |
2934 field.name = ASCIIToUTF16("username"); | 2920 field.name = ASCIIToUTF16("username"); |
2935 field.form_control_type = "text"; | 2921 field.form_control_type = "text"; |
2936 form.fields.push_back(field); | 2922 form.fields.push_back(field); |
2937 | 2923 |
2938 field.label = base::string16(); | 2924 field.label = base::string16(); |
2939 field.name = ASCIIToUTF16("country"); | 2925 field.name = ASCIIToUTF16("country"); |
2940 field.form_control_type = "text"; | 2926 field.form_control_type = "text"; |
2941 field.is_checkable = false; | 2927 field.is_checkable = false; |
2942 form.fields.push_back(field); | 2928 form.fields.push_back(field); |
2943 | 2929 |
2944 ScopedVector<FormStructure> forms; | 2930 ScopedVector<FormStructure> forms; |
2945 forms.push_back(new FormStructure(form)); | 2931 forms.push_back(new FormStructure(form)); |
2946 std::vector<std::string> encoded_signatures; | 2932 std::vector<std::string> encoded_signatures; |
2947 std::vector<FormStructure*> queried_forms; | |
2948 std::string encoded_xml; | 2933 std::string encoded_xml; |
2949 | 2934 |
2950 const char kSignature[] = "7635954436925888745"; | 2935 const char kSignature[] = "7635954436925888745"; |
2951 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | 2936 const char kResponse[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
2952 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" | 2937 "<autofillquery clientversion=\"6.1.1715.1442/en (GGLL)\">" |
2953 "<form signature=\"7635954436925888745\">" | 2938 "<form signature=\"7635954436925888745\">" |
2954 "<field signature=\"239111655\"/>" | 2939 "<field signature=\"239111655\"/>" |
2955 "<field signature=\"3654076265\"/>" | 2940 "<field signature=\"3654076265\"/>" |
2956 "</form></autofillquery>"; | 2941 "</form></autofillquery>"; |
2957 ASSERT_TRUE(FormStructure::EncodeQueryRequest( | 2942 ASSERT_TRUE(FormStructure::EncodeQueryRequest( |
2958 forms.get(), &encoded_signatures, &queried_forms, &encoded_xml)); | 2943 forms.get(), &encoded_signatures, &encoded_xml)); |
2959 ASSERT_EQ(1U, encoded_signatures.size()); | 2944 ASSERT_EQ(1U, encoded_signatures.size()); |
2960 EXPECT_EQ(kSignature, encoded_signatures[0]); | 2945 EXPECT_EQ(kSignature, encoded_signatures[0]); |
2961 EXPECT_EQ(forms[0], queried_forms[0]); | |
2962 EXPECT_EQ(kResponse, encoded_xml); | 2946 EXPECT_EQ(kResponse, encoded_xml); |
2963 } | 2947 } |
2964 | 2948 |
2965 TEST_F(FormStructureTest, PossibleValues) { | 2949 TEST_F(FormStructureTest, PossibleValues) { |
2966 FormData form_data; | 2950 FormData form_data; |
2967 FormFieldData field; | 2951 FormFieldData field; |
2968 field.autocomplete_attribute = "billing country"; | 2952 field.autocomplete_attribute = "billing country"; |
2969 field.option_contents.push_back(ASCIIToUTF16("Down Under")); | 2953 field.option_contents.push_back(ASCIIToUTF16("Down Under")); |
2970 field.option_values.push_back(ASCIIToUTF16("AU")); | 2954 field.option_values.push_back(ASCIIToUTF16("AU")); |
2971 field.option_contents.push_back(ASCIIToUTF16("Fr")); | 2955 field.option_contents.push_back(ASCIIToUTF16("Fr")); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3084 "</autofillqueryresponse>"; | 3068 "</autofillqueryresponse>"; |
3085 | 3069 |
3086 FormStructure::ParseQueryResponse(response, forms.get(), nullptr); | 3070 FormStructure::ParseQueryResponse(response, forms.get(), nullptr); |
3087 | 3071 |
3088 ASSERT_GE(forms[0]->field_count(), 2U); | 3072 ASSERT_GE(forms[0]->field_count(), 2U); |
3089 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); | 3073 EXPECT_EQ(NO_SERVER_DATA, forms[0]->field(0)->server_type()); |
3090 EXPECT_EQ(76, forms[0]->field(1)->server_type()); | 3074 EXPECT_EQ(76, forms[0]->field(1)->server_type()); |
3091 } | 3075 } |
3092 | 3076 |
3093 } // namespace autofill | 3077 } // namespace autofill |
OLD | NEW |