OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Returns the HTML element for the |field|. | 6 * Returns the HTML element for the |field|. |
7 * @param {string} field The field name for the element. | 7 * @param {string} field The field name for the element. |
8 * @return {HTMLElement} The HTML element. | 8 * @return {HTMLElement} The HTML element. |
9 */ | 9 */ |
10 function getField(field) { | 10 function getField(field) { |
11 return document.querySelector( | 11 return document.querySelector( |
12 '#autofill-edit-address-overlay [field=' + field + ']'); | 12 '#autofill-edit-address-overlay [field=' + field + ']'); |
13 } | 13 } |
14 | 14 |
15 /** | 15 /** |
16 * Returns the size of the |list|. | 16 * Returns the size of the |list|. |
17 * @param {HTMLElement} list The list to check. | 17 * @param {HTMLElement} list The list to check. |
18 * @return {int} The size of the list. | 18 * @return {number} The size of the list. |
19 */ | 19 */ |
20 function getListSize(list) { | 20 function getListSize(list) { |
21 // Remove 1 for placeholder input field. | 21 // Remove 1 for placeholder input field. |
22 return list.items.length - 1; | 22 return list.items.length - 1; |
23 } | 23 } |
24 | 24 |
25 /** | 25 /** |
26 * TestFixture for autofill options WebUI testing. | 26 * TestFixture for autofill options WebUI testing. |
27 * @extends {testing.Test} | 27 * @extends {testing.Test} |
28 * @constructor | 28 * @constructor |
(...skipping 17 matching lines...) Expand all Loading... |
46 /** | 46 /** |
47 * TestFixture for autofill edit address overlay WebUI testing. | 47 * TestFixture for autofill edit address overlay WebUI testing. |
48 * @extends {testing.Test} | 48 * @extends {testing.Test} |
49 * @constructor | 49 * @constructor |
50 */ | 50 */ |
51 function AutofillEditAddressWebUITest() {} | 51 function AutofillEditAddressWebUITest() {} |
52 | 52 |
53 AutofillEditAddressWebUITest.prototype = { | 53 AutofillEditAddressWebUITest.prototype = { |
54 __proto__: testing.Test.prototype, | 54 __proto__: testing.Test.prototype, |
55 | 55 |
56 /** | 56 /** @override */ |
57 * Browse to autofill edit address overlay. | |
58 */ | |
59 browsePreload: 'chrome://settings-frame/autofillEditAddress', | 57 browsePreload: 'chrome://settings-frame/autofillEditAddress', |
60 | |
61 /** @override */ | |
62 isAsync: true, | |
63 }; | 58 }; |
64 | 59 |
65 TEST_F('AutofillEditAddressWebUITest', | 60 TEST_F('AutofillEditAddressWebUITest', 'testInitialFormLayout', function() { |
66 'testAutofillPhoneValueListDoneValidating', | |
67 function() { | |
68 assertEquals(this.browsePreload, document.location.href); | |
69 | |
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 }); | |
84 | |
85 TEST_F('AutofillEditAddressWebUITest', | |
86 'testInitialFormLayout', | |
87 function() { | |
88 assertEquals(this.browsePreload, document.location.href); | 61 assertEquals(this.browsePreload, document.location.href); |
89 | 62 |
90 assertEquals(getField('country').value, ''); | 63 assertEquals(getField('country').value, ''); |
91 assertEquals(0, getListSize(getField('phone'))); | 64 assertEquals(0, getListSize(getField('phone'))); |
92 assertEquals(0, getListSize(getField('email'))); | 65 assertEquals(0, getListSize(getField('email'))); |
93 assertEquals(0, getListSize(getField('fullName'))); | 66 assertEquals(0, getListSize(getField('fullName'))); |
94 assertEquals('', getField('city').value); | 67 assertEquals('', getField('city').value); |
95 | 68 |
96 testDone(); | 69 testDone(); |
97 }); | 70 }); |
98 | 71 |
99 TEST_F('AutofillEditAddressWebUITest', | 72 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddress', function() { |
100 'testLoadAddress', | |
101 function() { | |
102 assertEquals(this.browsePreload, document.location.href); | 73 assertEquals(this.browsePreload, document.location.href); |
103 | 74 |
104 var testAddress = { | 75 var testAddress = { |
105 guid: 'GUID Value', | 76 guid: 'GUID Value', |
106 fullName: ['Full Name 1', 'Full Name 2'], | 77 fullName: ['Full Name 1', 'Full Name 2'], |
107 companyName: 'Company Name Value', | 78 companyName: 'Company Name Value', |
108 addrLines: 'First Line Value\nSecond Line Value', | 79 addrLines: 'First Line Value\nSecond Line Value', |
109 dependentLocality: 'Dependent Locality Value', | 80 dependentLocality: 'Dependent Locality Value', |
110 city: 'City Value', | 81 city: 'City Value', |
111 state: 'State Value', | 82 state: 'State Value', |
(...skipping 10 matching lines...) Expand all Loading... |
122 {field: 'city', length: 'short'}, | 93 {field: 'city', length: 'short'}, |
123 {field: 'state', length: 'short'}, | 94 {field: 'state', length: 'short'}, |
124 {field: 'addrLines', length: 'long'}, | 95 {field: 'addrLines', length: 'long'}, |
125 {field: 'companyName', length: 'long'}, | 96 {field: 'companyName', length: 'long'}, |
126 {field: 'country', length: 'long'}, | 97 {field: 'country', length: 'long'}, |
127 {field: 'fullName', length: 'long', placeholder: 'Add name'} | 98 {field: 'fullName', length: 'long', placeholder: 'Add name'} |
128 ]] | 99 ]] |
129 }; | 100 }; |
130 AutofillEditAddressOverlay.loadAddress(testAddress); | 101 AutofillEditAddressOverlay.loadAddress(testAddress); |
131 | 102 |
132 assertEquals(testAddress.guid, AutofillEditAddressOverlay.getInstance().guid); | 103 var overlay = AutofillEditAddressOverlay.getInstance(); |
133 assertEquals(testAddress.languageCode, | 104 assertEquals(testAddress.guid, overlay.guid_); |
134 AutofillEditAddressOverlay.getInstance().languageCode); | 105 assertEquals(testAddress.languageCode, overlay.languageCode_); |
135 | 106 |
136 var lists = ['fullName', 'email', 'phone']; | 107 var lists = ['fullName', 'email', 'phone']; |
137 for (var i in lists) { | 108 for (var i in lists) { |
138 var field = getField(lists[i]); | 109 var field = getField(lists[i]); |
139 assertEquals(testAddress[lists[i]].length, getListSize(field)); | 110 assertEquals(testAddress[lists[i]].length, getListSize(field)); |
140 assertTrue(field.getAttribute('placeholder').length > 0); | 111 assertTrue(field.getAttribute('placeholder').length > 0); |
141 assertTrue(field instanceof cr.ui.List); | 112 assertTrue(field instanceof cr.ui.List); |
142 } | 113 } |
143 | 114 |
144 var inputs = ['companyName', 'dependentLocality', 'city', 'state', | 115 var inputs = ['companyName', 'dependentLocality', 'city', 'state', |
145 'postalCode', 'sortingCode']; | 116 'postalCode', 'sortingCode']; |
146 for (var i in inputs) { | 117 for (var i in inputs) { |
147 var field = getField(inputs[i]); | 118 var field = getField(inputs[i]); |
148 assertEquals(testAddress[inputs[i]], field.value); | 119 assertEquals(testAddress[inputs[i]], field.value); |
149 assertTrue(field instanceof HTMLInputElement); | 120 assertTrue(field instanceof HTMLInputElement); |
150 } | 121 } |
151 | 122 |
152 var addrLines = getField('addrLines'); | 123 var addrLines = getField('addrLines'); |
153 assertEquals(testAddress.addrLines, addrLines.value); | 124 assertEquals(testAddress.addrLines, addrLines.value); |
154 assertTrue(addrLines instanceof HTMLTextAreaElement); | 125 assertTrue(addrLines instanceof HTMLTextAreaElement); |
155 | 126 |
156 var country = getField('country'); | 127 var country = getField('country'); |
157 assertEquals(testAddress.country, country.value); | 128 assertEquals(testAddress.country, country.value); |
158 assertTrue(country instanceof HTMLSelectElement); | 129 assertTrue(country instanceof HTMLSelectElement); |
159 | |
160 testDone(); | |
161 }); | 130 }); |
162 | 131 |
163 TEST_F('AutofillEditAddressWebUITest', | 132 TEST_F('AutofillEditAddressWebUITest', 'testLoadAddressComponents', function() { |
164 'testLoadAddressComponents', | |
165 function() { | |
166 assertEquals(this.browsePreload, document.location.href); | 133 assertEquals(this.browsePreload, document.location.href); |
167 | 134 |
168 var testInput = { | 135 var testInput = { |
169 languageCode: 'fr', | 136 languageCode: 'fr', |
170 components: [[{field: 'city'}], | 137 components: [[{field: 'city'}], |
171 [{field: 'state'}]] | 138 [{field: 'state'}]] |
172 }; | 139 }; |
173 AutofillEditAddressOverlay.loadAddressComponents(testInput); | 140 AutofillEditAddressOverlay.loadAddressComponents(testInput); |
174 | 141 |
175 assertEquals('fr', AutofillEditAddressOverlay.getInstance().languageCode); | 142 assertEquals('fr', AutofillEditAddressOverlay.getInstance().languageCode_); |
176 expectEquals(2, $('autofill-edit-address-fields').children.length); | 143 expectEquals(2, $('autofill-edit-address-fields').children.length); |
| 144 }); |
177 | 145 |
178 testDone(); | 146 /** |
| 147 * Class to test the autofill edit address overlay asynchronously. |
| 148 * @extends {testing.Test} |
| 149 * @constructor |
| 150 */ |
| 151 function AutofillEditAddressAsyncWebUITest() {} |
| 152 |
| 153 AutofillEditAddressAsyncWebUITest.prototype = { |
| 154 __proto__: testing.Test.prototype, |
| 155 |
| 156 /** @override */ |
| 157 browsePreload: 'chrome://settings-frame/autofillEditAddress', |
| 158 |
| 159 /** @override */ |
| 160 isAsync: true, |
| 161 }; |
| 162 |
| 163 TEST_F('AutofillEditAddressAsyncWebUITest', |
| 164 'testAutofillPhoneValueListDoneValidating', |
| 165 function() { |
| 166 assertEquals(this.browsePreload, document.location.href); |
| 167 |
| 168 var phoneList = getField('phone'); |
| 169 expectEquals(0, phoneList.validationRequests_); |
| 170 phoneList.doneValidating().then(function() { |
| 171 phoneList.focus(); |
| 172 var input = phoneList.querySelector('input'); |
| 173 input.focus(); |
| 174 document.execCommand('insertText', false, '111-222-333'); |
| 175 assertEquals('111-222-333', input.value); |
| 176 input.blur(); |
| 177 phoneList.doneValidating().then(testDone); |
| 178 }); |
179 }); | 179 }); |
OLD | NEW |