| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @fileoverview Runs the Polymer Autofill Settings tests. */ |
| 6 |
| 7 /** @const {string} Path to root from chrome/test/data/webui/settings/. */ |
| 8 var ROOT_PATH = '../../../../../'; |
| 9 |
| 10 // Polymer BrowserTest fixture. |
| 11 GEN_INCLUDE( |
| 12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); |
| 13 |
| 14 /** |
| 15 * @constructor |
| 16 * @extends {PolymerTest} |
| 17 */ |
| 18 function SettingsAutofillSectionBrowserTest() {} |
| 19 |
| 20 SettingsAutofillSectionBrowserTest.prototype = { |
| 21 __proto__: PolymerTest.prototype, |
| 22 |
| 23 /** @override */ |
| 24 browsePreload: |
| 25 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', |
| 26 |
| 27 /** @override */ |
| 28 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
| 29 |
| 30 /** @override */ |
| 31 setUp: function() { |
| 32 PolymerTest.prototype.setUp.call(this); |
| 33 |
| 34 // Test is run on an individual element that won't have a page language. |
| 35 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
| 36 }, |
| 37 |
| 38 /** |
| 39 * Replaces any 'x' in a string with a random number of the base. |
| 40 * @param {!string} pattern The pattern that should be used as an input. |
| 41 * @param {!number} base The number base. ie: 16 for hex or 10 for decimal. |
| 42 * @return {!string} |
| 43 * @private |
| 44 */ |
| 45 patternMaker_: function(pattern, base) { |
| 46 return pattern.replace(/x/g, function() { |
| 47 return Math.floor(Math.random() * base).toString(base); |
| 48 }); |
| 49 }, |
| 50 |
| 51 /** |
| 52 * Creates a new random GUID for testing. |
| 53 * @return {!string} |
| 54 * @private |
| 55 */ |
| 56 makeGuid_: function() { |
| 57 return this.patternMaker_('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16); |
| 58 }, |
| 59 |
| 60 /** |
| 61 * Creates a fake address entry for testing. |
| 62 * @return {!chrome.autofillPrivate.AddressEntry} |
| 63 * @private |
| 64 */ |
| 65 createFakeAddressEntry_: function() { |
| 66 var ret = {}; |
| 67 ret.guid = this.makeGuid_(); |
| 68 ret.fullNames = ['John', 'Doe']; |
| 69 ret.companyName = 'Google'; |
| 70 ret.addressLines = this.patternMaker_('xxxx Main St', 10); |
| 71 ret.addressLevel1 = "CA"; |
| 72 ret.addressLevel2 = "Venice"; |
| 73 ret.postalCode = this.patternMaker_('xxxxx', 10); |
| 74 ret.countryCode = 'US'; |
| 75 ret.phoneNumbers = [this.patternMaker_('(xxx) xxx-xxxx', 10)]; |
| 76 ret.emailAddresses = [this.patternMaker_('userxxxx@gmail.com', 16)]; |
| 77 ret.languageCode = 'EN-US'; |
| 78 ret.metadata = {isLocal: true}; |
| 79 ret.metadata.summaryLabel = ret.fullNames[0]; |
| 80 ret.metadata.summarySublabel = ' ' + ret.addressLines; |
| 81 return ret; |
| 82 }, |
| 83 |
| 84 /** |
| 85 * Creates a new random credit card entry for testing. |
| 86 * @return {!chrome.autofillPrivate.CreditCardEntry} |
| 87 * @private |
| 88 */ |
| 89 createFakeCreditCardEntry_: function() { |
| 90 var ret = {}; |
| 91 ret.guid = this.makeGuid_(); |
| 92 ret.name = 'Jane Doe'; |
| 93 ret.cardNumber = this.patternMaker_('xxxx xxxx xxxx xxxx', 10); |
| 94 ret.expirationMonth = Math.ceil(Math.random() * 11).toString(); |
| 95 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString(); |
| 96 ret.metadata = {isLocal: true}; |
| 97 var cards = ['Visa', 'Mastercard', 'Discover', 'Card']; |
| 98 var card = cards[Math.floor(Math.random() * cards.length)]; |
| 99 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4); |
| 100 return ret; |
| 101 }, |
| 102 |
| 103 /** |
| 104 * Allow the iron-list to be sized properly. |
| 105 * @param {!Object} autofillSection |
| 106 * @private |
| 107 */ |
| 108 flushAutofillSection_: function(autofillSection) { |
| 109 autofillSection.$.addressList.notifyResize(); |
| 110 autofillSection.$.creditCardList.notifyResize(); |
| 111 Polymer.dom.flush(); |
| 112 }, |
| 113 /** |
| 114 * Creates the autofill section for the given lists. |
| 115 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
| 116 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList |
| 117 * @return {!Object} |
| 118 * @private |
| 119 */ |
| 120 createAutofillSection_: function(addresses, creditCards) { |
| 121 // Create a passwords-section to use for testing. |
| 122 var section = document.createElement('settings-autofill-section'); |
| 123 section.addresses = addresses; |
| 124 section.creditCards = creditCards; |
| 125 document.body.appendChild(section); |
| 126 this.flushAutofillSection_(section); |
| 127 return section; |
| 128 }, |
| 129 }; |
| 130 |
| 131 /** |
| 132 * This test will validate that the section is loaded with data. |
| 133 */ |
| 134 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { |
| 135 var self = this; |
| 136 |
| 137 suite('AutofillSection', function() { |
| 138 test('verifyCreditCardCount', function() { |
| 139 var creditCards = [ |
| 140 self.createFakeCreditCardEntry_(), |
| 141 self.createFakeCreditCardEntry_(), |
| 142 self.createFakeCreditCardEntry_(), |
| 143 self.createFakeCreditCardEntry_(), |
| 144 self.createFakeCreditCardEntry_(), |
| 145 self.createFakeCreditCardEntry_(), |
| 146 ]; |
| 147 |
| 148 var section = self.createAutofillSection_([], creditCards); |
| 149 |
| 150 assertTrue(!!section); |
| 151 var creditCardList = section.$.creditCardList; |
| 152 assertTrue(!!creditCardList); |
| 153 assertEquals(creditCards, creditCardList.items); |
| 154 // +1 for the template element. |
| 155 assertEquals(creditCards.length + 1, creditCardList.children.length); |
| 156 }); |
| 157 |
| 158 test('verifyCreditCardFields', function() { |
| 159 var creditCard = self.createFakeCreditCardEntry_(); |
| 160 var section = self.createAutofillSection_([], [creditCard]); |
| 161 var creditCardList = section.$.creditCardList; |
| 162 var row = creditCardList.children[1]; // Skip over the template. |
| 163 assertTrue(!!row); |
| 164 |
| 165 assertEquals(creditCard.metadata.summaryLabel, |
| 166 row.querySelector('#creditCardLabel').textContent); |
| 167 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear, |
| 168 row.querySelector('#creditCardExpiration').textContent); |
| 169 }); |
| 170 |
| 171 test('verifyAddressCount', function() { |
| 172 var addresses = [ |
| 173 self.createFakeAddressEntry_(), |
| 174 self.createFakeAddressEntry_(), |
| 175 self.createFakeAddressEntry_(), |
| 176 self.createFakeAddressEntry_(), |
| 177 self.createFakeAddressEntry_(), |
| 178 ]; |
| 179 |
| 180 var section = self.createAutofillSection_(addresses, []); |
| 181 |
| 182 assertTrue(!!section); |
| 183 var addressList = section.$.addressList; |
| 184 assertTrue(!!addressList); |
| 185 assertEquals(addresses, addressList.items); |
| 186 // +1 for the template element. |
| 187 assertEquals(addresses.length + 1, addressList.children.length); |
| 188 }); |
| 189 |
| 190 test('verifyAddressFields', function() { |
| 191 var address = self.createFakeAddressEntry_(); |
| 192 var section = self.createAutofillSection_([address], []); |
| 193 var addressList = section.$.addressList; |
| 194 var row = addressList.children[1]; // Skip over the template. |
| 195 assertTrue(!!row); |
| 196 |
| 197 var addressSummary = address.metadata.summaryLabel + |
| 198 address.metadata.summarySublabel; |
| 199 |
| 200 assertEquals(addressSummary, |
| 201 row.querySelector('#addressSummary').textContent); |
| 202 }); |
| 203 }); |
| 204 |
| 205 mocha.run(); |
| 206 }); |
| OLD | NEW |