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 */ |
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; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 done(); | 303 done(); |
204 }); | 304 }); |
205 | 305 |
206 MockInteractions.tap(creditCardDialog.$.saveButton); | 306 MockInteractions.tap(creditCardDialog.$.saveButton); |
207 }), | 307 }), |
208 | 308 |
209 test('verifyCancelCreditCardEdit', function(done) { | 309 test('verifyCancelCreditCardEdit', function(done) { |
210 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 310 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
211 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 311 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
212 | 312 |
213 creditCardDialog.addEventListener('save-credit-card', function(event) { | 313 creditCardDialog.addEventListener('save-credit-card', function() { |
214 // Fail the test because the save event should not be called when cancel | 314 // Fail the test because the save event should not be called when cancel |
215 // is clicked. | 315 // is clicked. |
216 assertTrue(false); | 316 assertTrue(false); |
217 done(); | 317 done(); |
218 }); | 318 }); |
219 | 319 |
220 creditCardDialog.addEventListener('iron-overlay-closed', function(event) { | 320 creditCardDialog.addEventListener('iron-overlay-closed', function() { |
221 // Test is |done| in a timeout in order to ensure that | 321 // Test is |done| in a timeout in order to ensure that |
222 // 'save-credit-card' is NOT fired after this test. | 322 // 'save-credit-card' is NOT fired after this test. |
223 window.setTimeout(done, 100); | 323 window.setTimeout(done, 100); |
224 }); | 324 }); |
225 | 325 |
226 MockInteractions.tap(creditCardDialog.$.cancelButton); | 326 MockInteractions.tap(creditCardDialog.$.cancelButton); |
227 }), | 327 }), |
228 | 328 |
229 test('verifyAddressCount', function() { | 329 test('verifyAddressCount', function() { |
230 var addresses = [ | 330 var addresses = [ |
(...skipping 20 matching lines...) Expand all Loading... |
251 var addressList = section.$.addressList; | 351 var addressList = section.$.addressList; |
252 var row = addressList.children[1]; // Skip over the template. | 352 var row = addressList.children[1]; // Skip over the template. |
253 assertTrue(!!row); | 353 assertTrue(!!row); |
254 | 354 |
255 var addressSummary = address.metadata.summaryLabel + | 355 var addressSummary = address.metadata.summaryLabel + |
256 address.metadata.summarySublabel; | 356 address.metadata.summarySublabel; |
257 | 357 |
258 assertEquals(addressSummary, | 358 assertEquals(addressSummary, |
259 row.querySelector('#addressSummary').textContent); | 359 row.querySelector('#addressSummary').textContent); |
260 }); | 360 }); |
| 361 |
| 362 test('verifyAddAddressDialog', function() { |
| 363 return self.createAddressDialog_( |
| 364 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { |
| 365 var title = dialog.$$('.title'); |
| 366 assertEquals(self.i18nStrings.addAddressTitle, title.textContent); |
| 367 // Shouldn't be possible to save until something is typed in. |
| 368 assertTrue(dialog.$.saveButton.disabled); |
| 369 }); |
| 370 }); |
| 371 |
| 372 test('verifyEditAddressDialog', function() { |
| 373 return self.createAddressDialog_( |
| 374 FakeDataMaker.addressEntry()).then(function(dialog) { |
| 375 var title = dialog.$$('.title'); |
| 376 assertEquals(self.i18nStrings.editAddressTitle, title.textContent); |
| 377 // Should be possible to save when editing because fields are populated. |
| 378 assertFalse(dialog.$.saveButton.disabled); |
| 379 }); |
| 380 }); |
| 381 |
| 382 test('verifyCountryIsSaved', function() { |
| 383 var address = FakeDataMaker.emptyAddressEntry(); |
| 384 return self.createAddressDialog_(address).then(function(dialog) { |
| 385 assertEquals(undefined, dialog.$.countryList.selected); |
| 386 assertEquals(undefined, address.countryCode); |
| 387 dialog.$.countryList.selected = 'US'; |
| 388 Polymer.dom.flush(); |
| 389 assertEquals('US', dialog.$.countryList.selected); |
| 390 assertEquals('US', address.countryCode); |
| 391 }); |
| 392 }); |
| 393 |
| 394 test('verifyPhoneAndEmailAreSaved', function() { |
| 395 var address = FakeDataMaker.emptyAddressEntry(); |
| 396 return self.createAddressDialog_(address).then(function(dialog) { |
| 397 assertEquals('', dialog.$.phoneInput.value); |
| 398 assertFalse(!!(address.phoneNumbers && address.phoneNumbers[0])); |
| 399 |
| 400 assertEquals('', dialog.$.emailInput.value); |
| 401 assertFalse(!!(address.emailAddresses && address.emailAddresses[0])); |
| 402 |
| 403 var phoneNumber = '(555) 555-5555'; |
| 404 var emailAddress = 'no-reply@chromium.org'; |
| 405 |
| 406 dialog.$.phoneInput.value = phoneNumber; |
| 407 dialog.$.emailInput.value = emailAddress; |
| 408 |
| 409 Polymer.dom.flush(); |
| 410 |
| 411 assertEquals(phoneNumber, dialog.$.phoneInput.value); |
| 412 assertEquals(phoneNumber, address.phoneNumbers[0]); |
| 413 |
| 414 assertEquals(emailAddress, dialog.$.emailInput.value); |
| 415 assertEquals(emailAddress, address.emailAddresses[0]); |
| 416 }); |
| 417 }); |
| 418 |
| 419 // Test will set a value of 'foo' in each text field and verify that the |
| 420 // save button is enabled, then it will clear the field and verify that the |
| 421 // save button is disabled. Test passes after all elements have been tested. |
| 422 test('verifySaveIsNotClickableIfAllInputFieldsAreEmpty', function() { |
| 423 return self.createAddressDialog_( |
| 424 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { |
| 425 var saveButton = dialog.$.saveButton; |
| 426 var testElements = |
| 427 dialog.$.dialog.querySelectorAll('paper-input,paper-textarea'); |
| 428 |
| 429 // Default country is 'US' expecting: Name, Organization, |
| 430 // Street address, City, State, ZIP code, Phone, and Email. |
| 431 assertEquals(8, testElements.length); |
| 432 |
| 433 return asyncForEach(testElements, function(element) { |
| 434 return expectEvent(dialog, 'on-update-can-save', function() { |
| 435 assertTrue(saveButton.disabled); |
| 436 element.value = 'foo'; |
| 437 }).then(function() { |
| 438 return expectEvent(dialog, 'on-update-can-save', function() { |
| 439 assertFalse(saveButton.disabled); |
| 440 element.value = ''; |
| 441 }); |
| 442 }).then(function() { |
| 443 assertTrue(saveButton.disabled); |
| 444 }); |
| 445 }); |
| 446 }); |
| 447 }); |
| 448 |
| 449 // Setting the country should allow the address to be saved. |
| 450 test('verifySaveIsNotClickableIfCountryNotSet', function() { |
| 451 return self.createAddressDialog_( |
| 452 FakeDataMaker.emptyAddressEntry()).then(function(dialog) { |
| 453 var saveButton = dialog.$.saveButton; |
| 454 var countries = dialog.$.countryList; |
| 455 |
| 456 return expectEvent(dialog, 'on-update-can-save', function() { |
| 457 assertTrue(saveButton.disabled); |
| 458 countries.selected = 'US'; |
| 459 }).then(function() { |
| 460 assertFalse(saveButton.disabled); |
| 461 countries.selected = ''; |
| 462 }).then(function() { |
| 463 assertTrue(saveButton.disabled); |
| 464 }); |
| 465 }); |
| 466 }); |
| 467 |
| 468 // Test will timeout if save-address event is not fired. |
| 469 test('verifyDefaultCountryIsAppliedWhenSaving', function() { |
| 470 var address = FakeDataMaker.emptyAddressEntry(); |
| 471 address.companyName = 'Google'; |
| 472 return self.createAddressDialog_(address).then(function(dialog) { |
| 473 return expectEvent(dialog, 'save-address', function() { |
| 474 // Verify |countryCode| is not set. |
| 475 assertEquals(undefined, address.countryCode); |
| 476 MockInteractions.tap(dialog.$.saveButton); |
| 477 }).then(function(event) { |
| 478 // 'US' is the default country for these tests. |
| 479 assertEquals('US', event.detail.countryCode); |
| 480 }); |
| 481 }); |
| 482 }); |
| 483 |
| 484 test('verifyCancelDoesNotSaveAddress', function(done) { |
| 485 self.createAddressDialog_( |
| 486 FakeDataMaker.addressEntry()).then(function(dialog) { |
| 487 dialog.addEventListener('save-address', function() { |
| 488 // Fail the test because the save event should not be called when |
| 489 // cancel is clicked. |
| 490 assertTrue(false); |
| 491 done(); |
| 492 }); |
| 493 |
| 494 dialog.addEventListener('iron-overlay-closed', function() { |
| 495 // Test is |done| in a timeout in order to ensure that |
| 496 // 'save-address' is NOT fired after this test. |
| 497 window.setTimeout(done, 100); |
| 498 }); |
| 499 |
| 500 MockInteractions.tap(dialog.$.cancelButton); |
| 501 }); |
| 502 }); |
| 503 |
| 504 // US address has 3 fields on the same line. |
| 505 test('verifyEditingUSAddress', function() { |
| 506 var address = FakeDataMaker.emptyAddressEntry(); |
| 507 |
| 508 address.fullNames = [ 'Name' ]; |
| 509 address.companyName = 'Organization'; |
| 510 address.addressLines = 'Street address'; |
| 511 address.addressLevel2 = 'City'; |
| 512 address.addressLevel1 = 'State'; |
| 513 address.postalCode = 'ZIP code'; |
| 514 address.countryCode = 'US'; |
| 515 address.phoneNumbers = [ 'Phone' ]; |
| 516 address.emailAddresses = [ 'Email' ]; |
| 517 |
| 518 return self.createAddressDialog_(address).then(function(dialog) { |
| 519 var rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 520 assertEquals(6, rows.length); |
| 521 |
| 522 // Name |
| 523 var row = rows[0]; |
| 524 var cols = row.querySelectorAll('.address-column'); |
| 525 assertEquals(1, cols.length); |
| 526 assertEquals(address.fullNames[0], cols[0].value); |
| 527 // Organization |
| 528 row = rows[1]; |
| 529 cols = row.querySelectorAll('.address-column'); |
| 530 assertEquals(1, cols.length); |
| 531 assertEquals(address.companyName, cols[0].value); |
| 532 // Street address |
| 533 row = rows[2]; |
| 534 cols = row.querySelectorAll('.address-column'); |
| 535 assertEquals(1, cols.length); |
| 536 assertEquals(address.addressLines, cols[0].value); |
| 537 // City, State, ZIP code |
| 538 row = rows[3]; |
| 539 cols = row.querySelectorAll('.address-column'); |
| 540 assertEquals(3, cols.length); |
| 541 assertEquals(address.addressLevel2, cols[0].value); |
| 542 assertEquals(address.addressLevel1, cols[1].value); |
| 543 assertEquals(address.postalCode, cols[2].value); |
| 544 // Country |
| 545 row = rows[4]; |
| 546 cols = row.querySelectorAll('.address-column'); |
| 547 assertEquals(1, cols.length); |
| 548 assertEquals('United States', cols[0].value); |
| 549 // Phone, Email |
| 550 row = rows[5]; |
| 551 cols = row.querySelectorAll('.address-column'); |
| 552 assertEquals(2, cols.length); |
| 553 assertEquals(address.phoneNumbers[0], cols[0].value); |
| 554 assertEquals(address.emailAddresses[0], cols[1].value); |
| 555 }); |
| 556 }); |
| 557 |
| 558 // GB address has 1 field per line for all lines that change. |
| 559 test('verifyEditingGBAddress', function() { |
| 560 var address = FakeDataMaker.emptyAddressEntry(); |
| 561 |
| 562 address.fullNames = [ 'Name' ]; |
| 563 address.companyName = 'Organization'; |
| 564 address.addressLines = 'Street address'; |
| 565 address.addressLevel2 = 'Post town'; |
| 566 address.addressLevel1 = 'County'; |
| 567 address.postalCode = 'Postal code'; |
| 568 address.countryCode = 'GB'; |
| 569 address.phoneNumbers = [ 'Phone' ]; |
| 570 address.emailAddresses = [ 'Email' ]; |
| 571 |
| 572 return self.createAddressDialog_(address).then(function(dialog) { |
| 573 var rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 574 assertEquals(8, rows.length); |
| 575 |
| 576 // Name |
| 577 var row = rows[0]; |
| 578 var cols = row.querySelectorAll('.address-column'); |
| 579 assertEquals(1, cols.length); |
| 580 assertEquals(address.fullNames[0], cols[0].value); |
| 581 // Organization |
| 582 row = rows[1]; |
| 583 cols = row.querySelectorAll('.address-column'); |
| 584 assertEquals(1, cols.length); |
| 585 assertEquals(address.companyName, cols[0].value); |
| 586 // Street address |
| 587 row = rows[2]; |
| 588 cols = row.querySelectorAll('.address-column'); |
| 589 assertEquals(1, cols.length); |
| 590 assertEquals(address.addressLines, cols[0].value); |
| 591 // Post Town |
| 592 row = rows[3]; |
| 593 cols = row.querySelectorAll('.address-column'); |
| 594 assertEquals(1, cols.length); |
| 595 assertEquals(address.addressLevel2, cols[0].value); |
| 596 // County |
| 597 row = rows[4]; |
| 598 cols = row.querySelectorAll('.address-column'); |
| 599 assertEquals(1, cols.length); |
| 600 assertEquals(address.addressLevel1, cols[0].value); |
| 601 // Postal code |
| 602 row = rows[5]; |
| 603 cols = row.querySelectorAll('.address-column'); |
| 604 assertEquals(1, cols.length); |
| 605 assertEquals(address.postalCode, cols[0].value); |
| 606 // Country |
| 607 row = rows[6]; |
| 608 cols = row.querySelectorAll('.address-column'); |
| 609 assertEquals(1, cols.length); |
| 610 assertEquals('United Kingdom', cols[0].value); |
| 611 // Phone, Email |
| 612 row = rows[7]; |
| 613 cols = row.querySelectorAll('.address-column'); |
| 614 assertEquals(2, cols.length); |
| 615 assertEquals(address.phoneNumbers[0], cols[0].value); |
| 616 assertEquals(address.emailAddresses[0], cols[1].value); |
| 617 }); |
| 618 }); |
| 619 |
| 620 // IL address has 2 fields on the same line and is an RTL locale. |
| 621 // RTL locale shouldn't affect this test. |
| 622 test('verifyEditingILAddress', function() { |
| 623 var address = FakeDataMaker.emptyAddressEntry(); |
| 624 |
| 625 address.fullNames = [ 'Name' ]; |
| 626 address.companyName = 'Organization'; |
| 627 address.addressLines = 'Street address'; |
| 628 address.addressLevel2 = 'City'; |
| 629 address.postalCode = 'Postal code'; |
| 630 address.countryCode = 'IL'; |
| 631 address.phoneNumbers = [ 'Phone' ]; |
| 632 address.emailAddresses = [ 'Email' ]; |
| 633 |
| 634 return self.createAddressDialog_(address).then(function(dialog) { |
| 635 var rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 636 assertEquals(6, rows.length); |
| 637 |
| 638 // Name |
| 639 var row = rows[0]; |
| 640 var cols = row.querySelectorAll('.address-column'); |
| 641 assertEquals(1, cols.length); |
| 642 assertEquals(address.fullNames[0], cols[0].value); |
| 643 // Organization |
| 644 row = rows[1]; |
| 645 cols = row.querySelectorAll('.address-column'); |
| 646 assertEquals(1, cols.length); |
| 647 assertEquals(address.companyName, cols[0].value); |
| 648 // Street address |
| 649 row = rows[2]; |
| 650 cols = row.querySelectorAll('.address-column'); |
| 651 assertEquals(1, cols.length); |
| 652 assertEquals(address.addressLines, cols[0].value); |
| 653 // City, Postal code |
| 654 row = rows[3]; |
| 655 cols = row.querySelectorAll('.address-column'); |
| 656 assertEquals(2, cols.length); |
| 657 assertEquals(address.addressLevel2, cols[0].value); |
| 658 assertEquals(address.postalCode, cols[1].value); |
| 659 // Country |
| 660 row = rows[4]; |
| 661 cols = row.querySelectorAll('.address-column'); |
| 662 assertEquals(1, cols.length); |
| 663 assertEquals('Israel', cols[0].value); |
| 664 // Phone, Email |
| 665 row = rows[5]; |
| 666 cols = row.querySelectorAll('.address-column'); |
| 667 assertEquals(2, cols.length); |
| 668 assertEquals(address.phoneNumbers[0], cols[0].value); |
| 669 assertEquals(address.emailAddresses[0], cols[1].value); |
| 670 }); |
| 671 }); |
| 672 |
| 673 // US has an extra field 'State'. Validate that this field is |
| 674 // persisted when switching to IL then back to US. |
| 675 test('verifyAddressPersistanceWhenSwitchingCountries', function() { |
| 676 var address = FakeDataMaker.emptyAddressEntry(); |
| 677 address.countryCode = 'US'; |
| 678 |
| 679 return self.createAddressDialog_(address).then(function(dialog) { |
| 680 var city = 'Los Angeles'; |
| 681 var state = 'CA'; |
| 682 var zip = '90291'; |
| 683 |
| 684 return expectEvent(dialog, 'on-update-address-wrapper', function() { |
| 685 // US: |
| 686 var rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 687 assertEquals(6, rows.length); |
| 688 |
| 689 // City, State, ZIP code |
| 690 var row = rows[3]; |
| 691 var cols = row.querySelectorAll('.address-column'); |
| 692 assertEquals(3, cols.length); |
| 693 cols[0].value = city; |
| 694 cols[1].value = state; |
| 695 cols[2].value = zip; |
| 696 |
| 697 dialog.$.countryList.selected = 'IL'; |
| 698 }).then(function() { |
| 699 return expectEvent(dialog, 'on-update-address-wrapper', function() { |
| 700 // IL: |
| 701 rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 702 assertEquals(6, rows.length); |
| 703 |
| 704 // City, Postal code |
| 705 row = rows[3]; |
| 706 cols = row.querySelectorAll('.address-column'); |
| 707 assertEquals(2, cols.length); |
| 708 assertEquals(city, cols[0].value); |
| 709 assertEquals(zip, cols[1].value); |
| 710 |
| 711 dialog.$.countryList.selected = 'US'; |
| 712 }); |
| 713 }).then(function() { |
| 714 // US: |
| 715 var rows = dialog.$.dialog.querySelectorAll('.address-row'); |
| 716 assertEquals(6, rows.length); |
| 717 |
| 718 // City, State, ZIP code |
| 719 row = rows[3]; |
| 720 cols = row.querySelectorAll('.address-column'); |
| 721 assertEquals(3, cols.length); |
| 722 assertEquals(city, cols[0].value); |
| 723 assertEquals(state, cols[1].value); |
| 724 assertEquals(zip, cols[2].value); |
| 725 }); |
| 726 }); |
| 727 }); |
261 }); | 728 }); |
262 | 729 |
263 mocha.run(); | 730 mocha.run(); |
264 }); | 731 }); |
OLD | NEW |