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 + | |
14 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', | |
15 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', | 13 ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', |
16 ]); | 14 ]); |
17 | 15 |
18 /** | 16 /** |
19 * Test implementation. | 17 * Test implementation. |
20 * @implements {settings.address.CountryDetailManager} | 18 * @implements {settings.address.CountryDetailManager} |
21 * @constructor | 19 * @constructor |
22 */ | 20 */ |
23 function CountryDetailManagerTestImpl() {} | 21 function CountryDetailManagerTestImpl() {} |
24 CountryDetailManagerTestImpl.prototype = { | 22 CountryDetailManagerTestImpl.prototype = { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 function SettingsAutofillSectionBrowserTest() {} | 89 function SettingsAutofillSectionBrowserTest() {} |
92 | 90 |
93 SettingsAutofillSectionBrowserTest.prototype = { | 91 SettingsAutofillSectionBrowserTest.prototype = { |
94 __proto__: PolymerTest.prototype, | 92 __proto__: PolymerTest.prototype, |
95 | 93 |
96 /** @override */ | 94 /** @override */ |
97 browsePreload: | 95 browsePreload: |
98 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', | 96 'chrome://md-settings/passwords_and_forms_page/autofill_section.html', |
99 | 97 |
100 /** @override */ | 98 /** @override */ |
101 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | 99 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ |
| 100 'passwords_and_autofill_fake_data.js', |
| 101 'test_util.js', |
| 102 ]), |
102 | 103 |
103 /** | 104 /** |
104 * TODO(hcarmona): Increases speed, but disables A11y checks. Enable checks | 105 * TODO(hcarmona): Increases speed, but disables A11y checks. Enable checks |
105 * when we "accessibilityIssuesAreErrors: true" for all tests. | 106 * when we "accessibilityIssuesAreErrors: true" for all tests. |
106 * @override | 107 * @override |
107 */ | 108 */ |
108 runAccessibilityChecks: false, | 109 runAccessibilityChecks: false, |
109 | 110 |
110 i18nStrings: { | 111 i18nStrings: { |
111 addAddressTitle: 'add-title', | 112 addAddressTitle: 'add-title', |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 }); | 240 }); |
240 | 241 |
241 test('verifyExpiredCreditCardYear', function() { | 242 test('verifyExpiredCreditCardYear', function() { |
242 var creditCard = FakeDataMaker.creditCardEntry(); | 243 var creditCard = FakeDataMaker.creditCardEntry(); |
243 | 244 |
244 // 2015 is over unless time goes wobbly. | 245 // 2015 is over unless time goes wobbly. |
245 var twentyFifteen = 2015; | 246 var twentyFifteen = 2015; |
246 creditCard.expirationYear = twentyFifteen.toString(); | 247 creditCard.expirationYear = twentyFifteen.toString(); |
247 | 248 |
248 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 249 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
249 var selectableYears = creditCardDialog.$.yearList.items; | |
250 var firstSelectableYear = selectableYears[0]; | |
251 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
252 | 250 |
253 var now = new Date(); | 251 return test_util.whenAttributeIs( |
254 var maxYear = now.getFullYear() + 9; | 252 creditCardDialog.$.dialog, 'open', true).then(function() { |
| 253 var now = new Date(); |
| 254 var maxYear = now.getFullYear() + 9; |
| 255 var yearOptions = creditCardDialog.$.year.options; |
255 | 256 |
256 assertEquals('2015', firstSelectableYear.textContent.trim()); | 257 assertEquals('2015', yearOptions[0].textContent.trim()); |
257 assertEquals(maxYear.toString(), lastSelectableYear.textContent.trim()); | 258 assertEquals( |
| 259 maxYear.toString(), |
| 260 yearOptions[yearOptions.length -1].textContent.trim()); |
| 261 assertEquals( |
| 262 creditCard.expirationYear, creditCardDialog.$.year.value); |
| 263 }); |
258 }); | 264 }); |
259 | 265 |
260 test('verifyVeryFutureCreditCardYear', function() { | 266 test('verifyVeryFutureCreditCardYear', function() { |
261 var creditCard = FakeDataMaker.creditCardEntry(); | 267 var creditCard = FakeDataMaker.creditCardEntry(); |
262 | 268 |
263 // Expiring 20 years from now is unusual. | 269 // Expiring 20 years from now is unusual. |
264 var now = new Date(); | 270 var now = new Date(); |
265 var farFutureYear = now.getFullYear() + 20; | 271 var farFutureYear = now.getFullYear() + 20; |
266 creditCard.expirationYear = farFutureYear.toString(); | 272 creditCard.expirationYear = farFutureYear.toString(); |
267 | 273 |
268 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 274 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
269 var selectableYears = creditCardDialog.$.yearList.items; | |
270 var firstSelectableYear = selectableYears[0]; | |
271 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
272 | 275 |
273 assertEquals(now.getFullYear().toString(), | 276 return test_util.whenAttributeIs( |
274 firstSelectableYear.textContent.trim()); | 277 creditCardDialog.$.dialog, 'open', true).then(function() { |
275 assertEquals(farFutureYear.toString(), | 278 var yearOptions = creditCardDialog.$.year.options; |
276 lastSelectableYear.textContent.trim()); | 279 |
| 280 assertEquals( |
| 281 now.getFullYear().toString(), |
| 282 yearOptions[0].textContent.trim()); |
| 283 assertEquals( |
| 284 farFutureYear.toString(), |
| 285 yearOptions[yearOptions.length -1].textContent.trim()); |
| 286 assertEquals( |
| 287 creditCard.expirationYear, creditCardDialog.$.year.value); |
| 288 }); |
277 }); | 289 }); |
278 | 290 |
279 test('verifyVeryNormalCreditCardYear', function() { | 291 test('verifyVeryNormalCreditCardYear', function() { |
280 var creditCard = FakeDataMaker.creditCardEntry(); | 292 var creditCard = FakeDataMaker.creditCardEntry(); |
281 | 293 |
282 // Expiring 2 years from now is not unusual. | 294 // Expiring 2 years from now is not unusual. |
283 var now = new Date(); | 295 var now = new Date(); |
284 var nearFutureYear = now.getFullYear() + 2; | 296 var nearFutureYear = now.getFullYear() + 2; |
285 creditCard.expirationYear = nearFutureYear.toString(); | 297 creditCard.expirationYear = nearFutureYear.toString(); |
286 var maxYear = now.getFullYear() + 9; | 298 var maxYear = now.getFullYear() + 9; |
287 | 299 |
288 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 300 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
289 var selectableYears = creditCardDialog.$.yearList.items; | |
290 var firstSelectableYear = selectableYears[0]; | |
291 var lastSelectableYear = selectableYears[selectableYears.length - 1]; | |
292 | 301 |
293 assertEquals(now.getFullYear().toString(), | 302 return test_util.whenAttributeIs( |
294 firstSelectableYear.textContent.trim()); | 303 creditCardDialog.$.dialog, 'open', true).then(function() { |
295 assertEquals(maxYear.toString(), lastSelectableYear.textContent.trim()); | 304 var yearOptions = creditCardDialog.$.year.options; |
| 305 |
| 306 assertEquals( |
| 307 now.getFullYear().toString(), |
| 308 yearOptions[0].textContent.trim()); |
| 309 assertEquals( |
| 310 maxYear.toString(), |
| 311 yearOptions[yearOptions.length -1].textContent.trim()); |
| 312 assertEquals( |
| 313 creditCard.expirationYear, creditCardDialog.$.year.value); |
| 314 }); |
296 }); | 315 }); |
297 | 316 |
298 // Test will timeout if event is not received. | 317 // Test will timeout if event is not received. |
299 test('verifySaveCreditCardEdit', function(done) { | 318 test('verifySaveCreditCardEdit', function(done) { |
300 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 319 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
301 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 320 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
302 | 321 |
303 creditCardDialog.addEventListener('save-credit-card', function(event) { | 322 return test_util.whenAttributeIs( |
304 assertEquals(creditCard.guid, event.detail.guid); | 323 creditCardDialog.$.dialog, 'open', true).then(function() { |
305 done(); | 324 creditCardDialog.addEventListener('save-credit-card', function(event) { |
| 325 assertEquals(creditCard.guid, event.detail.guid); |
| 326 done(); |
| 327 }); |
| 328 MockInteractions.tap(creditCardDialog.$.saveButton); |
306 }); | 329 }); |
307 | |
308 MockInteractions.tap(creditCardDialog.$.saveButton); | |
309 }); | 330 }); |
310 | 331 |
311 test('verifyCancelCreditCardEdit', function(done) { | 332 test('verifyCancelCreditCardEdit', function(done) { |
312 var creditCard = FakeDataMaker.emptyCreditCardEntry(); | 333 var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
313 var creditCardDialog = self.createCreditCardDialog_(creditCard); | 334 var creditCardDialog = self.createCreditCardDialog_(creditCard); |
314 | 335 |
315 creditCardDialog.addEventListener('save-credit-card', function() { | 336 return test_util.whenAttributeIs( |
316 // Fail the test because the save event should not be called when cancel | 337 creditCardDialog.$.dialog, 'open', true).then(function() { |
317 // is clicked. | 338 creditCardDialog.addEventListener('save-credit-card', function() { |
318 assertTrue(false); | 339 // Fail the test because the save event should not be called when |
319 done(); | 340 // cancel is clicked. |
| 341 assertTrue(false); |
| 342 done(); |
| 343 }); |
| 344 |
| 345 creditCardDialog.addEventListener('close', function() { |
| 346 // Test is |done| in a timeout in order to ensure that |
| 347 // 'save-credit-card' is NOT fired after this test. |
| 348 window.setTimeout(done, 100); |
| 349 }); |
| 350 |
| 351 MockInteractions.tap(creditCardDialog.$.cancelButton); |
320 }); | 352 }); |
321 | |
322 creditCardDialog.addEventListener('close', function() { | |
323 // Test is |done| in a timeout in order to ensure that | |
324 // 'save-credit-card' is NOT fired after this test. | |
325 window.setTimeout(done, 100); | |
326 }); | |
327 | |
328 MockInteractions.tap(creditCardDialog.$.cancelButton); | |
329 }); | 353 }); |
330 }); | 354 }); |
331 | 355 |
332 mocha.run(); | 356 mocha.run(); |
333 }); | 357 }); |
334 | 358 |
335 TEST_F('SettingsAutofillSectionBrowserTest', 'AddressTests', function() { | 359 TEST_F('SettingsAutofillSectionBrowserTest', 'AddressTests', function() { |
336 var self = this; | 360 var self = this; |
337 | 361 |
338 suite('AutofillSection', function() { | 362 suite('AutofillSection', function() { |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 assertEquals(city, cols[0].value); | 805 assertEquals(city, cols[0].value); |
782 assertEquals(state, cols[1].value); | 806 assertEquals(state, cols[1].value); |
783 assertEquals(zip, cols[2].value); | 807 assertEquals(zip, cols[2].value); |
784 }); | 808 }); |
785 }); | 809 }); |
786 }); | 810 }); |
787 }); | 811 }); |
788 | 812 |
789 mocha.run(); | 813 mocha.run(); |
790 }); | 814 }); |
OLD | NEW |