Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / autofill_options_browsertest.js
blob4cbd76d66488ff2d67e7ed7de6e9a52b77c9d20e
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 {int} 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 /**
57 * Browse to autofill edit address overlay.
59 browsePreload: 'chrome://settings-frame/autofillEditAddress',
61 /** @override */
62 isAsync: true,
65 TEST_F('AutofillEditAddressWebUITest',
66 'testAutofillPhoneValueListDoneValidating',
67 function() {
68 assertEquals(this.browsePreload, document.location.href);
70 var phoneList = getField('phone');
71 expectEquals(0, phoneList.validationRequests_);
72 phoneList.doneValidating().then(function() {
73 phoneList.focus();
74 var input = phoneList.querySelector('input');
75 input.focus();
76 document.execCommand('insertText', false, '111-222-333');
77 assertEquals('111-222-333', input.value);
78 input.blur();
79 phoneList.doneValidating().then(function() {
80 testDone();
81 });
82 });
83 });
85 TEST_F('AutofillEditAddressWebUITest',
86 'testInitialFormLayout',
87 function() {
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);
96 testDone();
97 });
99 TEST_F('AutofillEditAddressWebUITest',
100 'testLoadAddress',
101 function() {
102 assertEquals(this.browsePreload, document.location.href);
104 var testAddress = {
105 guid: 'GUID Value',
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',
110 city: 'City Value',
111 state: 'State Value',
112 postalCode: 'Postal Code Value',
113 sortingCode: 'Sorting Code Value',
114 country: 'CH',
115 phone: ['123', '456'],
116 email: ['a@b.c', 'x@y.z'],
117 languageCode: 'de',
118 components: [[
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);
160 testDone();
163 TEST_F('AutofillEditAddressWebUITest',
164 'testLoadAddressComponents',
165 function() {
166 assertEquals(this.browsePreload, document.location.href);
168 var testInput = {
169 languageCode: 'fr',
170 components: [[{field: 'city'}],
171 [{field: 'state'}]]
173 AutofillEditAddressOverlay.loadAddressComponents(testInput);
175 assertEquals('fr', AutofillEditAddressOverlay.getInstance().languageCode);
176 expectEquals(2, $('autofill-edit-address-fields').children.length);
178 testDone();