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 var fields
= ['country', 'phone', 'email', 'fullName', 'city'];
67 for (field
in fields
) {
68 assertEquals('', getField(fields
[field
]).value
, 'Field: ' + fields
[field
]);
74 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() {
75 // http://crbug.com/434502
76 // Accessibility failure was originally (and consistently) seen on Mac OS and
77 // Chromium OS. Disabling for all OSs because of a flake in Windows. There is
78 // a possibility for flake in linux too.
79 this.disableAccessibilityChecks();
81 assertEquals(this.browsePreload
, document
.location
.href
);
85 fullName
: 'Full Name 1',
86 companyName
: 'Company Name Value',
87 addrLines
: 'First Line Value\nSecond Line Value',
88 dependentLocality
: 'Dependent Locality Value',
91 postalCode
: 'Postal Code Value',
92 sortingCode
: 'Sorting Code Value',
98 {field
: 'postalCode', length
: 'short'},
99 {field
: 'sortingCode', length
: 'short'},
100 {field
: 'dependentLocality', length
: 'short'},
101 {field
: 'city', length
: 'short'},
102 {field
: 'state', length
: 'short'},
103 {field
: 'addrLines', length
: 'long'},
104 {field
: 'companyName', length
: 'long'},
105 {field
: 'country', length
: 'long'},
106 {field
: 'fullName', length
: 'long', placeholder
: 'Add name'}
109 AutofillEditAddressOverlay
.loadAddress(testAddress
);
111 var overlay
= AutofillEditAddressOverlay
.getInstance();
112 assertEquals(testAddress
.guid
, overlay
.guid_
);
113 assertEquals(testAddress
.languageCode
, overlay
.languageCode_
);
115 var inputs
= ['companyName', 'dependentLocality', 'city', 'state',
116 'postalCode', 'sortingCode', 'fullName', 'email', 'phone'];
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
);
137 components
: [[{field
: 'city'}],
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({
151 components
: [[{field
: 'city'}]]
153 getField('city').value
= 'New York';
155 AutofillEditAddressOverlay
.loadAddressComponents({
157 components
: [[{field
: 'state'}]]
159 assertEquals(null, getField('city'));
161 AutofillEditAddressOverlay
.loadAddressComponents({
163 components
: [[{field
: 'city'}]]
165 assertEquals('New York', getField('city').value
);