Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 6633001: Convert autofill messages to use the new IPC macros (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 // Test that we return autocomplete-like suggestions when trying to autofill 1171 // Test that we return autocomplete-like suggestions when trying to autofill
1172 // already filled forms. 1172 // already filled forms.
1173 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutoFilled) { 1173 TEST_F(AutofillManagerTest, GetFieldSuggestionsWhenFormIsAutoFilled) {
1174 // Set up our form data. 1174 // Set up our form data.
1175 FormData form; 1175 FormData form;
1176 CreateTestAddressFormData(&form); 1176 CreateTestAddressFormData(&form);
1177 std::vector<FormData> forms(1, form); 1177 std::vector<FormData> forms(1, form);
1178 FormsSeen(forms); 1178 FormsSeen(forms);
1179 1179
1180 // Mark one of the fields as filled. 1180 // Mark one of the fields as filled.
1181 form.fields[2].set_autofilled(true); 1181 form.fields[2].is_autofilled = true;
1182 const FormField& field = form.fields[0]; 1182 const FormField& field = form.fields[0];
1183 GetAutoFillSuggestions(form, field); 1183 GetAutoFillSuggestions(form, field);
1184 1184
1185 // No suggestions provided, so send an empty vector as the results. 1185 // No suggestions provided, so send an empty vector as the results.
1186 // This triggers the combined message send. 1186 // This triggers the combined message send.
1187 AutocompleteSuggestionsReturned(std::vector<string16>()); 1187 AutocompleteSuggestionsReturned(std::vector<string16>());
1188 1188
1189 // Test that we sent the right message to the renderer. 1189 // Test that we sent the right message to the renderer.
1190 int page_id = 0; 1190 int page_id = 0;
1191 std::vector<string16> values; 1191 std::vector<string16> values;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 FormsSeen(forms); 1259 FormsSeen(forms);
1260 1260
1261 // |profile| will be owned by the mock PersonalDataManager. 1261 // |profile| will be owned by the mock PersonalDataManager.
1262 AutoFillProfile* profile = new AutoFillProfile; 1262 AutoFillProfile* profile = new AutoFillProfile;
1263 autofill_test::SetProfileInfo(profile, "Elvis", "", "", "", "", 1263 autofill_test::SetProfileInfo(profile, "Elvis", "", "", "", "",
1264 "", "", "", "", "", "", "", ""); 1264 "", "", "", "", "", "", "", "");
1265 profile->set_guid("00000000-0000-0000-0000-000000000101"); 1265 profile->set_guid("00000000-0000-0000-0000-000000000101");
1266 autofill_manager_->AddProfile(profile); 1266 autofill_manager_->AddProfile(profile);
1267 1267
1268 FormField& field = form.fields[0]; 1268 FormField& field = form.fields[0];
1269 field.set_autofilled(true); 1269 field.is_autofilled = true;
1270 GetAutoFillSuggestions(form, field); 1270 GetAutoFillSuggestions(form, field);
1271 1271
1272 // No suggestions provided, so send an empty vector as the results. 1272 // No suggestions provided, so send an empty vector as the results.
1273 // This triggers the combined message send. 1273 // This triggers the combined message send.
1274 AutocompleteSuggestionsReturned(std::vector<string16>()); 1274 AutocompleteSuggestionsReturned(std::vector<string16>());
1275 1275
1276 // Test that we sent the right message to the renderer. 1276 // Test that we sent the right message to the renderer.
1277 int page_id = 0; 1277 int page_id = 0;
1278 std::vector<string16> values; 1278 std::vector<string16> values;
1279 std::vector<string16> labels; 1279 std::vector<string16> labels;
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 // Test that we correctly fill a form that has multiple logical sections, e.g. 1470 // Test that we correctly fill a form that has multiple logical sections, e.g.
1471 // both a billing and a shipping address. 1471 // both a billing and a shipping address.
1472 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) { 1472 TEST_F(AutofillManagerTest, FillFormWithMultipleSections) {
1473 // Set up our form data. 1473 // Set up our form data.
1474 FormData form; 1474 FormData form;
1475 CreateTestAddressFormData(&form); 1475 CreateTestAddressFormData(&form);
1476 const size_t kAddressFormSize = form.fields.size(); 1476 const size_t kAddressFormSize = form.fields.size();
1477 CreateTestAddressFormData(&form); 1477 CreateTestAddressFormData(&form);
1478 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { 1478 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) {
1479 // Make sure the fields have distinct names. 1479 // Make sure the fields have distinct names.
1480 form.fields[i].set_name(form.fields[i].name() + ASCIIToUTF16("_")); 1480 form.fields[i].name = form.fields[i].name + ASCIIToUTF16("_");
1481 } 1481 }
1482 std::vector<FormData> forms(1, form); 1482 std::vector<FormData> forms(1, form);
1483 FormsSeen(forms); 1483 FormsSeen(forms);
1484 1484
1485 // Fill the first section. 1485 // Fill the first section.
1486 std::string guid = "00000000-0000-0000-0000-000000000001"; 1486 std::string guid = "00000000-0000-0000-0000-000000000001";
1487 FillAutoFillFormData(kDefaultPageID, form, form.fields[0], 1487 FillAutoFillFormData(kDefaultPageID, form, form.fields[0],
1488 autofill_manager_->PackGUIDs(std::string(), guid)); 1488 autofill_manager_->PackGUIDs(std::string(), guid));
1489 1489
1490 int page_id = 0; 1490 int page_id = 0;
1491 FormData results; 1491 FormData results;
1492 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1492 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1493 { 1493 {
1494 SCOPED_TRACE("Address 1"); 1494 SCOPED_TRACE("Address 1");
1495 1495
1496 // The second address section should be empty. 1496 // The second address section should be empty.
1497 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize); 1497 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize);
1498 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) { 1498 for (size_t i = kAddressFormSize; i < form.fields.size(); ++i) {
1499 EXPECT_EQ(string16(), results.fields[i].value()); 1499 EXPECT_EQ(string16(), results.fields[i].value);
1500 } 1500 }
1501 1501
1502 // The first address section should be filled with Elvis's data. 1502 // The first address section should be filled with Elvis's data.
1503 results.fields.resize(kAddressFormSize); 1503 results.fields.resize(kAddressFormSize);
1504 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false); 1504 ExpectFilledAddressFormElvis(page_id, results, kDefaultPageID, false);
1505 } 1505 }
1506 1506
1507 // Fill the second section, with the initiating field somewhere in the middle 1507 // Fill the second section, with the initiating field somewhere in the middle
1508 // of the section. 1508 // of the section.
1509 const int kPageID2 = 2; 1509 const int kPageID2 = 2;
1510 guid = "00000000-0000-0000-0000-000000000001"; 1510 guid = "00000000-0000-0000-0000-000000000001";
1511 ASSERT_LT(9U, kAddressFormSize); 1511 ASSERT_LT(9U, kAddressFormSize);
1512 FillAutoFillFormData(kPageID2, form, form.fields[kAddressFormSize + 9], 1512 FillAutoFillFormData(kPageID2, form, form.fields[kAddressFormSize + 9],
1513 autofill_manager_->PackGUIDs(std::string(), guid)); 1513 autofill_manager_->PackGUIDs(std::string(), guid));
1514 1514
1515 page_id = 0; 1515 page_id = 0;
1516 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1516 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1517 { 1517 {
1518 SCOPED_TRACE("Address 2"); 1518 SCOPED_TRACE("Address 2");
1519 ASSERT_EQ(results.fields.size(), form.fields.size()); 1519 ASSERT_EQ(results.fields.size(), form.fields.size());
1520 1520
1521 // The first address section should be empty. 1521 // The first address section should be empty.
1522 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize); 1522 ASSERT_EQ(results.fields.size(), 2*kAddressFormSize);
1523 for (size_t i = 0; i < kAddressFormSize; ++i) { 1523 for (size_t i = 0; i < kAddressFormSize; ++i) {
1524 EXPECT_EQ(string16(), results.fields[i].value()); 1524 EXPECT_EQ(string16(), results.fields[i].value);
1525 } 1525 }
1526 1526
1527 // The second address section should be filled with Elvis's data. 1527 // The second address section should be filled with Elvis's data.
1528 FormData secondSection = results; 1528 FormData secondSection = results;
1529 secondSection.fields.erase(secondSection.fields.begin(), 1529 secondSection.fields.erase(secondSection.fields.begin(),
1530 secondSection.fields.begin() + kAddressFormSize); 1530 secondSection.fields.begin() + kAddressFormSize);
1531 for (size_t i = 0; i < kAddressFormSize; ++i) { 1531 for (size_t i = 0; i < kAddressFormSize; ++i) {
1532 // Restore the expected field names. 1532 // Restore the expected field names.
1533 string16 name = secondSection.fields[i].name(); 1533 string16 name = secondSection.fields[i].name;
1534 string16 original_name = name.substr(0, name.size() - 1); 1534 string16 original_name = name.substr(0, name.size() - 1);
1535 secondSection.fields[i].set_name(original_name); 1535 secondSection.fields[i].name = original_name;
1536 } 1536 }
1537 ExpectFilledAddressFormElvis(page_id, secondSection, kPageID2, false); 1537 ExpectFilledAddressFormElvis(page_id, secondSection, kPageID2, false);
1538 } 1538 }
1539 } 1539 }
1540 1540
1541 // Test that we correctly fill a previously auto-filled form. 1541 // Test that we correctly fill a previously auto-filled form.
1542 TEST_F(AutofillManagerTest, FillAutoFilledForm) { 1542 TEST_F(AutofillManagerTest, FillAutoFilledForm) {
1543 // Set up our form data. 1543 // Set up our form data.
1544 FormData form; 1544 FormData form;
1545 CreateTestAddressFormData(&form); 1545 CreateTestAddressFormData(&form);
1546 // Mark one of the address fields as autofilled. 1546 // Mark one of the address fields as autofilled.
1547 form.fields[4].set_autofilled(true); 1547 form.fields[4].is_autofilled = true;
1548 CreateTestCreditCardFormData(&form, true, false); 1548 CreateTestCreditCardFormData(&form, true, false);
1549 std::vector<FormData> forms(1, form); 1549 std::vector<FormData> forms(1, form);
1550 FormsSeen(forms); 1550 FormsSeen(forms);
1551 1551
1552 // First fill the address data. 1552 // First fill the address data.
1553 std::string guid = "00000000-0000-0000-0000-000000000001"; 1553 std::string guid = "00000000-0000-0000-0000-000000000001";
1554 FillAutoFillFormData( 1554 FillAutoFillFormData(
1555 kDefaultPageID, form, *form.fields.begin(), 1555 kDefaultPageID, form, *form.fields.begin(),
1556 autofill_manager_->PackGUIDs(std::string(), guid)); 1556 autofill_manager_->PackGUIDs(std::string(), guid));
1557 1557
(...skipping 19 matching lines...) Expand all
1577 { 1577 {
1578 SCOPED_TRACE("Credit card 1"); 1578 SCOPED_TRACE("Credit card 1");
1579 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true); 1579 ExpectFilledCreditCardFormElvis(page_id, results, kPageID2, true);
1580 } 1580 }
1581 1581
1582 // Now set the credit card fields to also be auto-filled, and try again to 1582 // Now set the credit card fields to also be auto-filled, and try again to
1583 // fill the credit card data 1583 // fill the credit card data
1584 for (std::vector<FormField>::iterator iter = form.fields.begin(); 1584 for (std::vector<FormField>::iterator iter = form.fields.begin();
1585 iter != form.fields.end(); 1585 iter != form.fields.end();
1586 ++iter) { 1586 ++iter) {
1587 iter->set_autofilled(true); 1587 iter->is_autofilled = true;
1588 } 1588 }
1589 1589
1590 const int kPageID3 = 3; 1590 const int kPageID3 = 3;
1591 FillAutoFillFormData( 1591 FillAutoFillFormData(
1592 kPageID3, form, *form.fields.rbegin(), 1592 kPageID3, form, *form.fields.rbegin(),
1593 autofill_manager_->PackGUIDs(guid, std::string())); 1593 autofill_manager_->PackGUIDs(guid, std::string()));
1594 1594
1595 page_id = 0; 1595 page_id = 0;
1596 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1596 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1597 { 1597 {
(...skipping 10 matching lines...) Expand all
1608 FormData form; 1608 FormData form;
1609 form.name = ASCIIToUTF16("MyPhoneForm"); 1609 form.name = ASCIIToUTF16("MyPhoneForm");
1610 form.method = ASCIIToUTF16("POST"); 1610 form.method = ASCIIToUTF16("POST");
1611 form.origin = GURL("http://myform.com/phone_form.html"); 1611 form.origin = GURL("http://myform.com/phone_form.html");
1612 form.action = GURL("http://myform.com/phone_submit.html"); 1612 form.action = GURL("http://myform.com/phone_submit.html");
1613 form.user_submitted = true; 1613 form.user_submitted = true;
1614 1614
1615 FormField field; 1615 FormField field;
1616 autofill_test::CreateTestFormField( 1616 autofill_test::CreateTestFormField(
1617 "country code", "country code", "", "text", &field); 1617 "country code", "country code", "", "text", &field);
1618 field.set_max_length(1); 1618 field.max_length = 1;
1619 form.fields.push_back(field); 1619 form.fields.push_back(field);
1620 autofill_test::CreateTestFormField( 1620 autofill_test::CreateTestFormField(
1621 "area code", "area code", "", "text", &field); 1621 "area code", "area code", "", "text", &field);
1622 field.set_max_length(3); 1622 field.max_length = 3;
1623 form.fields.push_back(field); 1623 form.fields.push_back(field);
1624 autofill_test::CreateTestFormField( 1624 autofill_test::CreateTestFormField(
1625 "phone", "phone prefix", "1", "text", &field); 1625 "phone", "phone prefix", "1", "text", &field);
1626 field.set_max_length(3); 1626 field.max_length = 3;
1627 form.fields.push_back(field); 1627 form.fields.push_back(field);
1628 autofill_test::CreateTestFormField( 1628 autofill_test::CreateTestFormField(
1629 "-", "phone suffix", "", "text", &field); 1629 "-", "phone suffix", "", "text", &field);
1630 field.set_max_length(4); 1630 field.max_length = 4;
1631 form.fields.push_back(field); 1631 form.fields.push_back(field);
1632 autofill_test::CreateTestFormField( 1632 autofill_test::CreateTestFormField(
1633 "Phone Extension", "ext", "", "text", &field); 1633 "Phone Extension", "ext", "", "text", &field);
1634 field.set_max_length(3); 1634 field.max_length = 3;
1635 form.fields.push_back(field); 1635 form.fields.push_back(field);
1636 1636
1637 std::vector<FormData> forms(1, form); 1637 std::vector<FormData> forms(1, form);
1638 FormsSeen(forms); 1638 FormsSeen(forms);
1639 1639
1640 AutoFillProfile *work_profile = autofill_manager_->GetProfileWithGUID( 1640 AutoFillProfile *work_profile = autofill_manager_->GetProfileWithGUID(
1641 "00000000-0000-0000-0000-000000000002"); 1641 "00000000-0000-0000-0000-000000000002");
1642 ASSERT_TRUE(work_profile != NULL); 1642 ASSERT_TRUE(work_profile != NULL);
1643 const AutofillType phone_type(PHONE_HOME_NUMBER); 1643 const AutofillType phone_type(PHONE_HOME_NUMBER);
1644 string16 saved_phone = work_profile->GetFieldText(phone_type); 1644 string16 saved_phone = work_profile->GetFieldText(phone_type);
1645 1645
1646 char test_data[] = "1234567890123456"; 1646 char test_data[] = "1234567890123456";
1647 for (int i = arraysize(test_data) - 1; i >= 0; --i) { 1647 for (int i = arraysize(test_data) - 1; i >= 0; --i) {
1648 test_data[i] = 0; 1648 test_data[i] = 0;
1649 SCOPED_TRACE(StringPrintf("Testing phone: %s", test_data)); 1649 SCOPED_TRACE(StringPrintf("Testing phone: %s", test_data));
1650 work_profile->SetInfo(phone_type, ASCIIToUTF16(test_data)); 1650 work_profile->SetInfo(phone_type, ASCIIToUTF16(test_data));
1651 // The page ID sent to the AutofillManager from the RenderView, used to send 1651 // The page ID sent to the AutofillManager from the RenderView, used to send
1652 // an IPC message back to the renderer. 1652 // an IPC message back to the renderer.
1653 int page_id = 100 - i; 1653 int page_id = 100 - i;
1654 FillAutoFillFormData( 1654 FillAutoFillFormData(
1655 page_id, form, *form.fields.begin(), 1655 page_id, form, *form.fields.begin(),
1656 autofill_manager_->PackGUIDs(std::string(), work_profile->guid())); 1656 autofill_manager_->PackGUIDs(std::string(), work_profile->guid()));
1657 page_id = 0; 1657 page_id = 0;
1658 FormData results; 1658 FormData results;
1659 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results)); 1659 EXPECT_TRUE(GetAutoFillFormDataFilledMessage(&page_id, &results));
1660 1660
1661 if (i != 7) { 1661 if (i != 7) {
1662 EXPECT_EQ(ASCIIToUTF16(test_data), results.fields[2].value()); 1662 EXPECT_EQ(ASCIIToUTF16(test_data), results.fields[2].value);
1663 EXPECT_EQ(ASCIIToUTF16(test_data), results.fields[3].value()); 1663 EXPECT_EQ(ASCIIToUTF16(test_data), results.fields[3].value);
1664 } else { 1664 } else {
1665 // The only size that is parsed and split, right now is 7: 1665 // The only size that is parsed and split, right now is 7:
1666 EXPECT_EQ(ASCIIToUTF16("123"), results.fields[2].value()); 1666 EXPECT_EQ(ASCIIToUTF16("123"), results.fields[2].value);
1667 EXPECT_EQ(ASCIIToUTF16("4567"), results.fields[3].value()); 1667 EXPECT_EQ(ASCIIToUTF16("4567"), results.fields[3].value);
1668 } 1668 }
1669 } 1669 }
1670 1670
1671 work_profile->SetInfo(phone_type, saved_phone); 1671 work_profile->SetInfo(phone_type, saved_phone);
1672 } 1672 }
1673 1673
1674 // Test that we can still fill a form when a field has been removed from it. 1674 // Test that we can still fill a form when a field has been removed from it.
1675 TEST_F(AutofillManagerTest, FormChangesRemoveField) { 1675 TEST_F(AutofillManagerTest, FormChangesRemoveField) {
1676 // Set up our form data. 1676 // Set up our form data.
1677 FormData form; 1677 FormData form;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1746 #else 1746 #else
1747 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1747 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1748 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1748 prefs::kAutoFillAuxiliaryProfilesEnabled));
1749 profile()->GetPrefs()->SetBoolean( 1749 profile()->GetPrefs()->SetBoolean(
1750 prefs::kAutoFillAuxiliaryProfilesEnabled, true); 1750 prefs::kAutoFillAuxiliaryProfilesEnabled, true);
1751 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled); 1751 profile()->GetPrefs()->ClearPref(prefs::kAutoFillAuxiliaryProfilesEnabled);
1752 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean( 1752 ASSERT_FALSE(profile()->GetPrefs()->GetBoolean(
1753 prefs::kAutoFillAuxiliaryProfilesEnabled)); 1753 prefs::kAutoFillAuxiliaryProfilesEnabled));
1754 #endif 1754 #endif
1755 } 1755 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | chrome/browser/autofill/autofill_merge_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698