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. |
(...skipping 13 matching lines...) Expand all Loading... | |
24 SettingsAutofillSectionBrowserTest.prototype = { | 24 SettingsAutofillSectionBrowserTest.prototype = { |
25 __proto__: PolymerTest.prototype, | 25 __proto__: PolymerTest.prototype, |
26 | 26 |
27 /** @override */ | 27 /** @override */ |
28 browsePreload: | 28 browsePreload: |
29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', | 29 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', |
30 | 30 |
31 /** @override */ | 31 /** @override */ |
32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 32 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), |
33 | 33 |
34 /** | |
35 * Title used when adding an autofill item. | |
36 * @type: {string} | |
37 * @private | |
38 */ | |
39 newTitle_: 'new-title', | |
michaelpg
2016/05/27 17:57:08
you shouldn't have to set this in a test
hcarmona
2016/05/31 21:14:06
Removed, but I had to change |browserPreload| beca
michaelpg
2016/06/03 13:51:14
dbeam, want to weigh in? Question is how to make c
Dan Beam
2016/06/03 21:44:43
I'm confused: why can't the element just do:
<lin
hcarmona
2016/06/04 00:36:47
Thanks guys, this helped me find a solution:
Inc
| |
40 | |
41 /** | |
42 * Title used when editing an autofill item. | |
43 * @type: {string} | |
44 * @private | |
45 */ | |
46 editTitle_: 'edit-title', | |
47 | |
34 /** @override */ | 48 /** @override */ |
35 setUp: function() { | 49 setUp: function() { |
36 PolymerTest.prototype.setUp.call(this); | 50 PolymerTest.prototype.setUp.call(this); |
37 | 51 |
38 // Test is run on an individual element that won't have a page language. | 52 // Test is run on an individual element that won't have a page language. |
39 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); | 53 this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
40 }, | 54 }, |
41 | 55 |
42 /** | 56 /** |
43 * Allow the iron-list to be sized properly. | 57 * Allow the iron-list to be sized properly. |
44 * @param {!Object} autofillSection | 58 * @param {!Object} autofillSection |
45 * @private | 59 * @private |
46 */ | 60 */ |
47 flushAutofillSection_: function(autofillSection) { | 61 flushAutofillSection_: function(autofillSection) { |
48 autofillSection.$.addressList.notifyResize(); | 62 autofillSection.$.addressList.notifyResize(); |
49 autofillSection.$.creditCardList.notifyResize(); | 63 autofillSection.$.creditCardList.notifyResize(); |
50 Polymer.dom.flush(); | 64 Polymer.dom.flush(); |
51 }, | 65 }, |
66 | |
52 /** | 67 /** |
53 * Creates the autofill section for the given lists. | 68 * Creates the autofill section for the given lists. |
54 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList | 69 * @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
55 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList | 70 * @param {!Array<!chrome.passwordsPrivate.ExceptionPair>} exceptionList |
56 * @return {!Object} | 71 * @return {!Object} |
57 * @private | 72 * @private |
58 */ | 73 */ |
59 createAutofillSection_: function(addresses, creditCards) { | 74 createAutofillSection_: function(addresses, creditCards) { |
60 // Create a passwords-section to use for testing. | |
61 var section = document.createElement('settings-autofill-section'); | 75 var section = document.createElement('settings-autofill-section'); |
62 section.addresses = addresses; | 76 section.addresses = addresses; |
63 section.creditCards = creditCards; | 77 section.creditCards = creditCards; |
64 document.body.appendChild(section); | 78 document.body.appendChild(section); |
65 this.flushAutofillSection_(section); | 79 this.flushAutofillSection_(section); |
66 return section; | 80 return section; |
67 }, | 81 }, |
82 | |
83 /** | |
84 * Creates the Edit Credit Card dialog. | |
85 * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem | |
86 * @return {!Object} | |
87 */ | |
88 createCreditCardDialog_: function(creditCardItem) { | |
89 var section = document.createElement('settings-credit-card-edit-dialog'); | |
90 section.newTitle = this.newTitle_; | |
91 section.editTitle = this.editTitle_; | |
92 document.body.appendChild(section); | |
93 section.open(creditCardItem); // Opening the dialog will add the item. | |
94 Polymer.dom.flush(); | |
95 return section; | |
96 }, | |
68 }; | 97 }; |
69 | 98 |
70 /** | 99 /** |
71 * This test will validate that the section is loaded with data. | 100 * This test will validate that the section is loaded with data. |
72 */ | 101 */ |
73 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { | 102 TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { |
74 var self = this; | 103 var self = this; |
75 | 104 |
76 suite('AutofillSection', function() { | 105 suite('AutofillSection', function() { |
77 test('verifyCreditCardCount', function() { | 106 test('verifyCreditCardCount', function() { |
(...skipping 22 matching lines...) Expand all Loading... | |
100 var creditCardList = section.$.creditCardList; | 129 var creditCardList = section.$.creditCardList; |
101 var row = creditCardList.children[1]; // Skip over the template. | 130 var row = creditCardList.children[1]; // Skip over the template. |
102 assertTrue(!!row); | 131 assertTrue(!!row); |
103 | 132 |
104 assertEquals(creditCard.metadata.summaryLabel, | 133 assertEquals(creditCard.metadata.summaryLabel, |
105 row.querySelector('#creditCardLabel').textContent); | 134 row.querySelector('#creditCardLabel').textContent); |
106 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear, | 135 assertEquals(creditCard.expirationMonth + '/' + creditCard.expirationYear, |
107 row.querySelector('#creditCardExpiration').textContent); | 136 row.querySelector('#creditCardExpiration').textContent); |
108 }); | 137 }); |
109 | 138 |
139 test('verifyAddCreditCardTitle', function() { | |
140 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | |
141 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
142 | |
143 assertEquals(self.newTitle_, creditCardDialog.title_); | |
144 }), | |
145 | |
146 test('verifyEditCreditCardTitle', function() { | |
147 var creditCard = FakeDataMaker.creditCardEntry(); | |
148 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
149 | |
150 assertEquals(self.editTitle_, creditCardDialog.title_); | |
151 }), | |
152 | |
153 test('verifyExpiredCreditCardYear', function() { | |
154 var creditCard = FakeDataMaker.creditCardEntry(); | |
155 | |
156 // 2015 is over unless time goes wobbly. | |
157 creditCard.expirationYear = 2015; | |
158 | |
159 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
160 var selectableYears = creditCardDialog.$.yearList.items; | |
161 var firstSelectableYear = selectableYears[0]; | |
162 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
163 | |
164 var now = new Date(); | |
165 | |
166 assertEquals('2015', firstSelectableYear.textContent); | |
167 assertEquals('' + (now.getFullYear() + 9), | |
168 lastSelectableYear.textContent); | |
169 }), | |
170 | |
171 test('verifyVeryFutureCreditCardYear', function() { | |
172 var creditCard = FakeDataMaker.creditCardEntry(); | |
173 | |
174 // Expiring 20 years from now is unusual. | |
175 var now = new Date(); | |
176 var farFutureYear = now.getFullYear() + 20; | |
177 creditCard.expirationYear = farFutureYear; | |
178 | |
179 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
180 var selectableYears = creditCardDialog.$.yearList.items; | |
181 var firstSelectableYear = selectableYears[0]; | |
182 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
183 | |
184 assertEquals('' + now.getFullYear(), firstSelectableYear.textContent); | |
185 assertEquals('' + farFutureYear, lastSelectableYear.textContent); | |
186 }), | |
187 | |
188 test('verifyVeryNormalCreditCardYear', function() { | |
189 var creditCard = FakeDataMaker.creditCardEntry(); | |
190 | |
191 // Expiring 2 years from now is not unusual. | |
192 var now = new Date(); | |
193 var nearFutureYear = now.getFullYear() + 2; | |
194 creditCard.expirationYear = nearFutureYear; | |
195 | |
196 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
197 var selectableYears = creditCardDialog.$.yearList.items; | |
198 var firstSelectableYear = selectableYears[0]; | |
199 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
200 | |
201 assertEquals('' + now.getFullYear(), firstSelectableYear.textContent); | |
202 assertEquals('' + (now.getFullYear() + 9), | |
203 lastSelectableYear.textContent); | |
204 }), | |
205 | |
206 // Test will timeout if event is not received. | |
207 test('verifySaveCreditCardEdit', function(done) { | |
208 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | |
209 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
210 | |
211 creditCardDialog.addEventListener('save-credit-card', function(event) { | |
212 assertEquals(creditCard.guid, event.detail.guid); | |
213 done(); | |
214 }); | |
215 | |
216 creditCardDialog.$.saveButton.click(); | |
217 }), | |
218 | |
219 test('verifyCancelCreditCardEdit', function(done) { | |
220 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | |
221 var creditCardDialog = self.createCreditCardDialog_(creditCard); | |
222 | |
223 creditCardDialog.addEventListener('save-credit-card', function(event) { | |
224 // Fail the test because the save event should not be called when cancel | |
225 // is clicked. | |
226 assertTrue(false); | |
227 done(); | |
228 }); | |
229 | |
230 creditCardDialog.addEventListener('iron-overlay-closed', function(event) { | |
231 // Finish test if dialog is closed. | |
232 done(); | |
233 }); | |
234 | |
235 creditCardDialog.$.cancelButton.click(); | |
236 }), | |
237 | |
110 test('verifyAddressCount', function() { | 238 test('verifyAddressCount', function() { |
111 var addresses = [ | 239 var addresses = [ |
112 FakeDataMaker.addressEntry(), | 240 FakeDataMaker.addressEntry(), |
113 FakeDataMaker.addressEntry(), | 241 FakeDataMaker.addressEntry(), |
114 FakeDataMaker.addressEntry(), | 242 FakeDataMaker.addressEntry(), |
115 FakeDataMaker.addressEntry(), | 243 FakeDataMaker.addressEntry(), |
116 FakeDataMaker.addressEntry(), | 244 FakeDataMaker.addressEntry(), |
117 ]; | 245 ]; |
118 | 246 |
119 var section = self.createAutofillSection_(addresses, []); | 247 var section = self.createAutofillSection_(addresses, []); |
(...skipping 16 matching lines...) Expand all Loading... | |
136 var addressSummary = address.metadata.summaryLabel + | 264 var addressSummary = address.metadata.summaryLabel + |
137 address.metadata.summarySublabel; | 265 address.metadata.summarySublabel; |
138 | 266 |
139 assertEquals(addressSummary, | 267 assertEquals(addressSummary, |
140 row.querySelector('#addressSummary').textContent); | 268 row.querySelector('#addressSummary').textContent); |
141 }); | 269 }); |
142 }); | 270 }); |
143 | 271 |
144 mocha.run(); | 272 mocha.run(); |
145 }); | 273 }); |
OLD | NEW |