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 "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_metrics.h" | 10 #include "chrome/browser/autofill/autofill_metrics.h" |
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 | 1567 |
1568 // Check that we fail if there are only bad form(s). | 1568 // Check that we fail if there are only bad form(s). |
1569 ScopedVector<FormStructure> bad_forms; | 1569 ScopedVector<FormStructure> bad_forms; |
1570 bad_forms.push_back(new FormStructure(malformed_form, false)); | 1570 bad_forms.push_back(new FormStructure(malformed_form, false)); |
1571 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1571 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
1572 &encoded_signatures, | 1572 &encoded_signatures, |
1573 &encoded_xml)); | 1573 &encoded_xml)); |
1574 EXPECT_EQ(0U, encoded_signatures.size()); | 1574 EXPECT_EQ(0U, encoded_signatures.size()); |
1575 EXPECT_EQ("", encoded_xml); | 1575 EXPECT_EQ("", encoded_xml); |
1576 | 1576 |
1577 // Check the behaviour with kEnableExperimentalFormFilling switch on. | 1577 // Check the behaviour with autocheckout enabled. |
1578 // Add the previous form but with flag set. | |
1579 ScopedVector<FormStructure> checkable_forms; | 1578 ScopedVector<FormStructure> checkable_forms; |
| 1579 form.origin = GURL("https://www.sample1.com/query/path"); |
1580 checkable_forms.push_back(new FormStructure(form, true)); | 1580 checkable_forms.push_back(new FormStructure(form, true)); |
1581 | 1581 |
1582 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | 1582 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), |
1583 &encoded_signatures, | 1583 &encoded_signatures, |
1584 &encoded_xml)); | 1584 &encoded_xml)); |
1585 const char * const kSignature3 = "7747357776717901584"; | 1585 const char * const kSignature3 = "10816570822443282449"; |
1586 const char * const kResponse3 = | 1586 const char * const kResponse3 = |
1587 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | 1587 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " |
1588 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" | 1588 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"a\" " |
1589 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" | 1589 "urlprefix=\"https://www.sample1.com/query/path\">" |
| 1590 "<form signature=\"10816570822443282449\">" |
| 1591 "<field signature=\"412125936\"/>" |
1590 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | 1592 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" |
1591 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | 1593 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " |
1592 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | 1594 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " |
1593 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1595 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
1594 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | 1596 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" |
1595 "</autofillquery>"; | 1597 "</autofillquery>"; |
1596 ASSERT_EQ(1U, encoded_signatures.size()); | 1598 ASSERT_EQ(1U, encoded_signatures.size()); |
1597 EXPECT_EQ(kSignature3, encoded_signatures[0]); | 1599 EXPECT_EQ(kSignature3, encoded_signatures[0]); |
1598 EXPECT_EQ(kResponse3, encoded_xml); | 1600 EXPECT_EQ(kResponse3, encoded_xml); |
| 1601 |
| 1602 // Check the behaviour with autocheckout enabled. |
| 1603 // It should remove query parameters and the encoded_xml should be same |
| 1604 // as previous test. |
| 1605 ScopedVector<FormStructure> checkable_forms2; |
| 1606 form.origin = GURL("https://www.sample1.com/query/path?a=b&c=d"); |
| 1607 checkable_forms2.push_back(new FormStructure(form, true)); |
| 1608 |
| 1609 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms2.get(), |
| 1610 &encoded_signatures, |
| 1611 &encoded_xml)); |
| 1612 ASSERT_EQ(1U, encoded_signatures.size()); |
| 1613 EXPECT_EQ(kSignature3, encoded_signatures[0]); |
| 1614 EXPECT_EQ(kResponse3, encoded_xml); |
1599 } | 1615 } |
1600 | 1616 |
1601 TEST(FormStructureTest, EncodeUploadRequest) { | 1617 TEST(FormStructureTest, EncodeUploadRequest) { |
1602 scoped_ptr<FormStructure> form_structure; | 1618 scoped_ptr<FormStructure> form_structure; |
1603 std::vector<FieldTypeSet> possible_field_types; | 1619 std::vector<FieldTypeSet> possible_field_types; |
1604 FormData form; | 1620 FormData form; |
1605 form.method = ASCIIToUTF16("post"); | 1621 form.method = ASCIIToUTF16("post"); |
1606 form_structure.reset(new FormStructure(form, false)); | 1622 form_structure.reset(new FormStructure(form, false)); |
1607 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1623 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1608 | 1624 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2181 field.form_control_type = "submit"; | 2197 field.form_control_type = "submit"; |
2182 form.fields.push_back(field); | 2198 form.fields.push_back(field); |
2183 | 2199 |
2184 EXPECT_EQ(form, FormStructure(form, false).ToFormData()); | 2200 EXPECT_EQ(form, FormStructure(form, false).ToFormData()); |
2185 | 2201 |
2186 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2202 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
2187 // false. This forces a future author that changes this to update this test. | 2203 // false. This forces a future author that changes this to update this test. |
2188 form.user_submitted = true; | 2204 form.user_submitted = true; |
2189 EXPECT_NE(form, FormStructure(form, false).ToFormData()); | 2205 EXPECT_NE(form, FormStructure(form, false).ToFormData()); |
2190 } | 2206 } |
OLD | NEW |