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 {int} 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 * Browse to autofill edit address overlay.
59 browsePreload
: 'chrome://settings-frame/autofillEditAddress',
65 TEST_F('AutofillEditAddressWebUITest',
66 'testAutofillPhoneValueListDoneValidating',
68 assertEquals(this.browsePreload
, document
.location
.href
);
70 var phoneList
= getField('phone');
71 expectEquals(0, phoneList
.validationRequests_
);
72 phoneList
.doneValidating().then(function() {
74 var input
= phoneList
.querySelector('input');
76 document
.execCommand('insertText', false, '111-222-333');
77 assertEquals('111-222-333', input
.value
);
79 phoneList
.doneValidating().then(function() {
85 TEST_F('AutofillEditAddressWebUITest',
86 'testInitialFormLayout',
88 assertEquals(this.browsePreload
, document
.location
.href
);
90 assertEquals(getField('country').value
, '');
91 assertEquals(0, getListSize(getField('phone')));
92 assertEquals(0, getListSize(getField('email')));
93 assertEquals(0, getListSize(getField('fullName')));
94 assertEquals('', getField('city').value
);
99 TEST_F('AutofillEditAddressWebUITest',
102 assertEquals(this.browsePreload
, document
.location
.href
);
106 fullName
: ['Full Name 1', 'Full Name 2'],
107 companyName
: 'Company Name Value',
108 addrLines
: 'First Line Value\nSecond Line Value',
109 dependentLocality
: 'Dependent Locality Value',
111 state
: 'State Value',
112 postalCode
: 'Postal Code Value',
113 sortingCode
: 'Sorting Code Value',
115 phone
: ['123', '456'],
116 email
: ['a@b.c', 'x@y.z'],
119 {field
: 'postalCode', length
: 'short'},
120 {field
: 'sortingCode', length
: 'short'},
121 {field
: 'dependentLocality', length
: 'short'},
122 {field
: 'city', length
: 'short'},
123 {field
: 'state', length
: 'short'},
124 {field
: 'addrLines', length
: 'long'},
125 {field
: 'companyName', length
: 'long'},
126 {field
: 'country', length
: 'long'},
127 {field
: 'fullName', length
: 'long', placeholder
: 'Add name'}
130 AutofillEditAddressOverlay
.loadAddress(testAddress
);
132 assertEquals(testAddress
.guid
, AutofillEditAddressOverlay
.getInstance().guid
);
133 assertEquals(testAddress
.languageCode
,
134 AutofillEditAddressOverlay
.getInstance().languageCode
);
136 var lists
= ['fullName', 'email', 'phone'];
137 for (var i
in lists
) {
138 var field
= getField(lists
[i
]);
139 assertEquals(testAddress
[lists
[i
]].length
, getListSize(field
));
140 assertTrue(field
.getAttribute('placeholder').length
> 0);
141 assertTrue(field
instanceof cr
.ui
.List
);
144 var inputs
= ['companyName', 'dependentLocality', 'city', 'state',
145 'postalCode', 'sortingCode'];
146 for (var i
in inputs
) {
147 var field
= getField(inputs
[i
]);
148 assertEquals(testAddress
[inputs
[i
]], field
.value
);
149 assertTrue(field
instanceof HTMLInputElement
);
152 var addrLines
= getField('addrLines');
153 assertEquals(testAddress
.addrLines
, addrLines
.value
);
154 assertTrue(addrLines
instanceof HTMLTextAreaElement
);
156 var country
= getField('country');
157 assertEquals(testAddress
.country
, country
.value
);
158 assertTrue(country
instanceof HTMLSelectElement
);
163 TEST_F('AutofillEditAddressWebUITest',
164 'testLoadAddressComponents',
166 assertEquals(this.browsePreload
, document
.location
.href
);
170 components
: [[{field
: 'city'}],
173 AutofillEditAddressOverlay
.loadAddressComponents(testInput
);
175 assertEquals('fr', AutofillEditAddressOverlay
.getInstance().languageCode
);
176 expectEquals(2, $('autofill-edit-address-fields').children
.length
);