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" | |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_metrics.h" | 11 #include "chrome/browser/autofill/autofill_metrics.h" |
12 #include "chrome/common/chrome_switches.h" | |
11 #include "chrome/common/form_data.h" | 13 #include "chrome/common/form_data.h" |
12 #include "chrome/common/form_field_data.h" | 14 #include "chrome/common/form_field_data.h" |
13 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
16 | 18 |
17 using WebKit::WebInputElement; | 19 using WebKit::WebInputElement; |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1423 form.fields.push_back(field); | 1425 form.fields.push_back(field); |
1424 | 1426 |
1425 field.label = ASCIIToUTF16("Expiration Date"); | 1427 field.label = ASCIIToUTF16("Expiration Date"); |
1426 field.name = ASCIIToUTF16("expiration_month"); | 1428 field.name = ASCIIToUTF16("expiration_month"); |
1427 form.fields.push_back(field); | 1429 form.fields.push_back(field); |
1428 | 1430 |
1429 field.label = ASCIIToUTF16("Expiration Year"); | 1431 field.label = ASCIIToUTF16("Expiration Year"); |
1430 field.name = ASCIIToUTF16("expiration_year"); | 1432 field.name = ASCIIToUTF16("expiration_year"); |
1431 form.fields.push_back(field); | 1433 form.fields.push_back(field); |
1432 | 1434 |
1435 // Add checkable field. | |
1436 FormFieldData checkable_field; | |
1437 checkable_field.is_checkable = true; | |
1438 checkable_field.label = ASCIIToUTF16("Checkable1"); | |
1439 checkable_field.name = ASCIIToUTF16("Checkable1"); | |
1440 form.fields.push_back(checkable_field); | |
1441 | |
1433 ScopedVector<FormStructure> forms; | 1442 ScopedVector<FormStructure> forms; |
1434 forms.push_back(new FormStructure(form)); | 1443 forms.push_back(new FormStructure(form)); |
1435 std::vector<std::string> encoded_signatures; | 1444 std::vector<std::string> encoded_signatures; |
1436 std::string encoded_xml; | 1445 std::string encoded_xml; |
1437 const char * const kSignature1 = "11337937696949187602"; | 1446 const char * const kSignature1 = "11337937696949187602"; |
1438 const char * const kResponse1 = | 1447 const char * const kResponse1 = |
1439 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " | 1448 "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?><autofillquery " |
1440 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " | 1449 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\"><form " |
1441 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" | 1450 "signature=\"11337937696949187602\"><field signature=\"412125936\"/>" |
1442 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1451 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1489 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
1481 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" | 1490 "<field signature=\"747221617\"/><field signature=\"4108155786\"/></form>" |
1482 "<form signature=\"8308881815906226214\"><field signature=\"412125936\"/>" | 1491 "<form signature=\"8308881815906226214\"><field signature=\"412125936\"/>" |
1483 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" | 1492 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/>" |
1484 "<field signature=\"747221617\"/><field signature=\"4108155786\"/><field " | 1493 "<field signature=\"747221617\"/><field signature=\"4108155786\"/><field " |
1485 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1494 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
1486 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | 1495 "signature=\"509334676\"/><field signature=\"509334676\"/><field " |
1487 "signature=\"509334676\"/></form></autofillquery>"; | 1496 "signature=\"509334676\"/></form></autofillquery>"; |
1488 EXPECT_EQ(kResponse2, encoded_xml); | 1497 EXPECT_EQ(kResponse2, encoded_xml); |
1489 | 1498 |
1499 FormData malformed_form(form); | |
1490 // Add 50 address fields - the form is not valid anymore, but previous ones | 1500 // Add 50 address fields - the form is not valid anymore, but previous ones |
1491 // are. The result should be the same as in previous test. | 1501 // are. The result should be the same as in previous test. |
1492 for (size_t i = 0; i < 50; ++i) { | 1502 for (size_t i = 0; i < 50; ++i) { |
1493 field.label = ASCIIToUTF16("Address"); | 1503 field.label = ASCIIToUTF16("Address"); |
1494 field.name = ASCIIToUTF16("address"); | 1504 field.name = ASCIIToUTF16("address"); |
1495 form.fields.push_back(field); | 1505 malformed_form.fields.push_back(field); |
1496 } | 1506 } |
1497 | 1507 |
1498 forms.push_back(new FormStructure(form)); | 1508 forms.push_back(new FormStructure(malformed_form)); |
1499 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), | 1509 ASSERT_TRUE(FormStructure::EncodeQueryRequest(forms.get(), |
1500 &encoded_signatures, | 1510 &encoded_signatures, |
1501 &encoded_xml)); | 1511 &encoded_xml)); |
1502 ASSERT_EQ(2U, encoded_signatures.size()); | 1512 ASSERT_EQ(2U, encoded_signatures.size()); |
1503 EXPECT_EQ(kSignature1, encoded_signatures[0]); | 1513 EXPECT_EQ(kSignature1, encoded_signatures[0]); |
1504 EXPECT_EQ(kSignature2, encoded_signatures[1]); | 1514 EXPECT_EQ(kSignature2, encoded_signatures[1]); |
1505 EXPECT_EQ(kResponse2, encoded_xml); | 1515 EXPECT_EQ(kResponse2, encoded_xml); |
1506 | 1516 |
1507 // Check that we fail if there are only bad form(s). | 1517 // Check that we fail if there are only bad form(s). |
1508 ScopedVector<FormStructure> bad_forms; | 1518 ScopedVector<FormStructure> bad_forms; |
1509 bad_forms.push_back(new FormStructure(form)); | 1519 bad_forms.push_back(new FormStructure(malformed_form)); |
1510 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), | 1520 EXPECT_FALSE(FormStructure::EncodeQueryRequest(bad_forms.get(), |
1511 &encoded_signatures, | 1521 &encoded_signatures, |
1512 &encoded_xml)); | 1522 &encoded_xml)); |
1513 EXPECT_EQ(0U, encoded_signatures.size()); | 1523 EXPECT_EQ(0U, encoded_signatures.size()); |
1514 EXPECT_EQ("", encoded_xml); | 1524 EXPECT_EQ("", encoded_xml); |
1525 | |
1526 // Check the behaviour with kEnableExperimentalFormFilling switch on. | |
1527 CommandLine::ForCurrentProcess()->AppendSwitch( | |
1528 switches::kEnableExperimentalFormFilling); | |
1529 // Add the previous form but with flag set. | |
1530 ScopedVector<FormStructure> checkable_forms; | |
1531 checkable_forms.push_back(new FormStructure(form)); | |
1532 | |
1533 ASSERT_TRUE(FormStructure::EncodeQueryRequest(checkable_forms.get(), | |
1534 &encoded_signatures, | |
1535 &encoded_xml)); | |
1536 const char * const kSignature3 = "7747357776717901584"; | |
1537 const char * const kResponse3 = | |
1538 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><autofillquery " | |
1539 "clientversion=\"6.1.1715.1442/en (GGLL)\" accepts=\"e\">" | |
1540 "<form signature=\"7747357776717901584\"><field signature=\"412125936\"/>" | |
1541 "<field signature=\"1917667676\"/><field signature=\"2226358947\"/><field" | |
1542 " signature=\"747221617\"/><field signature=\"4108155786\"/><field " | |
1543 "signature=\"3410250678\"/><field signature=\"509334676\"/><field " | |
1544 "signature=\"509334676\"/><field signature=\"509334676\"/><field " | |
1545 "signature=\"509334676\"/><field signature=\"509334676\"/></form>" | |
1546 "</autofillquery>"; | |
1547 ASSERT_EQ(1U, encoded_signatures.size()); | |
1548 EXPECT_EQ(kSignature3, encoded_signatures[0]); | |
1549 EXPECT_EQ(kResponse3, encoded_xml); | |
Ilya Sherman
2012/12/01 00:54:12
Please also add a similar test within EncodeUpload
Raman Kakilate
2012/12/06 01:54:05
Done. and fixed the code to not consider checkable
| |
1515 } | 1550 } |
1516 | 1551 |
1517 TEST(FormStructureTest, EncodeUploadRequest) { | 1552 TEST(FormStructureTest, EncodeUploadRequest) { |
1518 scoped_ptr<FormStructure> form_structure; | 1553 scoped_ptr<FormStructure> form_structure; |
1519 std::vector<FieldTypeSet> possible_field_types; | 1554 std::vector<FieldTypeSet> possible_field_types; |
1520 FormData form; | 1555 FormData form; |
1521 form.method = ASCIIToUTF16("post"); | 1556 form.method = ASCIIToUTF16("post"); |
1522 form_structure.reset(new FormStructure(form)); | 1557 form_structure.reset(new FormStructure(form)); |
1523 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); | 1558 form_structure->DetermineHeuristicTypes(TestAutofillMetrics()); |
1524 | 1559 |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2056 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2091 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2057 std::string("https://login.facebook.com&&email&first")), | 2092 std::string("https://login.facebook.com&&email&first")), |
2058 form_structure->FormSignature()); | 2093 form_structure->FormSignature()); |
2059 | 2094 |
2060 form.name = ASCIIToUTF16("login_form"); | 2095 form.name = ASCIIToUTF16("login_form"); |
2061 form_structure.reset(new FormStructure(form)); | 2096 form_structure.reset(new FormStructure(form)); |
2062 EXPECT_EQ(FormStructureTest::Hash64Bit( | 2097 EXPECT_EQ(FormStructureTest::Hash64Bit( |
2063 std::string("https://login.facebook.com&login_form&email&first")), | 2098 std::string("https://login.facebook.com&login_form&email&first")), |
2064 form_structure->FormSignature()); | 2099 form_structure->FormSignature()); |
2065 } | 2100 } |
OLD | NEW |