1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // This just tests the interface. It does not test for specific results, only
6 // that callbacks are correctly invoked, expected parameters are correct,
7 // and failures are detected.
10 function saveAddress() {
14 var handler = function(addressList) {
18 chrome.test.assertEq(addressList.length, 0);
20 chrome.test.assertEq(addressList.length, 1);
21 var address = addressList[0];
22 chrome.test.assertEq(address.fullNames[0], NAME);
23 chrome.test.succeed();
27 chrome.autofillPrivate.onAddressListChanged.addListener(handler);
28 chrome.autofillPrivate.saveAddress({fullNames: [NAME]});
31 function getAddressComponents() {
32 var COUNTRY_CODE = 'US';
34 var handler = function(components) {
35 chrome.test.assertTrue(!!components.components);
36 chrome.test.assertTrue(!!components.components[0]);
37 chrome.test.assertTrue(!!components.components[0].row);
38 chrome.test.assertTrue(!!components.components[0].row[0]);
39 chrome.test.assertTrue(!!components.components[0].row[0].field);
40 chrome.test.assertTrue(!!components.components[0].row[0].fieldName);
41 chrome.test.assertTrue(!!components.languageCode);
42 chrome.test.succeed();
45 chrome.autofillPrivate.getAddressComponents(COUNTRY_CODE, handler);
48 function saveCreditCard() {
52 var handler = function(creditCardList) {
56 chrome.test.assertEq(creditCardList.length, 0);
58 chrome.test.assertEq(creditCardList.length, 1);
59 var creditCard = creditCardList[0];
60 chrome.test.assertEq(creditCard.name, NAME);
61 chrome.test.succeed();
65 chrome.autofillPrivate.onCreditCardListChanged.addListener(handler);
66 chrome.autofillPrivate.saveCreditCard({name: NAME});
69 function removeEntry() {
74 var handler = function(creditCardList) {
78 chrome.test.assertEq(creditCardList.length, 0);
79 } else if (numCalls == 2) {
80 chrome.test.assertEq(creditCardList.length, 1);
81 var creditCard = creditCardList[0];
82 chrome.test.assertEq(creditCard.name, NAME);
84 guid = creditCard.guid;
85 chrome.autofillPrivate.removeEntry(guid);
87 chrome.test.assertEq(creditCardList.length, 0);
88 chrome.test.succeed();
92 chrome.autofillPrivate.onCreditCardListChanged.addListener(handler);
93 chrome.autofillPrivate.saveCreditCard({name: NAME});
96 function validatePhoneNumbers() {
97 var COUNTRY_CODE = 'US';
98 var ORIGINAL_NUMBERS = ['1-800-123-4567'];
99 var FIRST_NUMBER_TO_ADD = '1-800-234-5768';
100 // Same as original number, but without formatting.
101 var SECOND_NUMBER_TO_ADD = '18001234567';
103 var handler1 = function(validateNumbers) {
104 chrome.test.assertEq(validateNumbers.length, 1);
105 chrome.test.assertEq('1-800-123-4567', validateNumbers[0]);
107 chrome.autofillPrivate.validatePhoneNumbers({
108 phoneNumbers: validatedNumbers.concat(FIRST_NUMBER_TO_ADD),
110 countryCode: COUNTRY_CODE
114 var handler2 = function(validatedNumbers) {
115 chrome.test.assertEq(validateNumbers.length, 2);
116 chrome.test.assertEq('1-800-123-4567', validateNumbers[0]);
117 chrome.test.assertEq('1-800-234-5678', validateNumbers[1]);
119 chrome.autofillPrivate.validatePhoneNumbers({
120 phoneNumbers: validatedNumbers.concat(SECOND_NUMBER_TO_ADD),
122 countryCode: COUNTRY_CODE
126 var handler3 = function(validateNumbers) {
127 // Newly-added number should not appear since it was the same as an
129 chrome.test.assertEq(validateNumbers.length, 2);
130 chrome.test.assertEq('1-800-123-4567', validateNumbers[0]);
131 chrome.test.assertEq('1-800-234-5678', validateNumbers[1]);
132 chrome.test.succeed();
135 chrome.autofillPrivate.validatePhoneNumbers({
136 phoneNumbers: ORIGINAL_NUMBERS,
138 countryCode: COUNTRY_CODE
143 var testToRun = window.location.search.substring(1);
144 chrome.test.runTests(availableTests.filter(function(op) {
145 return op.name == testToRun;