Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / autofill_options_browsertest.js
blob43821b205a016ea6bd8a9095aa34ce21ef59214f
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 /**
6 * Returns the HTML element for the |field|.
7 * @param {string} field The field name for the element.
8 * @return {HTMLElement} The HTML element.
9 */
10 function getField(field) {
11 return document.querySelector(
12 '#autofill-edit-address-overlay [field=' + field + ']');
15 /**
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;
25 /**
26 * TestFixture for autofill options WebUI testing.
27 * @extends {testing.Test}
28 * @constructor
30 function AutofillOptionsWebUITest() {}
32 AutofillOptionsWebUITest.prototype = {
33 __proto__: testing.Test.prototype,
35 /**
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);
44 });
46 /**
47 * TestFixture for autofill edit address overlay WebUI testing.
48 * @extends {testing.Test}
49 * @constructor
51 function AutofillEditAddressWebUITest() {}
53 AutofillEditAddressWebUITest.prototype = {
54 __proto__: testing.Test.prototype,
56 /** @override */
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);
69 testDone();
70 });
72 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() {
73 assertEquals(this.browsePreload, document.location.href);
75 var testAddress = {
76 guid: 'GUID Value',
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',
81 city: 'City Value',
82 state: 'State Value',
83 postalCode: 'Postal Code Value',
84 sortingCode: 'Sorting Code Value',
85 country: 'CH',
86 phone: ['123', '456'],
87 email: ['a@b.c', 'x@y.z'],
88 languageCode: 'de',
89 components: [[
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);
135 var testInput = {
136 languageCode: 'fr',
137 components: [[{field: 'city'}],
138 [{field: 'state'}]]
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({
150 languageCode: 'en',
151 components: [[{field: 'city'}]]
153 getField('city').value = 'New York';
155 AutofillEditAddressOverlay.loadAddressComponents({
156 languageCode: 'en',
157 components: [[{field: 'state'}]]
159 assertEquals(null, getField('city'));
161 AutofillEditAddressOverlay.loadAddressComponents({
162 languageCode: 'en',
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}
171 * @constructor
173 function AutofillEditAddressAsyncWebUITest() {}
175 AutofillEditAddressAsyncWebUITest.prototype = {
176 __proto__: testing.Test.prototype,
178 /** @override */
179 browsePreload: 'chrome://settings-frame/autofillEditAddress',
181 /** @override */
182 isAsync: true,
185 TEST_F('AutofillEditAddressAsyncWebUITest',
186 'testAutofillPhoneValueListDoneValidating',
187 function() {
188 assertEquals(this.browsePreload, document.location.href);
190 var phoneList = getField('phone');
191 expectEquals(0, phoneList.validationRequests_);
192 phoneList.doneValidating().then(function() {
193 phoneList.focus();
194 var input = phoneList.querySelector('input');
195 input.focus();
196 document.execCommand('insertText', false, '111-222-333');
197 assertEquals('111-222-333', input.value);
198 input.blur();
199 phoneList.doneValidating().then(testDone);