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/command_line.h" | |
8 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/autofill/autofill_metrics.h" | 10 #include "chrome/browser/autofill/autofill_metrics.h" |
12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/form_data.h" | 12 #include "chrome/common/form_data.h" |
14 #include "chrome/common/form_field_data.h" | 13 #include "chrome/common/form_field_data.h" |
15 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 | 1567 |
1569 // Check that we fail if there are only bad form(s). | 1568 // Check that we fail if there are only bad form(s). |
1570 ScopedVector<FormStructure> bad_forms; | 1569 ScopedVector<FormStructure> bad_forms; |
1571 bad_forms.push_back(new FormStructure(malformed_form)); | 1570 bad_forms.push_back(new FormStructure(malformed_form)); |
1572 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1571 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
1573 &encoded_signatures, | 1572 &encoded_signatures, |
1574 &encoded_xml)); | 1573 &encoded_xml)); |
1575 EXPECT_EQ(0U, encoded_signatures.size()); | 1574 EXPECT_EQ(0U, encoded_signatures.size()); |
1576 EXPECT_EQ("", encoded_xml); | 1575 EXPECT_EQ("", encoded_xml); |
1577 | 1576 |
1578 // Check the behaviour with kEnableExperimentalFormFilling switch on. | 1577 // Check the behaviour with autocheckout enabled. |
1579 CommandLine::ForCurrentProcess()->AppendSwitch( | |
1580 switches::kEnableExperimentalFormFilling); | |
1581 // Add the previous form but with flag set. | |
1582 ScopedVector<FormStructure> checkable_forms; | 1578 ScopedVector<FormStructure> checkable_forms; |
1583 checkable_forms.push_back(new FormStructure(form)); | 1579 form.origin = GURL("https://www.sample1.com/query/path"); |
| 1580 checkable_forms.push_back(new FormStructure(form, true)); |
1584 | 1581 |
1585 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | 1582 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), |
1586 &encoded_signatures, | 1583 &encoded_signatures, |
1587 &encoded_xml)); | 1584 &encoded_xml)); |
1588 const char * const kSignature3 = "7747357776717901584"; | 1585 const char * const kSignature3 = "10816570822443282449"; |
1589 const char * const kResponse3 = | 1586 const char * const kResponse3 = |
1590 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | 1587 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " |
1591 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" | 1588 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"a\" " |
1592 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" | 1589 "urlprefix=\"https://www.sample1.com/query/path\">" |
| 1590 "<form signature=\"10816570822443282449\">" |
| 1591 "<field signature=\"412125936\"/>" |
1593 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | 1592 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" |
1594 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | 1593 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " |
1595 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | 1594 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " |
1596 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1595 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
1597 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | 1596 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" |
1598 "</autofillquery>"; | 1597 "</autofillquery>"; |
1599 ASSERT_EQ(1U, encoded_signatures.size()); | 1598 ASSERT_EQ(1U, encoded_signatures.size()); |
1600 EXPECT_EQ(kSignature3, encoded_signatures[0]); | 1599 EXPECT_EQ(kSignature3, encoded_signatures[0]); |
1601 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); |
1602 } | 1615 } |
1603 | 1616 |
1604 TEST(FormStructureTest, EncodeUploadRequest) { | 1617 TEST(FormStructureTest, EncodeUploadRequest) { |
1605 scoped_ptr<FormStructure> form_structure; | 1618 scoped_ptr<FormStructure> form_structure; |
1606 std::vector<FieldTypeSet> possible_field_types; | 1619 std::vector<FieldTypeSet> possible_field_types; |
1607 FormData form; | 1620 FormData form; |
1608 form.method = ASCIIToUTF16("post"); | 1621 form.method = ASCIIToUTF16("post"); |
1609 form_structure.reset(new FormStructure(form)); | 1622 form_structure.reset(new FormStructure(form)); |
1610 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1623 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1611 | 1624 |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 field.form_control_type = "submit"; | 2197 field.form_control_type = "submit"; |
2185 form.fields.push_back(field); | 2198 form.fields.push_back(field); |
2186 | 2199 |
2187 EXPECT_EQ(form, FormStructure(form).ToFormData()); | 2200 EXPECT_EQ(form, FormStructure(form).ToFormData()); |
2188 | 2201 |
2189 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always | 2202 // Currently |FormStructure(form_data)ToFormData().user_submitted| is always |
2190 // 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. |
2191 form.user_submitted = true; | 2204 form.user_submitted = true; |
2192 EXPECT_NE(form, FormStructure(form).ToFormData()); | 2205 EXPECT_NE(form, FormStructure(form).ToFormData()); |
2193 } | 2206 } |
OLD | NEW |