1 // Copyright (c) 2012 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.
6 * Returns the HTML element for the |field|.
7 * @param {string} field The field name for the element.
8 * @return {HTMLElement} The HTML element.
10 function getField(field
) {
11 return document
.querySelector(
12 '#autofill-edit-address-overlay [field=' + field
+ ']');
16 * Returns the size of the |list|.
17 * @param {HTMLElement} list The list to check.
18 * @return {number} The size of the list.
20 function getListSize(list
) {
21 // Remove 1 for placeholder input field.
22 return list
.items
.length
- 1;
26 * TestFixture for autofill options WebUI testing.
27 * @extends {testing.Test}
30 function AutofillOptionsWebUITest() {}
32 AutofillOptionsWebUITest
.prototype = {
33 __proto__
: testing
.Test
.prototype,
36 * Browse to autofill options.
38 browsePreload
: 'chrome://settings-frame/autofill',
41 // Test opening the autofill options has correct location.
42 TEST_F('AutofillOptionsWebUITest', 'testOpenAutofillOptions', function() {
43 assertEquals(this.browsePreload
, document
.location
.href
);
47 * TestFixture for autofill edit address overlay WebUI testing.
48 * @extends {testing.Test}
51 function AutofillEditAddressWebUITest() {}
53 AutofillEditAddressWebUITest
.prototype = {
54 __proto__
: testing
.Test
.prototype,
57 browsePreload
: 'chrome://settings-frame/autofillEditAddress',
60 TEST_F('AutofillEditAddressWebUITest', 'testInitialFormLayout', function() {
61 assertEquals(this.browsePreload
, document
.location
.href
);
63 assertEquals(getField('country').value
, '');
64 assertEquals(0, getListSize(getField('phone')));
65 assertEquals(0, getListSize(getField('email')));
66 assertEquals(0, getListSize(getField('fullName')));
67 assertEquals('', getField('city').value
);
72 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() {
73 assertEquals(this.browsePreload
, document
.location
.href
);
77 fullName
: ['Full Name 1', 'Full Name 2'],
78 companyName
: 'Company Name Value',
79 addrLines
: 'First Line Value\nSecond Line Value',
80 dependentLocality
: 'Dependent Locality Value',
83 postalCode
: 'Postal Code Value',
84 sortingCode
: 'Sorting Code Value',
86 phone
: ['123', '456'],
87 email
: ['a@b.c', 'x@y.z'],
90 {field
: 'postalCode', length
: 'short'},
91 {field
: 'sortingCode', length
: 'short'},
92 {field
: 'dependentLocality', length
: 'short'},
93 {field
: 'city', length
: 'short'},
94 {field
: 'state', length
: 'short'},
95 {field
: 'addrLines', length
: 'long'},
96 {field
: 'companyName', length
: 'long'},
97 {field
: 'country', length
: 'long'},
98 {field
: 'fullName', length
: 'long', placeholder
: 'Add name'}
101 AutofillEditAddressOverlay
.loadAddress(testAddress
);
103 var overlay
= AutofillEditAddressOverlay
.getInstance();
104 assertEquals(testAddress
.guid
, overlay
.guid_
);
105 assertEquals(testAddress
.languageCode
, overlay
.languageCode_
);
107 var lists
= ['fullName', 'email', 'phone'];
108 for (var i
in lists
) {
109 var field
= getField(lists
[i
]);
110 assertEquals(testAddress
[lists
[i
]].length
, getListSize(field
));
111 assertTrue(field
.getAttribute('placeholder').length
> 0);
112 assertTrue(field
instanceof cr
.ui
.List
);
115 var inputs
= ['companyName', 'dependentLocality', 'city', 'state',
116 'postalCode', 'sortingCode'];
117 for (var i
in inputs
) {
118 var field
= getField(inputs
[i
]);
119 assertEquals(testAddress
[inputs
[i
]], field
.value
);
120 assertTrue(field
instanceof HTMLInputElement
);
123 var addrLines
= getField('addrLines');
124 assertEquals(testAddress
.addrLines
, addrLines
.value
);
125 assertTrue(addrLines
instanceof HTMLTextAreaElement
);
127 var country
= getField('country');
128 assertEquals(testAddress
.country
, country
.value
);
129 assertTrue(country
instanceof HTMLSelectElement
);
132 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddressComponents', function() {
133 assertEquals(this.browsePreload
, document
.location
.href
);
137 components
: [[{field
: 'city'}],
140 AutofillEditAddressOverlay
.loadAddressComponents(testInput
);
142 assertEquals('fr', AutofillEditAddressOverlay
.getInstance().languageCode_
);
143 expectEquals(2, $('autofill-edit-address-fields').children
.length
);
146 TEST_F('AutofillEditAddressWebUITest', 'testFieldValuesSaved', function() {
147 assertEquals(this.browsePreload
, document
.location
.href
);
149 AutofillEditAddressOverlay
.loadAddressComponents({
151 components
: [[{field
: 'city'}]]
153 getField('city').value
= 'New York';
155 AutofillEditAddressOverlay
.loadAddressComponents({
157 components
: [[{field
: 'state'}]]
159 assertEquals(null, getField('city'));
161 AutofillEditAddressOverlay
.loadAddressComponents({
163 components
: [[{field
: 'city'}]]
165 assertEquals('New York', getField('city').value
);
169 * Class to test the autofill edit address overlay asynchronously.
170 * @extends {testing.Test}
173 function AutofillEditAddressAsyncWebUITest() {}
175 AutofillEditAddressAsyncWebUITest
.prototype = {
176 __proto__
: testing
.Test
.prototype,
179 browsePreload
: 'chrome://settings-frame/autofillEditAddress',
185 TEST_F('AutofillEditAddressAsyncWebUITest',
186 'testAutofillPhoneValueListDoneValidating',
188 assertEquals(this.browsePreload
, document
.location
.href
);
190 var phoneList
= getField('phone');
191 expectEquals(0, phoneList
.validationRequests_
);
192 phoneList
.doneValidating().then(function() {
194 var input
= phoneList
.querySelector('input');
196 document
.execCommand('insertText', false, '111-222-333');
197 assertEquals('111-222-333', input
.value
);
199 phoneList
.doneValidating().then(testDone
);