Commit 17ab08ce authored by rbpotter's avatar rbpotter Committed by Commit Bot

Settings: use cr.define/classes for autofill/passwords test utils

Instead of defining a function object and then adding functions to it,
wrap everything in a cr.define, which can be removed later once
these tests are fully migrated to use JS modules.

Update all test classes to es6 classes.

Bug: 1026426
Change-Id: I004fb0798b5a855bda2de9c3f996fe346937e1cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088650Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747471}
parent 380630a9
......@@ -94,7 +94,7 @@ AccessibilityTest.define('SettingsA11yPasswords', {
'Accessible with 10 passwords': function() {
const fakePasswords = [];
for (let i = 0; i < 10; i++) {
fakePasswords.push(FakeDataMaker.passwordEntry());
fakePasswords.push(autofill_test_util.createPasswordEntry());
}
// Set list of passwords.
this.passwordManager.lastCallback.addSavedPasswordListChangedListener(
......
......@@ -76,10 +76,10 @@ cr.define('settings_autofill_page', function() {
/**
* Creates PasswordManagerExpectations with the values expected after first
* creating the element.
* @return {!PasswordManagerExpectations}
* @return {!autofill_test_util.PasswordManagerExpectations}
*/
function basePasswordExpectations() {
const expected = new PasswordManagerExpectations();
const expected = new autofill_test_util.PasswordManagerExpectations();
expected.requested.passwords = 1;
expected.requested.exceptions = 1;
expected.requested.accountStorageOptInState = 1;
......@@ -92,10 +92,10 @@ cr.define('settings_autofill_page', function() {
/**
* Creates AutofillManagerExpectations with the values expected after first
* creating the element.
* @return {!AutofillManagerExpectations}
* @return {!autofill_test_util.AutofillManagerExpectations}
*/
function baseAutofillExpectations() {
const expected = new AutofillManagerExpectations();
const expected = new autofill_test_util.AutofillManagerExpectations();
expected.requestedAddresses = 1;
expected.listeningAddresses = 1;
return expected;
......@@ -104,10 +104,10 @@ cr.define('settings_autofill_page', function() {
/**
* Creates PaymentsManagerExpectations with the values expected after first
* creating the element.
* @return {!PaymentsManagerExpectations}
* @return {!autofill_test_util.PaymentsManagerExpectations}
*/
function basePaymentsExpectations() {
const expected = new PaymentsManagerExpectations();
const expected = new autofill_test_util.PaymentsManagerExpectations();
expected.requestedCreditCards = 1;
expected.listeningCreditCards = 1;
return expected;
......@@ -127,11 +127,11 @@ cr.define('settings_autofill_page', function() {
PasswordManagerImpl.instance_ = passwordManager;
// Override the AutofillManagerImpl for testing.
autofillManager = new TestAutofillManager();
autofillManager = new autofill_test_util.TestAutofillManager();
settings.AutofillManagerImpl.instance_ = autofillManager;
// Override the PaymentsManagerImpl for testing.
paymentsManager = new TestPaymentsManager();
paymentsManager = new autofill_test_util.TestPaymentsManager();
settings.PaymentsManagerImpl.instance_ = paymentsManager;
});
......@@ -170,8 +170,10 @@ cr.define('settings_autofill_page', function() {
return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs);
const list =
[FakeDataMaker.passwordEntry(), FakeDataMaker.passwordEntry()];
const list = [
autofill_test_util.createPasswordEntry(),
autofill_test_util.createPasswordEntry()
];
passwordManager.lastCallback.addSavedPasswordListChangedListener(list);
Polymer.dom.flush();
......@@ -195,8 +197,10 @@ cr.define('settings_autofill_page', function() {
return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs);
const list =
[FakeDataMaker.exceptionEntry(), FakeDataMaker.exceptionEntry()];
const list = [
autofill_test_util.createExceptionEntry(),
autofill_test_util.createExceptionEntry()
];
passwordManager.lastCallback.addExceptionListChangedListener(list);
Polymer.dom.flush();
......@@ -216,10 +220,14 @@ cr.define('settings_autofill_page', function() {
return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs);
const addressList =
[FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
const cardList =
[FakeDataMaker.creditCardEntry(), FakeDataMaker.creditCardEntry()];
const addressList = [
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry()
];
const cardList = [
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry()
];
autofillManager.lastCallback.setPersonalDataManagerListener(
addressList, cardList);
Polymer.dom.flush();
......@@ -240,10 +248,14 @@ cr.define('settings_autofill_page', function() {
return createPrefs(true, true).then(function(prefs) {
const element = createAutofillElement(prefs);
const addressList =
[FakeDataMaker.addressEntry(), FakeDataMaker.addressEntry()];
const cardList =
[FakeDataMaker.creditCardEntry(), FakeDataMaker.creditCardEntry()];
const addressList = [
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry()
];
const cardList = [
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry()
];
paymentsManager.lastCallback.setPersonalDataManagerListener(
addressList, cardList);
Polymer.dom.flush();
......
......@@ -58,7 +58,7 @@ cr.define('settings_autofill_section', function() {
*/
function createAutofillSection(addresses, prefValues) {
// Override the AutofillManagerImpl for testing.
this.autofillManager = new TestAutofillManager();
this.autofillManager = new autofill_test_util.TestAutofillManager();
this.autofillManager.data.addresses = addresses;
settings.AutofillManagerImpl.instance_ = this.autofillManager;
......@@ -153,11 +153,11 @@ cr.define('settings_autofill_section', function() {
test('verifyAddressCount', function() {
const addresses = [
FakeDataMaker.addressEntry(),
FakeDataMaker.addressEntry(),
FakeDataMaker.addressEntry(),
FakeDataMaker.addressEntry(),
FakeDataMaker.addressEntry(),
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry(),
autofill_test_util.createAddressEntry(),
];
const section =
......@@ -182,7 +182,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyAddressFields', function() {
const address = FakeDataMaker.addressEntry();
const address = autofill_test_util.createAddressEntry();
const section = createAutofillSection([address], {});
const addressList = section.$.addressList;
const row = addressList.children[0];
......@@ -203,7 +203,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyAddressRowButtonIsDropdownWhenLocal', function() {
const address = FakeDataMaker.addressEntry();
const address = autofill_test_util.createAddressEntry();
address.metadata.isLocal = true;
const section = createAutofillSection([address], {});
const addressList = section.$.addressList;
......@@ -216,7 +216,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyAddressRowButtonIsOutlinkWhenRemote', function() {
const address = FakeDataMaker.addressEntry();
const address = autofill_test_util.createAddressEntry();
address.metadata.isLocal = false;
const section = createAutofillSection([address], {});
const addressList = section.$.addressList;
......@@ -229,7 +229,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyAddAddressDialog', function() {
return createAddressDialog(FakeDataMaker.emptyAddressEntry())
return createAddressDialog(autofill_test_util.createEmptyAddressEntry())
.then(function(dialog) {
const title = dialog.$$('[slot=title]');
assertEquals(
......@@ -240,7 +240,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyEditAddressDialog', function() {
return createAddressDialog(FakeDataMaker.addressEntry())
return createAddressDialog(autofill_test_util.createAddressEntry())
.then(function(dialog) {
const title = dialog.$$('[slot=title]');
assertEquals(
......@@ -252,7 +252,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyCountryIsSaved', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
return createAddressDialog(address).then(function(dialog) {
const countrySelect = dialog.$$('select');
assertEquals('', countrySelect.value);
......@@ -266,7 +266,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyPhoneAndEmailAreSaved', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
return createAddressDialog(address).then(function(dialog) {
assertEquals('', dialog.$.phoneInput.value);
assertFalse(!!(address.phoneNumbers && address.phoneNumbers[0]));
......@@ -293,7 +293,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyPhoneAndEmailAreRemoved', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
const phoneNumber = '(555) 555-5555';
const emailAddress = 'no-reply@chromium.org';
......@@ -322,7 +322,7 @@ cr.define('settings_autofill_section', function() {
// save button is enabled, then it will clear the field and verify that the
// save button is disabled. Test passes after all elements have been tested.
test('verifySaveIsNotClickableIfAllInputFieldsAreEmpty', function() {
return createAddressDialog(FakeDataMaker.emptyAddressEntry())
return createAddressDialog(autofill_test_util.createEmptyAddressEntry())
.then(function(dialog) {
const saveButton = dialog.$.saveButton;
const testElements =
......@@ -366,7 +366,7 @@ cr.define('settings_autofill_section', function() {
countrySelect.dispatchEvent(new CustomEvent('change'));
};
return createAddressDialog(FakeDataMaker.emptyAddressEntry())
return createAddressDialog(autofill_test_util.createEmptyAddressEntry())
.then(function(d) {
dialog = d;
assertTrue(dialog.$.saveButton.disabled);
......@@ -389,7 +389,7 @@ cr.define('settings_autofill_section', function() {
// Test will timeout if save-address event is not fired.
test('verifyDefaultCountryIsAppliedWhenSaving', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
address.fullNames = ['Name'];
return createAddressDialog(address).then(function(dialog) {
return expectEvent(dialog, 'save-address', function() {
......@@ -404,7 +404,7 @@ cr.define('settings_autofill_section', function() {
});
test('verifyCancelDoesNotSaveAddress', function(done) {
createAddressDialog(FakeDataMaker.addressEntry())
createAddressDialog(autofill_test_util.createAddressEntry())
.then(function(dialog) {
test_util.eventToPromise('save-address', dialog).then(function() {
// Fail the test because the save event should not be called when
......@@ -435,7 +435,7 @@ cr.define('settings_autofill_section', function() {
// US address has 3 fields on the same line.
test('verifyEditingUSAddress', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
const company_enabled = loadTimeData.getBoolean('EnableCompanyName');
address.fullNames = ['Name'];
address.companyName = 'Organization';
......@@ -499,7 +499,7 @@ cr.define('settings_autofill_section', function() {
// GB address has 1 field per line for all lines that change.
test('verifyEditingGBAddress', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
const company_enabled = loadTimeData.getBoolean('EnableCompanyName');
address.fullNames = ['Name'];
......@@ -568,7 +568,7 @@ cr.define('settings_autofill_section', function() {
// IL address has 2 fields on the same line and is an RTL locale.
// RTL locale shouldn't affect this test.
test('verifyEditingILAddress', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
const company_enabled = loadTimeData.getBoolean('EnableCompanyName');
address.fullNames = ['Name'];
......@@ -632,7 +632,7 @@ cr.define('settings_autofill_section', function() {
// US has an extra field 'State'. Validate that this field is
// persisted when switching to IL then back to US.
test('verifyAddressPersistanceWhenSwitchingCountries', function() {
const address = FakeDataMaker.emptyAddressEntry();
const address = autofill_test_util.createEmptyAddressEntry();
const company_enabled = loadTimeData.getBoolean('EnableCompanyName');
address.countryCode = 'US';
......
......@@ -77,10 +77,13 @@ cr.define('settings_passwords_check', function() {
// Test verifies that compromised credentials are displayed in a proper way
test('testSomeCompromisedCredentials', function() {
const leakedPasswords = [
FakeDataMaker.makeCompromisedCredentials('one.com', 'test4', 'LEAKED'),
FakeDataMaker.makeCompromisedCredentials('two.com', 'test3', 'PHISHED'),
autofill_test_util.makeCompromisedCredentials(
'one.com', 'test4', 'LEAKED'),
autofill_test_util.makeCompromisedCredentials(
'two.com', 'test3', 'PHISHED'),
];
const leakedPasswordsInfo = FakeDataMaker.makeCompromisedCredentialsInfo(
const leakedPasswordsInfo =
autofill_test_util.makeCompromisedCredentialsInfo(
leakedPasswords, '5 min ago');
passwordManager.data.leakedCredentials = leakedPasswordsInfo;
const checkPasswordSection = createCheckPasswordSection();
......
......@@ -28,7 +28,7 @@ cr.define('settings_passwords_section_cros', function() {
* tests to track auth token and saved password requests.
*/
class CrosPasswordSectionElementFactory extends
PasswordSectionElementFactory {
autofill_test_util.PasswordSectionElementFactory {
/**
* @param {HTMLDocument} document The test's |document| object.
* @param {request: Function} tokenRequestManager Fake for
......@@ -119,7 +119,7 @@ cr.define('settings_passwords_section_cros', function() {
let passwordItem;
passwordPromise = new Promise(resolve => {
passwordItem = {
entry: FakeDataMaker.passwordEntry(),
entry: autofill_test_util.createPasswordEntry(),
set password(newPassword) {
if (newPassword && newPassword != this.password_) {
resolve(newPassword);
......
......@@ -41,7 +41,7 @@ cr.define('settings_payments_section', function() {
*/
function createPaymentsSection(creditCards, upiIds, prefValues) {
// Override the PaymentsManagerImpl for testing.
const paymentsManager = new TestPaymentsManager();
const paymentsManager = new autofill_test_util.TestPaymentsManager();
paymentsManager.data.creditCards = creditCards;
paymentsManager.data.upiIds = upiIds;
settings.PaymentsManagerImpl.instance_ = paymentsManager;
......@@ -142,12 +142,12 @@ cr.define('settings_payments_section', function() {
test('verifyCreditCardCount', function() {
const creditCards = [
FakeDataMaker.creditCardEntry(),
FakeDataMaker.creditCardEntry(),
FakeDataMaker.creditCardEntry(),
FakeDataMaker.creditCardEntry(),
FakeDataMaker.creditCardEntry(),
FakeDataMaker.creditCardEntry(),
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry(),
autofill_test_util.createCreditCardEntry(),
];
const section = createPaymentsSection(
......@@ -164,7 +164,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyCreditCardFields', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
const section = createPaymentsSection(
[creditCard], /*upiIds=*/[], /*prefValues=*/ {});
const rowShadowRoot = getCardRowShadowRoot(section.$$('#paymentsList'));
......@@ -178,7 +178,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyCreditCardRowButtonIsDropdownWhenLocal', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isLocal = true;
const section = createPaymentsSection(
[creditCard], /*upiIds=*/[], /*prefValues=*/ {});
......@@ -191,7 +191,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyCreditCardRowButtonIsOutlinkWhenRemote', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isLocal = false;
const section = createPaymentsSection(
[creditCard], /*upiIds=*/[], /*prefValues=*/ {});
......@@ -204,9 +204,9 @@ cr.define('settings_payments_section', function() {
});
test('verifyAddVsEditCreditCardTitle', function() {
const newCreditCard = FakeDataMaker.emptyCreditCardEntry();
const newCreditCard = autofill_test_util.createEmptyCreditCardEntry();
const newCreditCardDialog = createCreditCardDialog(newCreditCard);
const oldCreditCard = FakeDataMaker.creditCardEntry();
const oldCreditCard = autofill_test_util.createCreditCardEntry();
const oldCreditCardDialog = createCreditCardDialog(oldCreditCard);
assertNotEquals(oldCreditCardDialog.title_, newCreditCardDialog.title_);
......@@ -221,7 +221,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyExpiredCreditCardYear', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
// 2015 is over unless time goes wobbly.
const twentyFifteen = 2015;
......@@ -245,7 +245,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyVeryFutureCreditCardYear', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
// Expiring 25 years from now is unusual.
const now = new Date();
......@@ -270,7 +270,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyVeryNormalCreditCardYear', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
// Expiring 2 years from now is not unusual.
const now = new Date();
......@@ -296,7 +296,7 @@ cr.define('settings_payments_section', function() {
});
test('verify save disabled for expired credit card', function() {
const creditCard = FakeDataMaker.emptyCreditCardEntry();
const creditCard = autofill_test_util.createEmptyCreditCardEntry();
const now = new Date();
creditCard.expirationYear = now.getFullYear() - 2;
......@@ -312,7 +312,7 @@ cr.define('settings_payments_section', function() {
});
test('verify save new credit card', function() {
const creditCard = FakeDataMaker.emptyCreditCardEntry();
const creditCard = autofill_test_util.createEmptyCreditCardEntry();
const creditCardDialog = createCreditCardDialog(creditCard);
return test_util.whenAttributeIs(creditCardDialog.$.dialog, 'open', '')
......@@ -341,7 +341,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyCancelCreditCardEdit', function(done) {
const creditCard = FakeDataMaker.emptyCreditCardEntry();
const creditCard = autofill_test_util.createEmptyCreditCardEntry();
const creditCardDialog = createCreditCardDialog(creditCard);
test_util.whenAttributeIs(creditCardDialog.$.dialog, 'open', '')
......@@ -366,7 +366,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyLocalCreditCardMenu', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
// When credit card is local, |isCached| will be undefined.
creditCard.metadata.isLocal = true;
......@@ -397,7 +397,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyCachedCreditCardMenu', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isLocal = false;
creditCard.metadata.isCached = true;
......@@ -427,7 +427,7 @@ cr.define('settings_payments_section', function() {
});
test('verifyNotCachedCreditCardMenu', function() {
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isLocal = false;
creditCard.metadata.isCached = false;
......@@ -447,7 +447,7 @@ cr.define('settings_payments_section', function() {
loadTimeData.overrideValues({migrationEnabled: false});
// Add one migratable credit card.
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isMigratable = true;
const section = createPaymentsSection(
[creditCard], /*upiIds=*/[], {credit_card_enabled: {value: true}});
......@@ -457,7 +457,7 @@ cr.define('settings_payments_section', function() {
test('verifyMigrationButtonNotShownIfCreditCardDisabled', function() {
// Add one migratable credit card.
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isMigratable = true;
// Mock credit card save toggle is turned off by users.
const section = createPaymentsSection(
......@@ -468,7 +468,7 @@ cr.define('settings_payments_section', function() {
test('verifyMigrationButtonNotShownIfNoCardIsMigratable', function() {
// Add one migratable credit card.
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
// Mock credit card is not valid.
creditCard.metadata.isMigratable = false;
const section = createPaymentsSection(
......@@ -479,7 +479,7 @@ cr.define('settings_payments_section', function() {
test('verifyMigrationButtonShown', function() {
// Add one migratable credit card.
const creditCard = FakeDataMaker.creditCardEntry();
const creditCard = autofill_test_util.createCreditCardEntry();
creditCard.metadata.isMigratable = true;
const section = createPaymentsSection(
[creditCard], /*upiIds=*/[], {credit_card_enabled: {value: true}});
......
......@@ -17,13 +17,14 @@ class TestPasswordManagerProxy extends TestBrowserProxy {
'getCompromisedCredentialsInfo',
]);
this.actual_ = new PasswordManagerExpectations();
this.actual_ = new autofill_test_util.PasswordManagerExpectations();
// Set these to have non-empty data.
this.data = {
passwords: [],
exceptions: [],
leakedCredentials: FakeDataMaker.makeCompromisedCredentialsInfo([], ''),
leakedCredentials:
autofill_test_util.makeCompromisedCredentialsInfo([], ''),
};
// Holds the last callbacks so they can be called when needed/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment