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