Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / autofill_options_browsertest.js
blob6da37b9610ef55b01676662825c7e24ef46cd024
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']);
7 /**
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 + ']');
17 /**
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;
27 /**
28 * TestFixture for autofill options WebUI testing.
29 * @extends {testing.Test}
30 * @constructor
32 function AutofillOptionsWebUITest() {}
34 AutofillOptionsWebUITest.prototype = {
35 __proto__: OptionsBrowsertestBase.prototype,
37 /**
38 * Browse to autofill options.
39 * @override
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);
47 });
49 /**
50 * TestFixture for autofill edit address overlay WebUI testing.
51 * @extends {testing.Test}
52 * @constructor
54 function AutofillEditAddressWebUITest() {}
56 AutofillEditAddressWebUITest.prototype = {
57 __proto__: OptionsBrowsertestBase.prototype,
59 /** @override */
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);
72 testDone();
73 });
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);
84 var testAddress = {
85 guid: 'GUID Value',
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',
90 city: 'City Value',
91 state: 'State Value',
92 postalCode: 'Postal Code Value',
93 sortingCode: 'Sorting Code Value',
94 country: 'CH',
95 phone: ['123', '456'],
96 email: ['a@b.c', 'x@y.z'],
97 languageCode: 'de',
98 components: [[
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);
144 var testInput = {
145 languageCode: 'fr',
146 components: [[{field: 'city'}],
147 [{field: 'state'}]]
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({
159 languageCode: 'en',
160 components: [[{field: 'city'}]]
162 getField('city').value = 'New York';
164 AutofillEditAddressOverlay.loadAddressComponents({
165 languageCode: 'en',
166 components: [[{field: 'state'}]]
168 assertEquals(null, getField('city'));
170 AutofillEditAddressOverlay.loadAddressComponents({
171 languageCode: 'en',
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}
180 * @constructor
182 function AutofillEditAddressAsyncWebUITest() {}
184 AutofillEditAddressAsyncWebUITest.prototype = {
185 __proto__: testing.Test.prototype,
187 /** @override */
188 browsePreload: 'chrome://settings-frame/autofillEditAddress',
190 /** @override */
191 isAsync: true,
194 TEST_F('AutofillEditAddressAsyncWebUITest',
195 'testAutofillPhoneValueListDoneValidating',
196 function() {
197 assertEquals(this.browsePreload, document.location.href);
199 var phoneList = getField('phone');
200 expectEquals(0, phoneList.validationRequests_);
201 phoneList.doneValidating().then(function() {
202 phoneList.focus();
203 var input = phoneList.querySelector('input');
204 input.focus();
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
209 // input.blur();
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
214 // phoneList.blur();
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.
220 phoneList.blur();
221 phoneList.doneValidating().then(testDone);