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.
5 GEN_INCLUDE(['options_browsertest_base.js']);
8 * Returns the HTML element for the |field|.
9 * @param {string} field The field name for the element.
10 * @return {HTMLElement} The HTML element.
12 function getField(field
) {
13 return document
.querySelector(
14 '#autofill-edit-address-overlay [field=' + field
+ ']');
18 * Returns the size of the |list|.
19 * @param {HTMLElement} list The list to check.
20 * @return {number} The size of the list.
22 function getListSize(list
) {
23 // Remove 1 for placeholder input field.
24 return list
.items
.length
- 1;
28 * TestFixture for autofill options WebUI testing.
29 * @extends {testing.Test}
32 function AutofillOptionsWebUITest() {}
34 AutofillOptionsWebUITest
.prototype = {
35 __proto__
: OptionsBrowsertestBase
.prototype,
38 * Browse to autofill options.
41 browsePreload
: 'chrome://settings-frame/autofill',
44 // Test opening the autofill options has correct location.
45 TEST_F('AutofillOptionsWebUITest', 'testOpenAutofillOptions', function() {
46 assertEquals(this.browsePreload
, document
.location
.href
);
50 * TestFixture for autofill edit address overlay WebUI testing.
51 * @extends {testing.Test}
54 function AutofillEditAddressWebUITest() {}
56 AutofillEditAddressWebUITest
.prototype = {
57 __proto__
: OptionsBrowsertestBase
.prototype,
60 browsePreload
: 'chrome://settings-frame/autofillEditAddress',
63 TEST_F('AutofillEditAddressWebUITest', 'testInitialFormLayout', function() {
64 assertEquals(this.browsePreload
, document
.location
.href
);
66 assertEquals(getField('country').value
, '');
67 assertEquals(0, getListSize(getField('phone')));
68 assertEquals(0, getListSize(getField('email')));
69 assertEquals(0, getListSize(getField('fullName')));
70 assertEquals('', getField('city').value
);
75 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() {
76 // http://crbug.com/434502
77 // Accessibility failure was originally (and consistently) seen on Mac OS and
78 // Chromium OS. Disabling for all OSs because of a flake in Windows. There is
79 // a possibility for flake in linux too.
80 this.disableAccessibilityChecks();
82 assertEquals(this.browsePreload
, document
.location
.href
);
86 fullName
: ['Full Name 1', 'Full Name 2'],
87 companyName
: 'Company Name Value',
88 addrLines
: 'First Line Value\nSecond Line Value',
89 dependentLocality
: 'Dependent Locality Value',
92 postalCode
: 'Postal Code Value',
93 sortingCode
: 'Sorting Code Value',
95 phone
: ['123', '456'],
96 email
: ['a@b.c', 'x@y.z'],
99 {field
: 'postalCode', length
: 'short'},
100 {field
: 'sortingCode', length
: 'short'},
101 {field
: 'dependentLocality', length
: 'short'},
102 {field
: 'city', length
: 'short'},
103 {field
: 'state', length
: 'short'},
104 {field
: 'addrLines', length
: 'long'},
105 {field
: 'companyName', length
: 'long'},
106 {field
: 'country', length
: 'long'},
107 {field
: 'fullName', length
: 'long', placeholder
: 'Add name'}
110 AutofillEditAddressOverlay
.loadAddress(testAddress
);
112 var overlay
= AutofillEditAddressOverlay
.getInstance();
113 assertEquals(testAddress
.guid
, overlay
.guid_
);
114 assertEquals(testAddress
.languageCode
, overlay
.languageCode_
);
116 var lists
= ['fullName', 'email', 'phone'];
117 for (var i
in lists
) {
118 var field
= getField(lists
[i
]);
119 assertEquals(testAddress
[lists
[i
]].length
, getListSize(field
));
120 assertTrue(field
.getAttribute('placeholder').length
> 0);
121 assertTrue(field
instanceof cr
.ui
.List
);
124 var inputs
= ['companyName', 'dependentLocality', 'city', 'state',
125 'postalCode', 'sortingCode'];
126 for (var i
in inputs
) {
127 var field
= getField(inputs
[i
]);
128 assertEquals(testAddress
[inputs
[i
]], field
.value
);
129 assertTrue(field
instanceof HTMLInputElement
);
132 var addrLines
= getField('addrLines');
133 assertEquals(testAddress
.addrLines
, addrLines
.value
);
134 assertTrue(addrLines
instanceof HTMLTextAreaElement
);
136 var country
= getField('country');
137 assertEquals(testAddress
.country
, country
.value
);
138 assertTrue(country
instanceof HTMLSelectElement
);
141 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddressComponents', function() {
142 assertEquals(this.browsePreload
, document
.location
.href
);
146 components
: [[{field
: 'city'}],
149 AutofillEditAddressOverlay
.loadAddressComponents(testInput
);
151 assertEquals('fr', AutofillEditAddressOverlay
.getInstance().languageCode_
);
152 expectEquals(2, $('autofill-edit-address-fields').children
.length
);
155 TEST_F('AutofillEditAddressWebUITest', 'testFieldValuesSaved', function() {
156 assertEquals(this.browsePreload
, document
.location
.href
);
158 AutofillEditAddressOverlay
.loadAddressComponents({
160 components
: [[{field
: 'city'}]]
162 getField('city').value
= 'New York';
164 AutofillEditAddressOverlay
.loadAddressComponents({
166 components
: [[{field
: 'state'}]]
168 assertEquals(null, getField('city'));
170 AutofillEditAddressOverlay
.loadAddressComponents({
172 components
: [[{field
: 'city'}]]
174 assertEquals('New York', getField('city').value
);
178 * Class to test the autofill edit address overlay asynchronously.
179 * @extends {testing.Test}
182 function AutofillEditAddressAsyncWebUITest() {}
184 AutofillEditAddressAsyncWebUITest
.prototype = {
185 __proto__
: testing
.Test
.prototype,
188 browsePreload
: 'chrome://settings-frame/autofillEditAddress',
194 TEST_F('AutofillEditAddressAsyncWebUITest',
195 'testAutofillPhoneValueListDoneValidating',
197 assertEquals(this.browsePreload
, document
.location
.href
);
199 var phoneList
= getField('phone');
200 expectEquals(0, phoneList
.validationRequests_
);
201 phoneList
.doneValidating().then(function() {
203 var input
= phoneList
.querySelector('input');
205 document
.execCommand('insertText', false, '111-222-333');
206 assertEquals('111-222-333', input
.value
);
207 // TODO(bondd, dbeam): The way that focus/blur interact with the testing
208 // system is rather confusing. The next line was originally
210 // but the test would time out when run as a single test locally (i.e.
211 // --gtest_filter=<test_name>), and complete successfully when other tests
212 // were run first (e.g. by the trybot, or locally with a wider
213 // gtest_filter). Changing the line to
215 // makes the result more deterministic when the test is run by itself.
217 // phoneList.blur() calls cr.ui.List.handleElementBlur_, which triggers
218 // InlineEditableItemList.handleListFocusChange_, which sends the
219 // 'commitedit' event.
221 phoneList
.doneValidating().then(testDone
);