Index: chrome/test/data/webui/settings/settings_autofill_section_browsertest.js |
diff --git a/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js b/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js |
index 7876c3376c433577ff303ea59ce9b0c8052c3ed8..e4bc7011e3d3fbc3af324fca74d5ed7d910b3abc 100644 |
--- a/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js |
+++ b/chrome/test/data/webui/settings/settings_autofill_section_browsertest.js |
@@ -8,12 +8,12 @@ |
var ROOT_PATH = '../../../../../'; |
// Polymer BrowserTest fixture. |
-GEN_INCLUDE( |
- [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); |
- |
-// Fake data generator. |
-GEN_INCLUDE([ROOT_PATH + |
- 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js']); |
+GEN_INCLUDE([ |
+ ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js', |
+ ROOT_PATH + |
+ 'chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js', |
+ ROOT_PATH + 'ui/webui/resources/js/load_time_data.js', |
+]); |
/** |
* @constructor |
@@ -37,6 +37,12 @@ SettingsAutofillSectionBrowserTest.prototype = { |
// Test is run on an individual element that won't have a page language. |
this.accessibilityAuditConfig.auditRulesToIgnore.push('humanLangMissing'); |
+ |
+ // Faking 'strings.js' for this test. |
+ loadTimeData.data = { |
+ editCreditCardTitle: 'edit-title', |
+ addCreditCardTitle: 'add-title' |
+ }; |
}, |
/** |
@@ -49,6 +55,7 @@ SettingsAutofillSectionBrowserTest.prototype = { |
autofillSection.$.creditCardList.notifyResize(); |
Polymer.dom.flush(); |
}, |
+ |
/** |
* Creates the autofill section for the given lists. |
* @param {!Array<!chrome.passwordsPrivate.PasswordUiEntry>} passwordList |
@@ -57,7 +64,6 @@ SettingsAutofillSectionBrowserTest.prototype = { |
* @private |
*/ |
createAutofillSection_: function(addresses, creditCards) { |
- // Create a passwords-section to use for testing. |
var section = document.createElement('settings-autofill-section'); |
section.addresses = addresses; |
section.creditCards = creditCards; |
@@ -65,6 +71,19 @@ SettingsAutofillSectionBrowserTest.prototype = { |
this.flushAutofillSection_(section); |
return section; |
}, |
+ |
+ /** |
+ * Creates the Edit Credit Card dialog. |
+ * @param {!chrome.autofillPrivate.CreditCardEntry} creditCardItem |
+ * @return {!Object} |
+ */ |
+ createCreditCardDialog_: function(creditCardItem) { |
+ var section = document.createElement('settings-credit-card-edit-dialog'); |
+ document.body.appendChild(section); |
+ section.open(creditCardItem); // Opening the dialog will add the item. |
+ Polymer.dom.flush(); |
+ return section; |
+ }, |
}; |
/** |
@@ -107,6 +126,106 @@ TEST_F('SettingsAutofillSectionBrowserTest', 'uiTests', function() { |
row.querySelector('#creditCardExpiration').textContent); |
}); |
+ test('verifyAddVsEditCreditCardTitle', function() { |
+ var newCreditCard = FakeDataMaker.emptyCreditCardEntry(); |
+ var newCreditCardDialog = self.createCreditCardDialog_(newCreditCard); |
+ var oldCreditCard = FakeDataMaker.creditCardEntry(); |
+ var oldCreditCardDialog = self.createCreditCardDialog_(oldCreditCard); |
+ |
+ assertNotEquals(oldCreditCardDialog.title_, newCreditCardDialog.title_); |
+ assertNotEquals('', newCreditCardDialog.title_); |
+ assertNotEquals('', oldCreditCardDialog.title_); |
+ }), |
+ |
+ test('verifyExpiredCreditCardYear', function() { |
+ var creditCard = FakeDataMaker.creditCardEntry(); |
+ |
+ // 2015 is over unless time goes wobbly. |
+ var twentyFifteen = 2015; |
+ creditCard.expirationYear = twentyFifteen.toString(); |
+ |
+ var creditCardDialog = self.createCreditCardDialog_(creditCard); |
+ var selectableYears = creditCardDialog.$.yearList.items; |
+ var firstSelectableYear = selectableYears[0]; |
+ var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
+ |
+ var now = new Date(); |
+ var maxYear = now.getFullYear() + 9; |
+ |
+ assertEquals('2015', firstSelectableYear.textContent); |
+ assertEquals(maxYear.toString(), lastSelectableYear.textContent); |
+ }), |
+ |
+ test('verifyVeryFutureCreditCardYear', function() { |
+ var creditCard = FakeDataMaker.creditCardEntry(); |
+ |
+ // Expiring 20 years from now is unusual. |
+ var now = new Date(); |
+ var farFutureYear = now.getFullYear() + 20; |
+ creditCard.expirationYear = farFutureYear.toString(); |
+ |
+ var creditCardDialog = self.createCreditCardDialog_(creditCard); |
+ var selectableYears = creditCardDialog.$.yearList.items; |
+ var firstSelectableYear = selectableYears[0]; |
+ var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
+ |
+ assertEquals(now.getFullYear().toString(), |
+ firstSelectableYear.textContent); |
+ assertEquals(farFutureYear.toString(), lastSelectableYear.textContent); |
+ }), |
+ |
+ test('verifyVeryNormalCreditCardYear', function() { |
+ var creditCard = FakeDataMaker.creditCardEntry(); |
+ |
+ // Expiring 2 years from now is not unusual. |
+ var now = new Date(); |
+ var nearFutureYear = now.getFullYear() + 2; |
+ creditCard.expirationYear = nearFutureYear.toString(); |
+ var maxYear = now.getFullYear() + 9; |
+ |
+ var creditCardDialog = self.createCreditCardDialog_(creditCard); |
+ var selectableYears = creditCardDialog.$.yearList.items; |
+ var firstSelectableYear = selectableYears[0]; |
+ var lastSelectableYear = selectableYears[selectableYears.length - 1]; |
+ |
+ assertEquals(now.getFullYear().toString(), |
+ firstSelectableYear.textContent); |
+ assertEquals(maxYear.toString(), lastSelectableYear.textContent); |
+ }), |
+ |
+ // Test will timeout if event is not received. |
+ test('verifySaveCreditCardEdit', function(done) { |
+ var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
+ var creditCardDialog = self.createCreditCardDialog_(creditCard); |
+ |
+ creditCardDialog.addEventListener('save-credit-card', function(event) { |
+ assertEquals(creditCard.guid, event.detail.guid); |
+ done(); |
+ }); |
+ |
+ MockInteractions.tap(creditCardDialog.$.saveButton); |
+ }), |
+ |
+ test('verifyCancelCreditCardEdit', function(done) { |
+ var creditCard = FakeDataMaker.emptyCreditCardEntry(); |
+ var creditCardDialog = self.createCreditCardDialog_(creditCard); |
+ |
+ creditCardDialog.addEventListener('save-credit-card', function(event) { |
+ // Fail the test because the save event should not be called when cancel |
+ // is clicked. |
+ assertTrue(false); |
+ done(); |
+ }); |
+ |
+ creditCardDialog.addEventListener('iron-overlay-closed', function(event) { |
+ // Test is |done| in a timeout in order to ensure that |
+ // 'save-credit-card' is NOT fired after this test. |
+ window.setTimeout(done, 100); |
+ }); |
+ |
+ MockInteractions.tap(creditCardDialog.$.cancelButton); |
+ }), |
+ |
test('verifyAddressCount', function() { |
var addresses = [ |
FakeDataMaker.addressEntry(), |