OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** @fileoverview Runs the Polymer Autofill Settings tests. */ | 5 /** @fileoverview Runs the Polymer Autofill Settings tests. */ |
6 | 6 |
7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ | 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ |
8 var ROOT_PATH = '../../../../../'; | 8 var ROOT_PATH = '../../../../../'; |
9 | 9 |
10 // Polymer BrowserTest fixture. | 10 // Polymer BrowserTest fixture. |
11 GEN_INCLUDE([ | 11 GEN_INCLUDE([ |
12 ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js', | 12 ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js', |
13 ROOT_PATH + | 13 ROOT_PATH + |
14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', | 14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', |
15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', | 15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', |
16 ]); | 16 ]); |
17 | 17 |
18 /** | 18 /** |
19 * Test implementation. | |
20 * @implements {settings.address.CountryDetailManager} | |
21 * @constructor | |
22 */ | |
23 function CountryDetailManagerTestImpl() {} | |
24 CountryDetailManagerTestImpl.prototype = { | |
25 /** @override */ | |
26 getCountryList: function() { | |
27 return new Promise(function(resolve) { | |
28 resolve([ | |
29 {name: 'United States', countryCode: 'US'}, // Default test country. | |
30 {name: 'Israel', countryCode: 'IL'}, | |
31 {name: 'United Kingdom', countryCode: 'GB'}, | |
32 ]); | |
33 }); | |
34 }, | |
35 | |
36 /** @override */ | |
37 getAddressFormat: function(countryCode) { | |
38 return new Promise(function(resolve) { | |
39 chrome.autofillPrivate.getAddressComponents(countryCode, resolve); | |
40 }); | |
41 }, | |
42 }; | |
43 | |
44 /** | |
45 * Will call |loopBody| for each item in |items|. Will only move to the next | |
46 * item after the promise from |loopBody| resolves. | |
47 * @param {!Array<Object>} items | |
48 * @param {!function(!Object):!Promise} loopBody | |
49 * @return {!Promise} | |
50 */ | |
51 function asyncForEach(items, loopBody) { | |
52 return new Promise(function(finish) { | |
53 var index = 0; | |
54 | |
55 function loop() { | |
56 var item = items[index++]; | |
57 if (item) | |
58 loopBody(item).then(loop); | |
59 else | |
60 finish(); | |
61 }; | |
62 | |
63 loop(); | |
64 }); | |
65 } | |
66 | |
67 /** | |
68 * Resolves the promise after the element fires the expected event. Will add and | |
69 * remove the listener so it is only triggered once. |causeEvent| is called | |
70 * after adding a listener to make sure that the event is captured. | |
71 * @param {!Element} element | |
72 * @param {string} eventName | |
73 * @param {function():void} causeEvent | |
74 * @return {!Promise} | |
75 */ | |
76 function expectEvent(element, eventName, causeEvent) { | |
77 return new Promise(function(resolve) { | |
78 var callback = function() { | |
79 element.removeEventListener(eventName, callback); | |
80 resolve.apply(this, arguments); | |
81 }; | |
82 element.addEventListener(eventName, callback); | |
83 causeEvent(); | |
84 }); | |
85 } | |
86 | |
87 /** | |
19 * @constructor | 88 * @constructor |
20 * @extends {PolymerTest} | 89 * @extends {PolymerTest} |
21 */ | 90 */ |
22 function SettingsAutofillSectionBrowserTest() {} | 91 function SettingsAutofillSectionBrowserTest() {} |
23 | 92 |
24 SettingsAutofillSectionBrowserTest.prototype = { | 93 SettingsAutofillSectionBrowserTest.prototype = { |
25 __proto__: PolymerTest.prototype, | 94 __proto__: PolymerTest.prototype, |
26 | 95 |
27 /** @override */ | 96 /** @override */ |
28 browsePreload: | 97 browsePreload: |
29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', | 98 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', |
30 | 99 |
31 /** @override */ | 100 /** @override */ |
32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 101 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
33 | 102 |
103 i18nStrings: { | |
104 addAddressTitle: 'add-title', | |
105 addCreditCardTitle: 'add-title', | |
106 editAddressTitle: 'edit-title', | |
107 editCreditCardTitle: 'edit-title', | |
108 }, | |
109 | |
34 /** @override */ | 110 /** @override */ |
michaelpg
2016/07/08 00:55:32
do you get any other a11y errors when running thes
hcarmona
2016/07/11 21:50:54
I've disabled the a11y checks as you suggested. I
| |
35 setUp: function() { | 111 setUp: function() { |
36 PolymerTest.prototype.setUp.call(this); | 112 PolymerTest.prototype.setUp.call(this); |
37 | 113 |
38 // Test is run on an individual element that won't have a page language. | 114 // Test is run on an individual element that won't have a page language. |
39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 115 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
40 | 116 |
41 // Faking 'strings.js' for this test. | 117 // Faking 'strings.js' for this test. |
42 loadTimeData.data = { | 118 loadTimeData.data = this.i18nStrings; |
43 editCreditCardTitle: 'edit-title', | 119 |
44 addCreditCardTitle: 'add-title' | 120 settings.address.CountryDetailManagerImpl.instance_ = |
45 }; | 121 new CountryDetailManagerTestImpl(); |
46 }, | 122 }, |
47 | 123 |
48 /** | 124 /** |
49 * Allow the iron-list to be sized properly. | 125 * Allow the iron-list to be sized properly. |
50 * @param {!Object} autofillSection | 126 * @param {!Object} autofillSection |
51 * @private | 127 * @private |
52 */ | 128 */ |
53 flushAutofillSection_: function(autofillSection) { | 129 flushAutofillSection_: function(autofillSection) { |
54 autofillSection.$.addressList.notifyResize(); | 130 autofillSection.$.addressList.notifyResize(); |
55 autofillSection.$.creditCardList.notifyResize(); | 131 autofillSection.$.creditCardList.notifyResize(); |
(...skipping 10 matching lines...) Expand all Loading... | |
66 createAutofillSection_: function(addresses, creditCards) { | 142 createAutofillSection_: function(addresses, creditCards) { |
67 var section = document.createElement('settings-autofill-section'); | 143 var section = document.createElement('settings-autofill-section'); |
68 section.addresses = addresses; | 144 section.addresses = addresses; |
69 section.creditCards = creditCards; | 145 section.creditCards = creditCards; |
70 document.body.appendChild(section); | 146 document.body.appendChild(section); |
71 this.flushAutofillSection_(section); | 147 this.flushAutofillSection_(section); |
72 return section; | 148 return section; |
73 }, | 149 }, |
74 | 150 |
75 /** | 151 /** |
152 * Creates the Edit Address dialog and fulfills the promise when the dialog | |
153 * has actually opened. | |
154 * @param {!chrome.autofillPrivate.AddressEntry} address | |
155 * @return {!Promise<Object>} | |
156 */ | |
157 createAddressDialog_: function(address) { | |
158 return new Promise(function(resolve) { | |
159 var section = document.createElement('settings-address-edit-dialog'); | |
160 document.body.appendChild(section); | |
161 var onOpen = function() { | |
162 resolve(section); | |
163 }; | |
164 section.addEventListener('iron-overlay-opened', onOpen); | |
165 | |
166 // |setTimeout| allows the dialog to async get the list of countries | |
167 // before running any tests. | |
168 window.setTimeout(function() { | |
169 section.open(address); // Opening the dialog will add the item. | |
170 Polymer.dom.flush(); | |
171 }, 0); | |
172 }); | |
173 }, | |
174 | |
175 /** | |
76 * Creates the Edit Credit Card dialog. | 176 * Creates the Edit Credit Card dialog. |
77 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem | 177 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem |
78 * @return {!Object} | 178 * @return {!Object} |
79 */ | 179 */ |
80 createCreditCardDialog_: function(creditCardItem) { | 180 createCreditCardDialog_: function(creditCardItem) { |
81 var section = document.createElement('settings-credit-card-edit-dialog'); | 181 var section = document.createElement('settings-credit-card-edit-dialog'); |
82 document.body.appendChild(section); | 182 document.body.appendChild(section); |
83 section.open(creditCardItem); // Opening the dialog will add the item. | 183 section.open(creditCardItem); // Opening the dialog will add the item. |
84 Polymer.dom.flush(); | 184 Polymer.dom.flush(); |
85 return section; | 185 return section; |
86 }, | 186 }, |
87 }; | 187 }; |
88 | 188 |
89 /** | 189 TEST_F('SettingsAutofillSectionBrowserTest', 'creditCardTests', function() { |
michaelpg
2016/07/08 00:55:32
i think the convention is for the test in TEST_F t
hcarmona
2016/07/11 21:50:54
Done.
| |
90 * This test will validate that the section is loaded with data. | |
91 */ | |
92 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { | |
93 var self = this; | 190 var self = this; |
94 | 191 |
95 suite('AutofillSection', function() { | 192 suite('AutofillSection', function() { |
96 test('verifyCreditCardCount', function() { | 193 test('verifyCreditCardCount', function() { |
97 var creditCards = [ | 194 var creditCards = [ |
98 FakeDataMaker.creditCardEntry(), | 195 FakeDataMaker.creditCardEntry(), |
99 FakeDataMaker.creditCardEntry(), | 196 FakeDataMaker.creditCardEntry(), |
100 FakeDataMaker.creditCardEntry(), | 197 FakeDataMaker.creditCardEntry(), |
101 FakeDataMaker.creditCardEntry(), | 198 FakeDataMaker.creditCardEntry(), |
102 FakeDataMaker.creditCardEntry(), | 199 FakeDataMaker.creditCardEntry(), |
(...skipping 25 matching lines...) Expand all Loading... | |
128 | 225 |
129 test('verifyAddVsEditCreditCardTitle', function() { | 226 test('verifyAddVsEditCreditCardTitle', function() { |
130 var newCreditCard = FakeDataMaker.emptyCreditCardEntry(); | 227 var newCreditCard = FakeDataMaker.emptyCreditCardEntry(); |
131 var newCreditCardDialog = self.createCreditCardDialog_(newCreditCard); | 228 var newCreditCardDialog = self.createCreditCardDialog_(newCreditCard); |
132 var oldCreditCard = FakeDataMaker.creditCardEntry(); | 229 var oldCreditCard = FakeDataMaker.creditCardEntry(); |
133 var oldCreditCardDialog = self.createCreditCardDialog_(oldCreditCard); | 230 var oldCreditCardDialog = self.createCreditCardDialog_(oldCreditCard); |
134 | 231 |
135 assertNotEquals(oldCreditCardDialog.title_, newCreditCardDialog.title_); | 232 assertNotEquals(oldCreditCardDialog.title_, newCreditCardDialog.title_); |
136 assertNotEquals('', newCreditCardDialog.title_); | 233 assertNotEquals('', newCreditCardDialog.title_); |
137 assertNotEquals('', oldCreditCardDialog.title_); | 234 assertNotEquals('', oldCreditCardDialog.title_); |
138 }), | 235 }); |
139 | 236 |
140 test('verifyExpiredCreditCardYear', function() { | 237 test('verifyExpiredCreditCardYear', function() { |
141 var creditCard = FakeDataMaker.creditCardEntry(); | 238 var creditCard = FakeDataMaker.creditCardEntry(); |
142 | 239 |
143 // 2015 is over unless time goes wobbly. | 240 // 2015 is over unless time goes wobbly. |
144 var twentyFifteen = 2015; | 241 var twentyFifteen = 2015; |
145 creditCard.expirationYear = twentyFifteen.toString(); | 242 creditCard.expirationYear = twentyFifteen.toString(); |
146 | 243 |
147 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 244 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
148 var selectableYears = creditCardDialog.$.yearList.items; | 245 var selectableYears = creditCardDialog.$.yearList.items; |
149 var firstSelectableYear = selectableYears[0]; | 246 var firstSelectableYear = selectableYears[0]; |
150 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | 247 var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
151 | 248 |
152 var now = new Date(); | 249 var now = new Date(); |
153 var maxYear = now.getFullYear() + 9; | 250 var maxYear = now.getFullYear() + 9; |
154 | 251 |
155 assertEquals('2015', firstSelectableYear.textContent); | 252 assertEquals('2015', firstSelectableYear.textContent); |
156 assertEquals(maxYear.toString(), lastSelectableYear.textContent); | 253 assertEquals(maxYear.toString(), lastSelectableYear.textContent); |
157 }), | 254 }); |
158 | 255 |
159 test('verifyVeryFutureCreditCardYear', function() { | 256 test('verifyVeryFutureCreditCardYear', function() { |
160 var creditCard = FakeDataMaker.creditCardEntry(); | 257 var creditCard = FakeDataMaker.creditCardEntry(); |
161 | 258 |
162 // Expiring 20 years from now is unusual. | 259 // Expiring 20 years from now is unusual. |
163 var now = new Date(); | 260 var now = new Date(); |
164 var farFutureYear = now.getFullYear() + 20; | 261 var farFutureYear = now.getFullYear() + 20; |
165 creditCard.expirationYear = farFutureYear.toString(); | 262 creditCard.expirationYear = farFutureYear.toString(); |
166 | 263 |
167 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 264 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
168 var selectableYears = creditCardDialog.$.yearList.items; | 265 var selectableYears = creditCardDialog.$.yearList.items; |
169 var firstSelectableYear = selectableYears[0]; | 266 var firstSelectableYear = selectableYears[0]; |
170 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | 267 var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
171 | 268 |
172 assertEquals(now.getFullYear().toString(), | 269 assertEquals(now.getFullYear().toString(), |
173 firstSelectableYear.textContent); | 270 firstSelectableYear.textContent); |
174 assertEquals(farFutureYear.toString(), lastSelectableYear.textContent); | 271 assertEquals(farFutureYear.toString(), lastSelectableYear.textContent); |
175 }), | 272 }); |
176 | 273 |
177 test('verifyVeryNormalCreditCardYear', function() { | 274 test('verifyVeryNormalCreditCardYear', function() { |
178 var creditCard = FakeDataMaker.creditCardEntry(); | 275 var creditCard = FakeDataMaker.creditCardEntry(); |
179 | 276 |
180 // Expiring 2 years from now is not unusual. | 277 // Expiring 2 years from now is not unusual. |
181 var now = new Date(); | 278 var now = new Date(); |
182 var nearFutureYear = now.getFullYear() + 2; | 279 var nearFutureYear = now.getFullYear() + 2; |
183 creditCard.expirationYear = nearFutureYear.toString(); | 280 creditCard.expirationYear = nearFutureYear.toString(); |
184 var maxYear = now.getFullYear() + 9; | 281 var maxYear = now.getFullYear() + 9; |
185 | 282 |
186 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 283 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
187 var selectableYears = creditCardDialog.$.yearList.items; | 284 var selectableYears = creditCardDialog.$.yearList.items; |
188 var firstSelectableYear = selectableYears[0]; | 285 var firstSelectableYear = selectableYears[0]; |
189 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | 286 var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
190 | 287 |
191 assertEquals(now.getFullYear().toString(), | 288 assertEquals(now.getFullYear().toString(), |
192 firstSelectableYear.textContent); | 289 firstSelectableYear.textContent); |
193 assertEquals(maxYear.toString(), lastSelectableYear.textContent); | 290 assertEquals(maxYear.toString(), lastSelectableYear.textContent); |
194 }), | 291 }); |
195 | 292 |
196 // Test will timeout if event is not received. | 293 // Test will timeout if event is not received. |
197 test('verifySaveCreditCardEdit', function(done) { | 294 test('verifySaveCreditCardEdit', function(done) { |
198 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 295 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
199 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 296 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
200 | 297 |
201 creditCardDialog.addEventListener('save-credit-card', function(event) { | 298 creditCardDialog.addEventListener('save-credit-card', function(event) { |
202 assertEquals(creditCard.guid, event.detail.guid); | 299 assertEquals(creditCard.guid, event.detail.guid); |
203 done(); | 300 done(); |
204 }); | 301 }); |
205 | 302 |
206 MockInteractions.tap(creditCardDialog.$.saveButton); | 303 MockInteractions.tap(creditCardDialog.$.saveButton); |
207 }), | 304 }); |
208 | 305 |
209 test('verifyCancelCreditCardEdit', function(done) { | 306 test('verifyCancelCreditCardEdit', function(done) { |
210 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 307 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
211 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 308 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
212 | 309 |
213 creditCardDialog.addEventListener('save-credit-card', function(event) { | 310 creditCardDialog.addEventListener('save-credit-card', function() { |
214 // Fail the test because the save event should not be called when cancel | 311 // Fail the test because the save event should not be called when cancel |
215 // is clicked. | 312 // is clicked. |
216 assertTrue(false); | 313 assertTrue(false); |
217 done(); | 314 done(); |
218 }); | 315 }); |
219 | 316 |
220 creditCardDialog.addEventListener('iron-overlay-closed', function(event) { | 317 creditCardDialog.addEventListener('iron-overlay-closed', function() { |
221 // Test is |done| in a timeout in order to ensure that | 318 // Test is |done| in a timeout in order to ensure that |
222 // 'save-credit-card' is NOT fired after this test. | 319 // 'save-credit-card' is NOT fired after this test. |
223 window.setTimeout(done, 100); | 320 window.setTimeout(done, 100); |
224 }); | 321 }); |
225 | 322 |
226 MockInteractions.tap(creditCardDialog.$.cancelButton); | 323 MockInteractions.tap(creditCardDialog.$.cancelButton); |
227 }), | 324 }); |
325 }); | |
228 | 326 |
327 mocha.run(); | |
328 }); | |
329 | |
330 TEST_F('SettingsAutofillSectionBrowserTest', 'addressTests', function() { | |
331 var self = this; | |
332 | |
333 suite('AutofillSection', function() { | |
229 test('verifyAddressCount', function() { | 334 test('verifyAddressCount', function() { |
230 var addresses = [ | 335 var addresses = [ |
231 FakeDataMaker.addressEntry(), | 336 FakeDataMaker.addressEntry(), |
232 FakeDataMaker.addressEntry(), | 337 FakeDataMaker.addressEntry(), |
233 FakeDataMaker.addressEntry(), | 338 FakeDataMaker.addressEntry(), |
234 FakeDataMaker.addressEntry(), | 339 FakeDataMaker.addressEntry(), |
235 FakeDataMaker.addressEntry(), | 340 FakeDataMaker.addressEntry(), |
236 ]; | 341 ]; |
237 | 342 |
238 var section = self.createAutofillSection_(addresses, []); | 343 var section = self.createAutofillSection_(addresses, []); |
(...skipping 12 matching lines...) Expand all Loading... | |
251 var addressList = section.$.addressList; | 356 var addressList = section.$.addressList; |
252 var row = addressList.children[1]; // Skip over the template. | 357 var row = addressList.children[1]; // Skip over the template. |
253 assertTrue(!!row); | 358 assertTrue(!!row); |
254 | 359 |
255 var addressSummary = address.metadata.summaryLabel + | 360 var addressSummary = address.metadata.summaryLabel + |
256 address.metadata.summarySublabel; | 361 address.metadata.summarySublabel; |
257 | 362 |
258 assertEquals(addressSummary, | 363 assertEquals(addressSummary, |
259 row.querySelector('#addressSummary').textContent); | 364 row.querySelector('#addressSummary').textContent); |
260 }); | 365 }); |
366 | |
367 test('verifyAddAddressDialog', function() { | |
368 return self.createAddressDialog_( | |
369 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
370 var title = dialog.$$('.title'); | |
371 assertEquals(self.i18nStrings.addAddressTitle, title.textContent); | |
372 // Shouldn't be possible to save until something is typed in. | |
373 assertTrue(dialog.$.saveButton.disabled); | |
374 }); | |
375 }); | |
376 | |
377 test('verifyEditAddressDialog', function() { | |
378 return self.createAddressDialog_( | |
379 FakeDataMaker.addressEntry()).then(function(dialog) { | |
380 var title = dialog.$$('.title'); | |
381 assertEquals(self.i18nStrings.editAddressTitle, title.textContent); | |
382 // Should be possible to save when editing because fields are populated. | |
383 assertFalse(dialog.$.saveButton.disabled); | |
384 }); | |
385 }); | |
386 | |
387 test('verifyCountryIsSaved', function() { | |
388 var address = FakeDataMaker.emptyAddressEntry(); | |
389 return self.createAddressDialog_(address).then(function(dialog) { | |
390 assertEquals(undefined, dialog.$.countryList.selected); | |
391 assertEquals(undefined, address.countryCode); | |
392 dialog.$.countryList.selected = 'US'; | |
393 Polymer.dom.flush(); | |
394 assertEquals('US', dialog.$.countryList.selected); | |
395 assertEquals('US', address.countryCode); | |
396 }); | |
397 }); | |
398 | |
399 test('verifyPhoneAndEmailAreSaved', function() { | |
400 var address = FakeDataMaker.emptyAddressEntry(); | |
401 return self.createAddressDialog_(address).then(function(dialog) { | |
402 assertEquals('', dialog.$.phoneInput.value); | |
403 assertFalse(!!(address.phoneNumbers && address.phoneNumbers[0])); | |
404 | |
405 assertEquals('', dialog.$.emailInput.value); | |
406 assertFalse(!!(address.emailAddresses && address.emailAddresses[0])); | |
407 | |
408 var phoneNumber = '(555) 555-5555'; | |
409 var emailAddress = 'no-reply@chromium.org'; | |
410 | |
411 dialog.$.phoneInput.value = phoneNumber; | |
412 dialog.$.emailInput.value = emailAddress; | |
413 | |
414 Polymer.dom.flush(); | |
415 | |
416 assertEquals(phoneNumber, dialog.$.phoneInput.value); | |
417 assertEquals(phoneNumber, address.phoneNumbers[0]); | |
418 | |
419 assertEquals(emailAddress, dialog.$.emailInput.value); | |
420 assertEquals(emailAddress, address.emailAddresses[0]); | |
421 }); | |
422 }); | |
423 | |
424 // Test will set a value of 'foo' in each text field and verify that the | |
425 // save button is enabled, then it will clear the field and verify that the | |
426 // save button is disabled. Test passes after all elements have been tested. | |
427 test('verifySaveIsNotClickableIfAllInputFieldsAreEmpty', function() { | |
428 return self.createAddressDialog_( | |
429 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
430 var saveButton = dialog.$.saveButton; | |
431 var testElements = | |
432 dialog.$.dialog.querySelectorAll('paper-input,paper-textarea'); | |
433 | |
434 // Default country is 'US' expecting: Name, Organization, | |
435 // Street address, City, State, ZIP code, Phone, and Email. | |
436 assertEquals(8, testElements.length); | |
437 | |
438 return asyncForEach(testElements, function(element) { | |
439 return expectEvent(dialog, 'on-update-can-save', function() { | |
440 assertTrue(saveButton.disabled); | |
441 element.value = 'foo'; | |
442 }).then(function() { | |
443 return expectEvent(dialog, 'on-update-can-save', function() { | |
444 assertFalse(saveButton.disabled); | |
445 element.value = ''; | |
446 }); | |
447 }).then(function() { | |
448 assertTrue(saveButton.disabled); | |
449 }); | |
450 }); | |
451 }); | |
452 }); | |
453 | |
454 // Setting the country should allow the address to be saved. | |
455 test('verifySaveIsNotClickableIfCountryNotSet', function() { | |
456 return self.createAddressDialog_( | |
457 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { | |
458 var saveButton = dialog.$.saveButton; | |
459 var countries = dialog.$.countryList; | |
460 | |
461 return expectEvent(dialog, 'on-update-can-save', function() { | |
462 assertTrue(saveButton.disabled); | |
463 countries.selected = 'US'; | |
464 }).then(function() { | |
465 assertFalse(saveButton.disabled); | |
466 countries.selected = ''; | |
467 }).then(function() { | |
468 assertTrue(saveButton.disabled); | |
469 }); | |
470 }); | |
471 }); | |
472 | |
473 // Test will timeout if save-address event is not fired. | |
474 test('verifyDefaultCountryIsAppliedWhenSaving', function() { | |
475 var address = FakeDataMaker.emptyAddressEntry(); | |
476 address.companyName = 'Google'; | |
477 return self.createAddressDialog_(address).then(function(dialog) { | |
478 return expectEvent(dialog, 'save-address', function() { | |
479 // Verify |countryCode| is not set. | |
480 assertEquals(undefined, address.countryCode); | |
481 MockInteractions.tap(dialog.$.saveButton); | |
482 }).then(function(event) { | |
483 // 'US' is the default country for these tests. | |
484 assertEquals('US', event.detail.countryCode); | |
485 }); | |
486 }); | |
487 }); | |
488 | |
489 test('verifyCancelDoesNotSaveAddress', function(done) { | |
490 self.createAddressDialog_( | |
491 FakeDataMaker.addressEntry()).then(function(dialog) { | |
492 dialog.addEventListener('save-address', function() { | |
493 // Fail the test because the save event should not be called when | |
494 // cancel is clicked. | |
495 assertTrue(false); | |
496 done(); | |
497 }); | |
498 | |
499 dialog.addEventListener('iron-overlay-closed', function() { | |
500 // Test is |done| in a timeout in order to ensure that | |
501 // 'save-address' is NOT fired after this test. | |
502 window.setTimeout(done, 100); | |
503 }); | |
504 | |
505 MockInteractions.tap(dialog.$.cancelButton); | |
506 }); | |
507 }); | |
261 }); | 508 }); |
262 | 509 |
263 mocha.run(); | 510 mocha.run(); |
511 }); | |
512 | |
513 TEST_F('SettingsAutofillSectionBrowserTest', 'addressLocaleTests', function() { | |
514 var self = this; | |
515 | |
516 suite('AutofillSection', function() { | |
517 // US address has 3 fields on the same line. | |
518 test('verifyEditingUSAddress', function() { | |
519 var address = FakeDataMaker.emptyAddressEntry(); | |
520 | |
521 address.fullNames = [ 'Name' ]; | |
522 address.companyName = 'Organization'; | |
523 address.addressLines = 'Street address'; | |
524 address.addressLevel2 = 'City'; | |
525 address.addressLevel1 = 'State'; | |
526 address.postalCode = 'ZIP code'; | |
527 address.countryCode = 'US'; | |
528 address.phoneNumbers = [ 'Phone' ]; | |
529 address.emailAddresses = [ 'Email' ]; | |
530 | |
531 return self.createAddressDialog_(address).then(function(dialog) { | |
532 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
533 assertEquals(6, rows.length); | |
534 | |
535 // Name | |
536 var row = rows[0]; | |
537 var cols = row.querySelectorAll('.address-column'); | |
538 assertEquals(1, cols.length); | |
539 assertEquals(address.fullNames[0], cols[0].value); | |
540 // Organization | |
541 row = rows[1]; | |
542 cols = row.querySelectorAll('.address-column'); | |
543 assertEquals(1, cols.length); | |
544 assertEquals(address.companyName, cols[0].value); | |
545 // Street address | |
546 row = rows[2]; | |
547 cols = row.querySelectorAll('.address-column'); | |
548 assertEquals(1, cols.length); | |
549 assertEquals(address.addressLines, cols[0].value); | |
550 // City, State, ZIP code | |
551 row = rows[3]; | |
552 cols = row.querySelectorAll('.address-column'); | |
553 assertEquals(3, cols.length); | |
554 assertEquals(address.addressLevel2, cols[0].value); | |
555 assertEquals(address.addressLevel1, cols[1].value); | |
556 assertEquals(address.postalCode, cols[2].value); | |
557 // Country | |
558 row = rows[4]; | |
559 cols = row.querySelectorAll('.address-column'); | |
560 assertEquals(1, cols.length); | |
561 assertEquals('United States', cols[0].value); | |
562 // Phone, Email | |
563 row = rows[5]; | |
564 cols = row.querySelectorAll('.address-column'); | |
565 assertEquals(2, cols.length); | |
566 assertEquals(address.phoneNumbers[0], cols[0].value); | |
567 assertEquals(address.emailAddresses[0], cols[1].value); | |
568 }); | |
569 }); | |
570 | |
571 // GB address has 1 field per line for all lines that change. | |
572 test('verifyEditingGBAddress', function() { | |
573 var address = FakeDataMaker.emptyAddressEntry(); | |
574 | |
575 address.fullNames = [ 'Name' ]; | |
576 address.companyName = 'Organization'; | |
577 address.addressLines = 'Street address'; | |
578 address.addressLevel2 = 'Post town'; | |
579 address.addressLevel1 = 'County'; | |
580 address.postalCode = 'Postal code'; | |
581 address.countryCode = 'GB'; | |
582 address.phoneNumbers = [ 'Phone' ]; | |
583 address.emailAddresses = [ 'Email' ]; | |
584 | |
585 return self.createAddressDialog_(address).then(function(dialog) { | |
586 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
587 assertEquals(8, rows.length); | |
588 | |
589 // Name | |
590 var row = rows[0]; | |
591 var cols = row.querySelectorAll('.address-column'); | |
592 assertEquals(1, cols.length); | |
593 assertEquals(address.fullNames[0], cols[0].value); | |
594 // Organization | |
595 row = rows[1]; | |
596 cols = row.querySelectorAll('.address-column'); | |
597 assertEquals(1, cols.length); | |
598 assertEquals(address.companyName, cols[0].value); | |
599 // Street address | |
600 row = rows[2]; | |
601 cols = row.querySelectorAll('.address-column'); | |
602 assertEquals(1, cols.length); | |
603 assertEquals(address.addressLines, cols[0].value); | |
604 // Post Town | |
605 row = rows[3]; | |
606 cols = row.querySelectorAll('.address-column'); | |
607 assertEquals(1, cols.length); | |
608 assertEquals(address.addressLevel2, cols[0].value); | |
609 // County | |
610 row = rows[4]; | |
611 cols = row.querySelectorAll('.address-column'); | |
612 assertEquals(1, cols.length); | |
613 assertEquals(address.addressLevel1, cols[0].value); | |
614 // Postal code | |
615 row = rows[5]; | |
616 cols = row.querySelectorAll('.address-column'); | |
617 assertEquals(1, cols.length); | |
618 assertEquals(address.postalCode, cols[0].value); | |
619 // Country | |
620 row = rows[6]; | |
621 cols = row.querySelectorAll('.address-column'); | |
622 assertEquals(1, cols.length); | |
623 assertEquals('United Kingdom', cols[0].value); | |
624 // Phone, Email | |
625 row = rows[7]; | |
626 cols = row.querySelectorAll('.address-column'); | |
627 assertEquals(2, cols.length); | |
628 assertEquals(address.phoneNumbers[0], cols[0].value); | |
629 assertEquals(address.emailAddresses[0], cols[1].value); | |
630 }); | |
631 }); | |
632 | |
633 // IL address has 2 fields on the same line and is an RTL locale. | |
634 // RTL locale shouldn't affect this test. | |
635 test('verifyEditingILAddress', function() { | |
636 var address = FakeDataMaker.emptyAddressEntry(); | |
637 | |
638 address.fullNames = [ 'Name' ]; | |
639 address.companyName = 'Organization'; | |
640 address.addressLines = 'Street address'; | |
641 address.addressLevel2 = 'City'; | |
642 address.postalCode = 'Postal code'; | |
643 address.countryCode = 'IL'; | |
644 address.phoneNumbers = [ 'Phone' ]; | |
645 address.emailAddresses = [ 'Email' ]; | |
646 | |
647 return self.createAddressDialog_(address).then(function(dialog) { | |
648 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
649 assertEquals(6, rows.length); | |
650 | |
651 // Name | |
652 var row = rows[0]; | |
653 var cols = row.querySelectorAll('.address-column'); | |
654 assertEquals(1, cols.length); | |
655 assertEquals(address.fullNames[0], cols[0].value); | |
656 // Organization | |
657 row = rows[1]; | |
658 cols = row.querySelectorAll('.address-column'); | |
659 assertEquals(1, cols.length); | |
660 assertEquals(address.companyName, cols[0].value); | |
661 // Street address | |
662 row = rows[2]; | |
663 cols = row.querySelectorAll('.address-column'); | |
664 assertEquals(1, cols.length); | |
665 assertEquals(address.addressLines, cols[0].value); | |
666 // City, Postal code | |
667 row = rows[3]; | |
668 cols = row.querySelectorAll('.address-column'); | |
669 assertEquals(2, cols.length); | |
670 assertEquals(address.addressLevel2, cols[0].value); | |
671 assertEquals(address.postalCode, cols[1].value); | |
672 // Country | |
673 row = rows[4]; | |
674 cols = row.querySelectorAll('.address-column'); | |
675 assertEquals(1, cols.length); | |
676 assertEquals('Israel', cols[0].value); | |
677 // Phone, Email | |
678 row = rows[5]; | |
679 cols = row.querySelectorAll('.address-column'); | |
680 assertEquals(2, cols.length); | |
681 assertEquals(address.phoneNumbers[0], cols[0].value); | |
682 assertEquals(address.emailAddresses[0], cols[1].value); | |
683 }); | |
684 }); | |
685 | |
686 // US has an extra field 'State'. Validate that this field is | |
687 // persisted when switching to IL then back to US. | |
688 test('verifyAddressPersistanceWhenSwitchingCountries', function() { | |
689 var address = FakeDataMaker.emptyAddressEntry(); | |
690 address.countryCode = 'US'; | |
691 | |
692 return self.createAddressDialog_(address).then(function(dialog) { | |
693 var city = 'Los Angeles'; | |
694 var state = 'CA'; | |
695 var zip = '90291'; | |
696 | |
697 return expectEvent(dialog, 'on-update-address-wrapper', function() { | |
698 // US: | |
699 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
700 assertEquals(6, rows.length); | |
701 | |
702 // City, State, ZIP code | |
703 var row = rows[3]; | |
704 var cols = row.querySelectorAll('.address-column'); | |
705 assertEquals(3, cols.length); | |
706 cols[0].value = city; | |
707 cols[1].value = state; | |
708 cols[2].value = zip; | |
709 | |
710 dialog.$.countryList.selected = 'IL'; | |
711 }).then(function() { | |
712 return expectEvent(dialog, 'on-update-address-wrapper', function() { | |
713 // IL: | |
714 rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
715 assertEquals(6, rows.length); | |
716 | |
717 // City, Postal code | |
718 row = rows[3]; | |
719 cols = row.querySelectorAll('.address-column'); | |
720 assertEquals(2, cols.length); | |
721 assertEquals(city, cols[0].value); | |
722 assertEquals(zip, cols[1].value); | |
723 | |
724 dialog.$.countryList.selected = 'US'; | |
725 }); | |
726 }).then(function() { | |
727 // US: | |
728 var rows = dialog.$.dialog.querySelectorAll('.address-row'); | |
729 assertEquals(6, rows.length); | |
730 | |
731 // City, State, ZIP code | |
732 row = rows[3]; | |
733 cols = row.querySelectorAll('.address-column'); | |
734 assertEquals(3, cols.length); | |
735 assertEquals(city, cols[0].value); | |
736 assertEquals(state, cols[1].value); | |
737 assertEquals(zip, cols[2].value); | |
738 }); | |
739 }); | |
740 }); | |
741 }); | |
742 | |
743 mocha.run(); | |
264 }); | 744 }); |
OLD | NEW |