1eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Copyright 2013 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/autofill/core/browser/autofill_test_utils.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/guid.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/prefs/pref_service.h" 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/prefs/pref_service_factory.h" 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/prefs/testing_pref_store.h" 11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "components/autofill/core/browser/autofill_manager.h" 13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/autofill_profile.h" 14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/browser/credit_card.h" 153240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch#include "components/autofill/core/browser/field_types.h" 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/autofill_pref_names.h" 17eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "components/autofill/core/common/form_data.h" 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "components/autofill/core/common/form_field_data.h" 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/os_crypt/os_crypt.h" 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "components/pref_registry/pref_registry_syncable.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16; 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace autofill { 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)namespace test { 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace { 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)const char kSettingsOrigin[] = "Chrome settings"; 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_ptr<PrefService> PrefServiceForTesting() { 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) scoped_refptr<user_prefs::PrefRegistrySyncable> registry( 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) new user_prefs::PrefRegistrySyncable()); 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) AutofillManager::RegisterProfilePrefs(registry.get()); 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) base::PrefServiceFactory factory; 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) factory.set_user_prefs(make_scoped_refptr(new TestingPrefStore())); 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return factory.Create(registry.get()); 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)} 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void CreateTestFormField(const char* label, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* name, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* value, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* type, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FormFieldData* field) { 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) field->label = ASCIIToUTF16(label); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) field->name = ASCIIToUTF16(name); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) field->value = ASCIIToUTF16(value); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) field->form_control_type = type; 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid CreateTestAddressFormData(FormData* form) { 54eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->name = ASCIIToUTF16("MyForm"); 55eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->origin = GURL("http://myform.com/form.html"); 56eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->action = GURL("http://myform.com/submit.html"); 57eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->user_submitted = true; 58eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 59eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch FormFieldData field; 60eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("First Name", "firstname", "", "text", &field); 61eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 62eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Middle Name", "middlename", "", "text", &field); 63eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 64eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Last Name", "lastname", "", "text", &field); 65eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Address Line 1", "addr1", "", "text", &field); 67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 68eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Address Line 2", "addr2", "", "text", &field); 69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 70eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("City", "city", "", "text", &field); 71eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 72eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("State", "state", "", "text", &field); 73eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 74eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Postal Code", "zipcode", "", "text", &field); 75eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 76eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Country", "country", "", "text", &field); 77eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Phone Number", "phonenumber", "", "tel", &field); 79eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 80eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch test::CreateTestFormField("Email", "email", "", "email", &field); 81eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch form->fields.push_back(field); 82eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 83eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)inline void check_and_set( 853240926e260ce088908e02ac07a6cf7b0c0cbf44Ben Murdoch FormGroup* profile, ServerFieldType type, const char* value) { 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (value) 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) profile->SetRawInfo(type, base::UTF8ToUTF16(value)); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)AutofillProfile GetFullProfile() { 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(base::GenerateGUID(), "http://www.example.com/"); 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SetProfileInfo(&profile, 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "John", 942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "H.", 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "Doe", 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "johndoe@hades.com", 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "Underworld", 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "666 Erebus St.", 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "Apt 8", 1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "Elysium", "CA", 1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "91111", 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "US", 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) "16502111111"); 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return profile; 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 107c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)AutofillProfile GetFullProfile2() { 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) AutofillProfile profile(base::GenerateGUID(), "https://www.example.com/"); 109c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) SetProfileInfo(&profile, 110c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Jane", 111c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "A.", 112c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Smith", 113c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "jsmith@example.com", 114c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "ACME", 115c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "123 Main Street", 116c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Unit 1", 117c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "Greensdale", "MI", 118c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "48838", 119c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "US", 120c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) "13105557889"); 121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) return profile; 122c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} 123c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)AutofillProfile GetVerifiedProfile() { 12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile profile(GetFullProfile()); 12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) profile.set_origin(kSettingsOrigin); 12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return profile; 12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 12990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)AutofillProfile GetVerifiedProfile2() { 13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) AutofillProfile profile(GetFullProfile2()); 13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) profile.set_origin(kSettingsOrigin); 13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return profile; 13490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CreditCard GetCreditCard() { 13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard credit_card(base::GenerateGUID(), "http://www.example.com"); 13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SetCreditCardInfo( 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) &credit_card, "Test User", "4111111111111111" /* Visa */, "11", "2017"); 14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return credit_card; 14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 143d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)CreditCard GetCreditCard2() { 144d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) CreditCard credit_card(base::GenerateGUID(), "https://www.example.com"); 145d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) SetCreditCardInfo( 146d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) &credit_card, "Someone Else", "378282246310005" /* AmEx */, "07", "2019"); 147d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return credit_card; 148d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 149d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)CreditCard GetVerifiedCreditCard() { 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CreditCard credit_card(GetCreditCard()); 15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) credit_card.set_origin(kSettingsOrigin); 15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) return credit_card; 15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 156d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)CreditCard GetVerifiedCreditCard2() { 157d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) CreditCard credit_card(GetCreditCard2()); 158d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) credit_card.set_origin(kSettingsOrigin); 159d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) return credit_card; 160d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 161d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetProfileInfo(AutofillProfile* profile, 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* first_name, const char* middle_name, 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* last_name, const char* email, const char* company, 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* address1, const char* address2, const char* city, 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* state, const char* zipcode, const char* country, 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* phone) { 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, NAME_FIRST, first_name); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, NAME_MIDDLE, middle_name); 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, NAME_LAST, last_name); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, EMAIL_ADDRESS, email); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, COMPANY_NAME, company); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_LINE1, address1); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_LINE2, address2); 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_CITY, city); 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_STATE, state); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_ZIP, zipcode); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, ADDRESS_HOME_COUNTRY, country); 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(profile, PHONE_HOME_WHOLE_NUMBER, phone); 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetProfileInfoWithGuid(AutofillProfile* profile, 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* guid, const char* first_name, const char* middle_name, 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* last_name, const char* email, const char* company, 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* address1, const char* address2, const char* city, 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* state, const char* zipcode, const char* country, 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* phone) { 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (guid) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) profile->set_guid(guid); 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SetProfileInfo(profile, first_name, middle_name, last_name, email, 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) company, address1, address2, city, state, zipcode, country, 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) phone); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetCreditCardInfo(CreditCard* credit_card, 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* name_on_card, const char* card_number, 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char* expiration_month, const char* expiration_year) { 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(credit_card, CREDIT_CARD_NAME, name_on_card); 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(credit_card, CREDIT_CARD_NUMBER, card_number); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(credit_card, CREDIT_CARD_EXP_MONTH, expiration_month); 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) check_and_set(credit_card, CREDIT_CARD_EXP_4_DIGIT_YEAR, expiration_year); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void DisableSystemServices(PrefService* prefs) { 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use a mock Keychain rather than the OS one to store credit card data. 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_MACOSX) 207a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) OSCrypt::UseMockKeychain(true); 20846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#endif // defined(OS_MACOSX) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 21046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#if defined(OS_MACOSX) && !defined(OS_IOS) 21146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Don't use the Address Book on Mac, as it reaches out to system services. 21246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) if (prefs) 21346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) prefs->SetBoolean(prefs::kAutofillUseMacAddressBook, false); 21446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#else 21546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) // Disable auxiliary profiles for unit testing by default. 216a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) if (prefs) 217a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) prefs->SetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled, false); 21846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#endif // defined(OS_MACOSX) && !defined(OS_IOS) 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 221c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace test 222c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)} // namespace autofill 223