diff --git a/browser/components/aboutlogins/tests/browser/browser_loginItemErrors.js b/browser/components/aboutlogins/tests/browser/browser_loginItemErrors.js --- a/browser/components/aboutlogins/tests/browser/browser_loginItemErrors.js +++ b/browser/components/aboutlogins/tests/browser/browser_loginItemErrors.js @@ -19,11 +19,11 @@ "https://example.com", null, "user2", "pass2" ); - LOGIN_TO_UPDATE = Services.logins.addLogin(LOGIN_TO_UPDATE); + LOGIN_TO_UPDATE = await Services.logins.addLoginAsync(LOGIN_TO_UPDATE); EXPECTED_ERROR_MESSAGE = "This login already exists."; const LOGIN_UPDATES = { origin: "https://example.com", password: "my1GoodPassword", username: "user1", diff --git a/browser/components/aboutlogins/tests/browser/browser_openFiltered.js b/browser/components/aboutlogins/tests/browser/browser_openFiltered.js --- a/browser/components/aboutlogins/tests/browser/browser_openFiltered.js +++ b/browser/components/aboutlogins/tests/browser/browser_openFiltered.js @@ -4,17 +4,17 @@ add_setup(async function() { let storageChangedPromised = TestUtils.topicObserved( "passwordmgr-storage-changed", (_, data) => data == "addLogin" ); - TEST_LOGIN1 = Services.logins.addLogin(TEST_LOGIN1); + TEST_LOGIN1 = await Services.logins.addLoginAsync(TEST_LOGIN1); await storageChangedPromised; storageChangedPromised = TestUtils.topicObserved( "passwordmgr-storage-changed", (_, data) => data == "addLogin" ); - TEST_LOGIN2 = Services.logins.addLogin(TEST_LOGIN2); + TEST_LOGIN2 = await Services.logins.addLoginAsync(TEST_LOGIN2); await storageChangedPromised; let tabOpenedPromise = BrowserTestUtils.waitForNewTab( gBrowser, "about:logins?filter=" + encodeURIComponent(TEST_LOGIN1.origin), true diff --git a/browser/components/aboutlogins/tests/browser/head.js b/browser/components/aboutlogins/tests/browser/head.js --- a/browser/components/aboutlogins/tests/browser/head.js +++ b/browser/components/aboutlogins/tests/browser/head.js @@ -52,21 +52,16 @@ "password" ); TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456; async function addLogin(login) { - let storageChangedPromised = TestUtils.topicObserved( - "passwordmgr-storage-changed", - (_, data) => data == "addLogin" - ); - login = Services.logins.addLogin(login); - await storageChangedPromised; + const result = await Services.logins.addLoginAsync(login); registerCleanupFunction(() => { let matchData = Cc["@mozilla.org/hash-property-bag;1"].createInstance( Ci.nsIWritablePropertyBag2 ); - matchData.setPropertyAsAUTF8String("guid", login.guid); + matchData.setPropertyAsAUTF8String("guid", result.guid); let logins = Services.logins.searchLogins(matchData); if (!logins.length) { return; } @@ -74,11 +69,11 @@ // in case the initial login object was changed by the test code, // since removeLogin makes sure that the login argument exactly // matches the login that it will be removing. Services.logins.removeLogin(logins[0]); }); - return login; + return result; } let EXPECTED_BREACH = null; let EXPECTED_ERROR_MESSAGE = null; add_setup(async function setup_head() { diff --git a/browser/components/aboutlogins/tests/unit/test_getPotentialBreachesByLoginGUID.js b/browser/components/aboutlogins/tests/unit/test_getPotentialBreachesByLoginGUID.js --- a/browser/components/aboutlogins/tests/unit/test_getPotentialBreachesByLoginGUID.js +++ b/browser/components/aboutlogins/tests/unit/test_getPotentialBreachesByLoginGUID.js @@ -108,11 +108,11 @@ password: "password", timePasswordChanged: new Date("2018-12-15").getTime(), }); add_task(async function test_notBreachedLogin() { - Services.logins.addLogin(NOT_BREACHED_LOGIN); + await Services.logins.addLoginAsync(NOT_BREACHED_LOGIN); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [NOT_BREACHED_LOGIN], TEST_BREACHES ); Assert.strictEqual( @@ -121,11 +121,11 @@ "Should be 0 breached logins." ); }); add_task(async function test_breachedLogin() { - Services.logins.addLogin(BREACHED_LOGIN); + await Services.logins.addLoginAsync(BREACHED_LOGIN); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [NOT_BREACHED_LOGIN, BREACHED_LOGIN], TEST_BREACHES ); Assert.strictEqual( @@ -139,11 +139,11 @@ "Breach alert link should be equal to the breachAlertURL" ); }); add_task(async function test_breachedLoginAfterCrashingUriLogin() { - Services.logins.addLogin(CRASHING_URI_LOGIN); + await Services.logins.addLoginAsync(CRASHING_URI_LOGIN); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [CRASHING_URI_LOGIN, BREACHED_LOGIN], TEST_BREACHES ); @@ -158,11 +158,11 @@ "Breach alert link should be equal to the breachAlertURL" ); }); add_task(async function test_notBreachedSubdomain() { - Services.logins.addLogin(NOT_BREACHED_SUBDOMAIN_LOGIN); + await Services.logins.addLoginAsync(NOT_BREACHED_SUBDOMAIN_LOGIN); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [NOT_BREACHED_LOGIN, NOT_BREACHED_SUBDOMAIN_LOGIN], TEST_BREACHES ); @@ -172,11 +172,11 @@ "Should be 0 breached logins." ); }); add_task(async function test_breachedSubdomain() { - Services.logins.addLogin(BREACHED_SUBDOMAIN_LOGIN); + await Services.logins.addLoginAsync(BREACHED_SUBDOMAIN_LOGIN); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [NOT_BREACHED_SUBDOMAIN_LOGIN, BREACHED_SUBDOMAIN_LOGIN], TEST_BREACHES ); @@ -186,11 +186,13 @@ "Should be 1 breached login: " + BREACHED_SUBDOMAIN_LOGIN.origin ); }); add_task(async function test_breachedSiteWithoutPasswords() { - Services.logins.addLogin(LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS); + await Services.logins.addLoginAsync( + LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS + ); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS], TEST_BREACHES ); @@ -250,11 +252,11 @@ BREACHED_LOGIN.origin ); }); add_task(async function test_ExceptionsThrownByNonStandardURIsAreCaught() { - Services.logins.addLogin(LOGIN_WITH_NON_STANDARD_URI); + await Services.logins.addLoginAsync(LOGIN_WITH_NON_STANDARD_URI); const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID( [LOGIN_WITH_NON_STANDARD_URI, BREACHED_LOGIN], TEST_BREACHES ); diff --git a/browser/components/extensions/test/xpcshell/test_ext_browsingData_passwords.js b/browser/components/extensions/test/xpcshell/test_ext_browsingData_passwords.js --- a/browser/components/extensions/test/xpcshell/test_ext_browsingData_passwords.js +++ b/browser/components/extensions/test/xpcshell/test_ext_browsingData_passwords.js @@ -8,35 +8,35 @@ const OLD_HOST = "http://mozilla.org"; const NEW_HOST = "http://mozilla.com"; const FXA_HOST = "chrome://FirefoxAccounts"; function checkLoginExists(host, shouldExist) { - let logins = Services.logins.findLogins(host, "", null); + const logins = Services.logins.findLogins(host, "", null); equal( logins.length, shouldExist ? 1 : 0, `Login was ${shouldExist ? "" : "not "} found.` ); } -function addLogin(host, timestamp) { +async function addLogin(host, timestamp) { checkLoginExists(host, false); let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance( Ci.nsILoginInfo ); login.init(host, "", null, LOGIN_USERNAME, LOGIN_PASSWORD); login.QueryInterface(Ci.nsILoginMetaInfo); login.timePasswordChanged = timestamp; - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); checkLoginExists(host, true); } async function setupPasswords() { Services.logins.removeAllUserFacingLogins(); - addLogin(FXA_HOST, REFERENCE_DATE); - addLogin(NEW_HOST, REFERENCE_DATE); - addLogin(OLD_HOST, REFERENCE_DATE - 10000); + await addLogin(FXA_HOST, REFERENCE_DATE); + await addLogin(NEW_HOST, REFERENCE_DATE); + await addLogin(OLD_HOST, REFERENCE_DATE - 10000); } add_task(async function testPasswords() { function background() { browser.test.onMessage.addListener(async (msg, options) => { @@ -47,11 +47,11 @@ } browser.test.sendMessage("passwordsRemoved"); }); } - let extension = ExtensionTestUtils.loadExtension({ + const extension = ExtensionTestUtils.loadExtension({ background, manifest: { permissions: ["browsingData"], }, }); diff --git a/browser/components/migration/tests/marionette/test_refresh_firefox.py b/browser/components/migration/tests/marionette/test_refresh_firefox.py --- a/browser/components/migration/tests/marionette/test_refresh_firefox.py +++ b/browser/components/migration/tests/marionette/test_refresh_firefox.py @@ -38,22 +38,24 @@ _formAutofillAddressGuid = None _expectedURLs = ["about:robots", "about:mozilla"] def savePassword(self): - self.runCode( + self.runAsyncCode( """ + let [username, password, resolve] = arguments; let myLogin = new global.LoginInfo( "test.marionette.mozilla.com", "http://test.marionette.mozilla.com/some/form/", null, - arguments[0], - arguments[1], + username, + password, "username", "password" ); - Services.logins.addLogin(myLogin) + Services.logins.addLoginAsync(myLogin) + .then(() => resolve(false), resolve); """, script_args=(self._username, self._password), ) def createBookmarkInMenu(self): diff --git a/browser/components/migration/tests/unit/test_Chrome_passwords.js b/browser/components/migration/tests/unit/test_Chrome_passwords.js --- a/browser/components/migration/tests/unit/test_Chrome_passwords.js +++ b/browser/components/migration/tests/unit/test_Chrome_passwords.js @@ -102,16 +102,16 @@ var loginCrypto; var dbConn; async function promiseSetPassword(login) { - let encryptedString = await loginCrypto.encryptData( + const encryptedString = await loginCrypto.encryptData( login.password, login.version ); info(`promiseSetPassword: ${encryptedString}`); - let passwordValue = new Uint8Array( + const passwordValue = new Uint8Array( loginCrypto.stringToArray(encryptedString) ); return dbConn.execute( `UPDATE logins SET password_value = :password_value @@ -175,11 +175,11 @@ "The two logins ID " + id + " have the same timesUsed" ); } function generateDifferentLogin(login) { - let newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance( + const newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance( Ci.nsILoginInfo ); newLogin.init( login.origin, @@ -204,17 +204,17 @@ // Use a mock service and account name to avoid a Keychain auth. prompt that // would block the test from finishing if Chrome has already created a matching // Keychain entry. This allows us to still exercise the keychain lookup code. // The mock encryption passphrase is used when the Keychain item isn't found. - let mockMacOSKeychain = { + const mockMacOSKeychain = { passphrase: "bW96aWxsYWZpcmVmb3g=", serviceName: "TESTING Chrome Safe Storage", accountName: "TESTING Chrome", }; if (AppConstants.platform == "macosx") { - let { ChromeMacOSLoginCrypto } = ChromeUtils.importESModule( + const { ChromeMacOSLoginCrypto } = ChromeUtils.importESModule( "resource:///modules/ChromeMacOSLoginCrypto.sys.mjs" ); loginCrypto = new ChromeMacOSLoginCrypto( mockMacOSKeychain.serviceName, mockMacOSKeychain.accountName, @@ -228,11 +228,11 @@ "Chrome", "Default", "Login Data", ]; } else if (AppConstants.platform == "win") { - let { ChromeWindowsLoginCrypto } = ChromeUtils.importESModule( + const { ChromeWindowsLoginCrypto } = ChromeUtils.importESModule( "resource:///modules/ChromeWindowsLoginCrypto.sys.mjs" ); loginCrypto = new ChromeWindowsLoginCrypto("Chrome"); dirSvcPath = "AppData/Local/"; pathId = "LocalAppData"; @@ -244,22 +244,22 @@ "Login Data", ]; } else { throw new Error("Not implemented"); } - let dirSvcFile = do_get_file(dirSvcPath); + const dirSvcFile = do_get_file(dirSvcPath); registerFakePath(pathId, dirSvcFile); info(PathUtils.join(dirSvcFile.path, ...profilePathSegments)); - let loginDataFilePath = PathUtils.join( + const loginDataFilePath = PathUtils.join( dirSvcFile.path, ...profilePathSegments ); dbConn = await Sqlite.openConnection({ path: loginDataFilePath }); if (AppConstants.platform == "macosx") { - let migrator = await MigrationUtils.getMigrator("chrome"); + const migrator = await MigrationUtils.getMigrator("chrome"); Object.assign(migrator, { _keychainServiceName: mockMacOSKeychain.serviceName, _keychainAccountName: mockMacOSKeychain.accountName, _keychainMockPassphrase: mockMacOSKeychain.passphrase, }); @@ -273,15 +273,15 @@ return dbConn.close(); }); }); add_task(async function test_importIntoEmptyDB() { - for (let login of TEST_LOGINS) { + for (const login of TEST_LOGINS) { await promiseSetPassword(login); } - let migrator = await MigrationUtils.getMigrator("chrome"); + const migrator = await MigrationUtils.getMigrator("chrome"); Assert.ok( await migrator.isSourceAvailable(), "Sanity check the source exists" ); @@ -313,11 +313,11 @@ } }); // Test that existing logins for the same primary key don't get overwritten add_task(async function test_importExistingLogins() { - let migrator = await MigrationUtils.getMigrator("chrome"); + const migrator = await MigrationUtils.getMigrator("chrome"); Assert.ok( await migrator.isSourceAvailable(), "Sanity check the source exists" ); @@ -327,11 +327,11 @@ logins.length, 0, "There are no logins after removing all of them" ); - let newLogins = []; + const newLogins = []; // Create 3 new logins that are different but where the key properties are still the same. for (let i = 0; i < 3; i++) { newLogins.push(generateDifferentLogin(TEST_LOGINS[i])); Services.logins.addLogin(newLogins[i]); diff --git a/browser/components/protections/test/browser/browser_protections_lockwise.js b/browser/components/protections/test/browser/browser_protections_lockwise.js --- a/browser/components/protections/test/browser/browser_protections_lockwise.js +++ b/browser/components/protections/test/browser/browser_protections_lockwise.js @@ -10,15 +10,15 @@ "resource:///actors/AboutProtectionsParent.sys.mjs" ); const ABOUT_LOGINS_URL = "about:logins"; add_task(async function testNoLoginsLockwiseCardUI() { - let tab = await BrowserTestUtils.openNewForegroundTab({ + const tab = await BrowserTestUtils.openNewForegroundTab({ url: "about:protections", gBrowser, }); - let aboutLoginsPromise = BrowserTestUtils.waitForNewTab( + const aboutLoginsPromise = BrowserTestUtils.waitForNewTab( gBrowser, ABOUT_LOGINS_URL ); info( @@ -74,30 +74,30 @@ info( "Click on the save passwords button and check that it opens about:logins in a new tab" ); savePasswordsButton.click(); }); - let loginsTab = await aboutLoginsPromise; + const loginsTab = await aboutLoginsPromise; info("about:logins was successfully opened in a new tab"); gBrowser.removeTab(loginsTab); gBrowser.removeTab(tab); }); add_task(async function testLockwiseCardUIWithLogins() { - let tab = await BrowserTestUtils.openNewForegroundTab({ + const tab = await BrowserTestUtils.openNewForegroundTab({ url: "about:protections", gBrowser, }); - let aboutLoginsPromise = BrowserTestUtils.waitForNewTab( + const aboutLoginsPromise = BrowserTestUtils.waitForNewTab( gBrowser, ABOUT_LOGINS_URL ); info( "Add a login and check that lockwise card content for a logged in user is displayed correctly" ); - Services.logins.addLogin(TEST_LOGIN1); + await Services.logins.addLoginAsync(TEST_LOGIN1); await BrowserTestUtils.reloadTab(tab); await SpecialPowers.spawn(tab.linkedBrowser, [], async function() { await ContentTaskUtils.waitForCondition(() => { const hasLogins = content.document.querySelector(".lockwise-card"); @@ -170,18 +170,18 @@ info( "Click on the manage passwords button and check that it opens about:logins in a new tab" ); managePasswordsButton.click(); }); - let loginsTab = await aboutLoginsPromise; + const loginsTab = await aboutLoginsPromise; info("about:logins was successfully opened in a new tab"); gBrowser.removeTab(loginsTab); info( "Add another login and check that the scanned text about stored logins is updated after reload." ); - Services.logins.addLogin(TEST_LOGIN2); + await Services.logins.addLoginAsync(TEST_LOGIN2); await BrowserTestUtils.reloadTab(tab); await SpecialPowers.spawn(tab.linkedBrowser, [], async function() { const lockwiseScannedText = content.document.querySelector( "#lockwise-scanned-text" @@ -202,15 +202,15 @@ add_task(async function testLockwiseCardUIWithBreachedLogins() { info( "Add a breached login and test that the lockwise scanned text is displayed correctly" ); - let tab = await BrowserTestUtils.openNewForegroundTab({ + const tab = await BrowserTestUtils.openNewForegroundTab({ url: "about:protections", gBrowser, }); - Services.logins.addLogin(TEST_LOGIN1); + await Services.logins.addLoginAsync(TEST_LOGIN1); info("Mock monitor data with a breached login to test the Lockwise UI"); AboutProtectionsParent.setTestOverride( mockGetLoginDataWithSyncedDevices(false, 1) ); @@ -259,11 +259,11 @@ Services.logins.removeLogin(TEST_LOGIN1); gBrowser.removeTab(tab); }); add_task(async function testLockwiseCardPref() { - let tab = await BrowserTestUtils.openNewForegroundTab({ + const tab = await BrowserTestUtils.openNewForegroundTab({ url: "about:protections", gBrowser, }); info("Disable showing the Lockwise card."); diff --git a/browser/components/protections/test/browser/browser_protections_monitor.js b/browser/components/protections/test/browser/browser_protections_monitor.js --- a/browser/components/protections/test/browser/browser_protections_monitor.js +++ b/browser/components/protections/test/browser/browser_protections_monitor.js @@ -16,18 +16,18 @@ numBreaches: 11, numBreachesResolved: 0, }; add_task(async function() { - let tab = await BrowserTestUtils.openNewForegroundTab({ + const tab = await BrowserTestUtils.openNewForegroundTab({ url: "about:protections", gBrowser, }); await BrowserTestUtils.reloadTab(tab); - let monitorCardEnabled = Services.prefs.getBoolPref( + const monitorCardEnabled = Services.prefs.getBoolPref( "browser.contentblocking.report.monitor.enabled" ); // Only run monitor card tests if it's enabled. if (monitorCardEnabled) { @@ -37,11 +37,11 @@ await checkNoLoginsContentIsDisplayed(tab, "monitor-sign-up"); info( "Check that the correct content is displayed for users with monitor data." ); - Services.logins.addLogin(TEST_LOGIN1); + await Services.logins.addLoginAsync(TEST_LOGIN1); AboutProtectionsParent.setTestOverride(mockGetMonitorData(mockMonitorData)); await BrowserTestUtils.reloadTab(tab); Assert.ok( true, diff --git a/browser/components/protections/test/browser/browser_protections_telemetry.js b/browser/components/protections/test/browser/browser_protections_telemetry.js --- a/browser/components/protections/test/browser/browser_protections_telemetry.js +++ b/browser/components/protections/test/browser/browser_protections_telemetry.js @@ -205,11 +205,11 @@ url: "about:protections", gBrowser, }); // Add user logins. - Services.logins.addLogin(TEST_LOGIN1); + await Services.logins.addLoginAsync(TEST_LOGIN1); await BrowserTestUtils.reloadTab(tab); await SpecialPowers.spawn(tab.linkedBrowser, [], async function() { const managePasswordsButton = await ContentTaskUtils.waitForCondition( () => { return content.document.getElementById("manage-passwords-button"); diff --git a/dom/ipc/tests/browser_wpi_base.js b/dom/ipc/tests/browser_wpi_base.js --- a/dom/ipc/tests/browser_wpi_base.js +++ b/dom/ipc/tests/browser_wpi_base.js @@ -188,11 +188,11 @@ let LoginInfo = new Components.Constructor( "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init" ); - Services.logins.addLogin( + await Services.logins.addLoginAsync( new LoginInfo(COM_ORIGIN, "", null, "username", "password", "", "") ); // Init login detection service to trigger fetching logins let loginDetection = Cc[ diff --git a/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js b/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js --- a/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js +++ b/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js @@ -303,11 +303,11 @@ "foo@bar.com", // aUsername JSON.stringify(contents), // aPassword "", // aUsernameField "" ); // aPasswordField - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); // ensure we read it. let storage = new LoginManagerStorage(); let got = await storage.get("uid", "foo@bar.com"); Assert.deepEqual(got, contents); diff --git a/services/sync/tests/unit/test_engine_changes_during_sync.js b/services/sync/tests/unit/test_engine_changes_during_sync.js --- a/services/sync/tests/unit/test_engine_changes_during_sync.js +++ b/services/sync/tests/unit/test_engine_changes_during_sync.js @@ -141,11 +141,11 @@ "username", "password", "", "" ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); await engine._tracker.asyncObserver.promiseObserversComplete(); } }; engine._tracker.start(); diff --git a/services/sync/tests/unit/test_password_engine.js b/services/sync/tests/unit/test_password_engine.js --- a/services/sync/tests/unit/test_password_engine.js +++ b/services/sync/tests/unit/test_password_engine.js @@ -43,11 +43,11 @@ let server = await serverForFoo(engine); await SyncTestingInfrastructure(server); enableValidationPrefs(); - let login = Services.logins.addLogin( + let login = await Services.logins.addLoginAsync( new LoginInfo( "https://example.com", "", null, "username", @@ -95,11 +95,11 @@ enableValidationPrefs(); engine._tracker.start(); try { - let login = Services.logins.addLogin( + let login = await Services.logins.addLoginAsync( new LoginInfo( FXA_PWDMGR_HOST, null, FXA_PWDMGR_REALM, "fxa-uid", @@ -144,11 +144,11 @@ "username", "password", "", "" ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let logins = Services.logins.findLogins("https://example.com", "", ""); equal(logins.length, 1, "Should find new login in login manager"); newLogin = logins[0].QueryInterface(Ci.nsILoginMetaInfo); @@ -179,11 +179,11 @@ "us3r", "0ldpa55", "", "" ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let props = new PropertyBag(); let localPasswordChangeTime = Date.now() - 1 * 60 * 60 * 24 * 1000; props.setProperty("timePasswordChanged", localPasswordChangeTime); Services.logins.modifyLogin(login, props); diff --git a/services/sync/tests/unit/test_password_tracker.js b/services/sync/tests/unit/test_password_tracker.js --- a/services/sync/tests/unit/test_password_tracker.js +++ b/services/sync/tests/unit/test_password_tracker.js @@ -37,11 +37,11 @@ usernameField: "username", passwordField: "password", }; recordNum++; let login = store._nsLoginInfoFromRecord(record); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); await tracker.asyncObserver.promiseObserversComplete(); } try { _( @@ -124,11 +124,11 @@ usernameField: "username", passwordField: "password", }; recordNum++; let login = store._nsLoginInfoFromRecord(record); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); await tracker.asyncObserver.promiseObserversComplete(); } try { _("Tell tracker to start tracking changes"); tracker.start(); diff --git a/toolkit/components/cleardata/tests/unit/test_passwords.js b/toolkit/components/cleardata/tests/unit/test_passwords.js --- a/toolkit/components/cleardata/tests/unit/test_passwords.js +++ b/toolkit/components/cleardata/tests/unit/test_passwords.js @@ -18,11 +18,11 @@ username: "admin", password: "12345678", usernameField: "field_username", passwordField: "field_password", }); - Services.logins.addLogin(loginInfo); + await Services.logins.addLoginAsync(loginInfo); Assert.equal(countLogins(URL), 1); let uri = Services.io.newURI(URL); let principal = Services.scriptSecurityManager.createContentPrincipal( @@ -55,11 +55,11 @@ username: "admin", password: "12345678", usernameField: "field_username", passwordField: "field_password", }); - Services.logins.addLogin(loginInfo); + await Services.logins.addLoginAsync(loginInfo); Assert.equal(countLogins(URL), 1); await new Promise(resolve => { Services.clearData.deleteData( diff --git a/toolkit/components/forgetaboutsite/test/unit/test_removeDataFromDomain.js b/toolkit/components/forgetaboutsite/test/unit/test_removeDataFromDomain.js --- a/toolkit/components/forgetaboutsite/test/unit/test_removeDataFromDomain.js +++ b/toolkit/components/forgetaboutsite/test/unit/test_removeDataFromDomain.js @@ -105,11 +105,11 @@ * Adds a login for the specified host to the login manager. * * @param aHost * The host to add the login for. */ -function add_login(aHost) { +async function add_login(aHost) { check_login_exists(aHost, false); let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance( Ci.nsILoginInfo ); login.init( @@ -119,11 +119,11 @@ LOGIN_USERNAME, LOGIN_PASSWORD, LOGIN_USERNAME_FIELD, LOGIN_PASSWORD_FIELD ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); check_login_exists(aHost, true); } /** * Checks to see if a login exists for a host. @@ -310,25 +310,25 @@ check_disabled_host(TEST_HOST, false); } async function test_login_manager_logins_cleared_with_direct_match() { const TEST_HOST = "http://mozilla.org"; - add_login(TEST_HOST); + await add_login(TEST_HOST); await ForgetAboutSite.removeDataFromDomain("mozilla.org"); check_login_exists(TEST_HOST, true); } async function test_login_manager_logins_cleared_with_subdomain() { const TEST_HOST = "http://www.mozilla.org"; - add_login(TEST_HOST); + await add_login(TEST_HOST); await ForgetAboutSite.removeDataFromDomain("mozilla.org"); check_login_exists(TEST_HOST, true); } async function test_login_manager_logins_not_cleared_with_uri_contains_domain() { const TEST_HOST = "http://ilovemozilla.org"; - add_login(TEST_HOST); + await add_login(TEST_HOST); await ForgetAboutSite.removeDataFromDomain("mozilla.org"); check_login_exists(TEST_HOST, true); Services.logins.removeAllUserFacingLogins(); check_login_exists(TEST_HOST, false); diff --git a/toolkit/components/passwordmgr/test/LoginTestUtils.sys.mjs b/toolkit/components/passwordmgr/test/LoginTestUtils.sys.mjs --- a/toolkit/components/passwordmgr/test/LoginTestUtils.sys.mjs +++ b/toolkit/components/passwordmgr/test/LoginTestUtils.sys.mjs @@ -62,17 +62,11 @@ origin, formActionOrigin: formActionOrigin || origin, username, password, }); - let storageChangedPromised = TestUtils.topicObserved( - "passwordmgr-storage-changed", - (_, data) => data == "addLogin" - ); - Services.logins.addLogin(login); - let [savedLogin] = await storageChangedPromised; - return savedLogin; + return Services.logins.addLoginAsync(login); }, async modifyLogin(oldLogin, newLogin) { const storageChangedPromise = TestUtils.topicObserved( "passwordmgr-storage-changed", diff --git a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_autofocus_with_frame.js b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_autofocus_with_frame.js --- a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_autofocus_with_frame.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_autofocus_with_frame.js @@ -5,18 +5,18 @@ origin: "https://example.org", formActionOrigin: "https://example.org", username: "username1", password: "password1", }); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); login = LoginTestUtils.testData.formLogin({ origin: "https://example.org", formActionOrigin: "https://example.org", username: "username2", password: "password2", }); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); }); // Verify that the autocomplete popup opens when the username field in autofocused. add_task(async function test_autofocus_autocomplete() { let popup = document.getElementById("PopupAutoComplete"); diff --git a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_disabled_readonly_passwordField.js b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_disabled_readonly_passwordField.js --- a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_disabled_readonly_passwordField.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_disabled_readonly_passwordField.js @@ -20,12 +20,11 @@ formActionOrigin: "https://example.org", username: "username2", password: "password2", }); - Services.logins.addLogin(login1); - Services.logins.addLogin(login2); + await Services.logins.addLogins([login1, login2]); }); add_task( async function test_autocomplete_for_usernameField_with_disabled_passwordField() { await BrowserTestUtils.withNewTab( diff --git a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js --- a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_footer.js @@ -27,13 +27,11 @@ Services.prefs.setBoolPref("signon.showAutoCompleteFooter", true); registerCleanupFunction(() => { Services.prefs.clearUserPref("signon.showAutoCompleteFooter"); }); - for (let login of loginList()) { - Services.logins.addLogin(login); - } + await Services.logins.addLogins(loginList()); }); add_task(async function test_autocomplete_footer_onclick() { let url = TEST_ORIGIN + BASIC_FORM_PAGE_PATH; await BrowserTestUtils.withNewTab( diff --git a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_primary_password.js b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_primary_password.js --- a/toolkit/components/passwordmgr/test/browser/browser_autocomplete_primary_password.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autocomplete_primary_password.js @@ -28,11 +28,11 @@ origin: "https://example.com", formActionOrigin: "https://example.com", username: "username", password: "password", }); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); LoginTestUtils.primaryPassword.enable(); registerCleanupFunction(function() { LoginTestUtils.primaryPassword.disable(); }); @@ -80,14 +80,14 @@ // Wait for initial primary password dialog after adding the login. let dialogShown = waitForDialog(); let win = await BrowserTestUtils.openNewBrowserWindow(); - Services.tm.dispatchToMainThread(() => { + Services.tm.dispatchToMainThread(async () => { try { // Trigger a MP prompt in the new window by saving a login - Services.logins.addLogin(LoginTestUtils.testData.formLogin()); + await Services.logins.addLoginAsync(LoginTestUtils.testData.formLogin()); } catch (e) { // Handle throwing from MP cancellation } }); let { close } = await dialogShown; diff --git a/toolkit/components/passwordmgr/test/browser/browser_autofill_hidden_document.js b/toolkit/components/passwordmgr/test/browser/browser_autofill_hidden_document.js --- a/toolkit/components/passwordmgr/test/browser/browser_autofill_hidden_document.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autofill_hidden_document.js @@ -33,11 +33,11 @@ origin: "https://example.org", formActionOrigin: "https://example.org", username: "user1", password: "pass1", }); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); }); testUrlsWithForm.forEach(testUrl => { add_task(async function test_processed_form_fired() { // Sanity check. If this doesnt work any results for the subsequent tasks are suspect diff --git a/toolkit/components/passwordmgr/test/browser/browser_autofill_http.js b/toolkit/components/passwordmgr/test/browser/browser_autofill_http.js --- a/toolkit/components/passwordmgr/test/browser/browser_autofill_http.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autofill_http.js @@ -1,23 +1,22 @@ const TEST_URL_PATH = "://example.org/browser/toolkit/components/passwordmgr/test/browser/"; add_setup(async function() { - let login = LoginTestUtils.testData.formLogin({ + const login1 = LoginTestUtils.testData.formLogin({ origin: "http://example.org", formActionOrigin: "http://example.org", username: "username", password: "password", }); - Services.logins.addLogin(login); - login = LoginTestUtils.testData.formLogin({ + const login2 = LoginTestUtils.testData.formLogin({ origin: "http://example.org", formActionOrigin: "http://example.com", username: "username", password: "password", }); - Services.logins.addLogin(login); + await Services.logins.addLogins([login1, login2]); await SpecialPowers.pushPrefEnv({ set: [["signon.autofillForms.http", false]], }); }); diff --git a/toolkit/components/passwordmgr/test/browser/browser_autofill_track_filled_logins.js b/toolkit/components/passwordmgr/test/browser/browser_autofill_track_filled_logins.js --- a/toolkit/components/passwordmgr/test/browser/browser_autofill_track_filled_logins.js +++ b/toolkit/components/passwordmgr/test/browser/browser_autofill_track_filled_logins.js @@ -29,11 +29,11 @@ "bob", "mypassword", "form-basic-username", "form-basic-password" ); - login = Services.logins.addLogin(login); + login = await Services.logins.addLoginAsync(login); Assert.equal( login.timesUsed, 1, "The timesUsed should be 1 after creation" ); diff --git a/toolkit/components/passwordmgr/test/browser/browser_context_menu.js b/toolkit/components/passwordmgr/test/browser/browser_context_menu.js --- a/toolkit/components/passwordmgr/test/browser/browser_context_menu.js +++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu.js @@ -24,13 +24,11 @@ registerCleanupFunction(() => { Services.prefs.clearUserPref("signon.autofillForms"); Services.prefs.clearUserPref("signon.schemeUpgrades"); Services.prefs.clearUserPref("signon.usernameOnlyForm.enabled"); }); - for (let login of loginList()) { - Services.logins.addLogin(login); - } + await Services.logins.addLogins(loginList()); }); /** * Check if the context menu is populated with the right * menuitems for the target password input field. diff --git a/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js b/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js --- a/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js +++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu_autocomplete_interaction.js @@ -20,13 +20,11 @@ autocompletePopup.removeEventListener( "popupshowing", autocompleteUnexpectedPopupShowing ); }); - for (let login of loginList()) { - Services.logins.addLogin(login); - } + await Services.logins.addLogins(loginList()); autocompletePopup.addEventListener( "popupshowing", autocompleteUnexpectedPopupShowing ); }); diff --git a/toolkit/components/passwordmgr/test/browser/browser_context_menu_generated_password.js b/toolkit/components/passwordmgr/test/browser/browser_context_menu_generated_password.js --- a/toolkit/components/passwordmgr/test/browser/browser_context_menu_generated_password.js +++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu_generated_password.js @@ -258,11 +258,11 @@ }); let storageChangedPromised = TestUtils.topicObserved( "passwordmgr-storage-changed", (_, data) => data == "addLogin" ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); await storageChangedPromised; let formFilled = listenForTestNotification("FormProcessed"); await BrowserTestUtils.withNewTab( diff --git a/toolkit/components/passwordmgr/test/browser/browser_context_menu_iframe.js b/toolkit/components/passwordmgr/test/browser/browser_context_menu_iframe.js --- a/toolkit/components/passwordmgr/test/browser/browser_context_menu_iframe.js +++ b/toolkit/components/passwordmgr/test/browser/browser_context_menu_iframe.js @@ -19,13 +19,11 @@ Services.prefs.setBoolPref("signon.schemeUpgrades", true); registerCleanupFunction(() => { Services.prefs.clearUserPref("signon.autofillForms"); Services.prefs.clearUserPref("signon.schemeUpgrades"); }); - for (let login of loginList()) { - Services.logins.addLogin(login); - } + await Services.logins.addLogins(loginList()); }); /** * Check if the password field is correctly filled when it's in an iframe. */ diff --git a/toolkit/components/passwordmgr/test/browser/browser_deleteLoginsBackup.js b/toolkit/components/passwordmgr/test/browser/browser_deleteLoginsBackup.js --- a/toolkit/components/passwordmgr/test/browser/browser_deleteLoginsBackup.js +++ b/toolkit/components/passwordmgr/test/browser/browser_deleteLoginsBackup.js @@ -80,14 +80,14 @@ ); info("Adding two logins: fxa key and one user facing login"); let storageUpdatePromise = TestUtils.topicObserved( "password-storage-updated" ); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); Assert.ok(true, "added login1"); await loginStoreExists(); - Services.logins.addLogin(fxaKey); + await Services.logins.addLoginAsync(fxaKey); Assert.ok(true, "added fxaKey"); await loginBackupExists(); Assert.ok(true, "logins-backup.json now exists"); await storageUpdatePromise; info("Writes to storage are complete for addLogin calls"); @@ -121,16 +121,16 @@ let storageUpdatePromise = TestUtils.topicObserved( "password-storage-updated" ); info("Add a login to create logins.json"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await loginStoreExists(); Assert.ok(true, "logins.json now exists"); info("Add a second login to create logins-backup.json"); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); await loginBackupExists(); info("logins-backup.json now exists"); await storageUpdatePromise; info("Writes to storage are complete for addLogin calls"); @@ -164,15 +164,15 @@ let storageUpdatePromise = TestUtils.topicObserved( "password-storage-updated" ); info("Add a login to create logins.json"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); Assert.ok(true, "added login1"); await loginStoreExists(); Assert.ok(true, "logins.json now exists"); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); Assert.ok(true, "added login2"); await loginBackupExists(); info("logins-backup.json now exists"); await storageUpdatePromise; @@ -191,13 +191,13 @@ ); await IOUtils.remove(loginStorePath); info("Testing the removeAllLogins() case when FxA key is present"); storageUpdatePromise = TestUtils.topicObserved("password-storage-updated"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await loginStoreExists(); - Services.logins.addLogin(fxaKey); + await Services.logins.addLoginAsync(fxaKey); await loginBackupExists(); info("logins-backup.json now exists"); await storageUpdatePromise; info("Write to storage are complete for addLogin calls"); @@ -223,13 +223,13 @@ info("Testing the removeLogin() case when there is no saved fxa key"); info("Adding two logins"); let storageUpdatePromise = TestUtils.topicObserved( "password-storage-updated" ); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await loginStoreExists(); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); await loginBackupExists(); info("logins-backup.json now exists"); await storageUpdatePromise; info("Writes to storage are complete for addLogin calls"); @@ -253,13 +253,13 @@ await IOUtils.remove(loginStorePath); info("Testing the removeLogin() case when there is a saved fxa key"); info("Adding two logins: one user facing and the fxa key"); storageUpdatePromise = TestUtils.topicObserved("password-storage-updated"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await loginStoreExists(); - Services.logins.addLogin(fxaKey); + await Services.logins.addLoginAsync(fxaKey); await loginBackupExists(); info("logins-backup.json now exists"); await storageUpdatePromise; info("Writes to storage are complete for addLogin calls"); diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_autocomplete_values.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_autocomplete_values.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_autocomplete_values.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_autocomplete_values.js @@ -136,19 +136,20 @@ await SpecialPowers.pushPrefEnv({ set: [["signon.capture.inputChanges.enabled", true]], }); } -function _addSavedLogin(username) { - Services.logins.addLogin( +async function _addSavedLogins(logins) { + let loginsData = logins.map(({ username }) => LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username, password: "Saved login passwords not used in this test", }) ); + await Services.logins.addLogins(loginsData); } async function _clickDropmarker(document, notificationElement) { let acPopup = document.querySelector(AUTOCOMPLETE_POPUP_SELECTOR); let acPopupShown = BrowserTestUtils.waitForEvent(acPopup, "popupshown"); @@ -178,16 +179,13 @@ await cleanupDoorhanger(); await cleanupPasswordNotifications(); Services.logins.removeAllUserFacingLogins(); // Create the pre-existing logins when needed. - info("Adding any saved logins"); if (testCase.savedLogins) { - for (let login of testCase.savedLogins) { - info("Adding login " + JSON.stringify(login)); - _addSavedLogin(login.username); - } + info("Adding logins " + JSON.stringify(testCase.savedLogins)); + await _addSavedLogins(testCase.savedLogins); } info("Opening tab"); await BrowserTestUtils.withNewTab( { diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_dismissed_for_ccnumber.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_dismissed_for_ccnumber.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_dismissed_for_ccnumber.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_dismissed_for_ccnumber.js @@ -164,11 +164,11 @@ "4111111111111111", "111", // password looks like a card security code "form-basic-username", "form-basic-password" ); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let passwordFilledPromise = listenForTestNotification( "PasswordEditedOrGenerated" ); diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_httpsUpgrade.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_httpsUpgrade.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_httpsUpgrade.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_httpsUpgrade.js @@ -28,11 +28,11 @@ add_task(async function test_httpsUpgradeCaptureFields_noChange() { info( "Check that we don't prompt to remember when capturing an upgraded login with no change" ); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); // Sanity check the HTTP login exists. let logins = Services.logins.getAllLogins(); Assert.equal(logins.length, 1, "Should have the HTTP login"); await testSubmittingLoginForm( @@ -71,11 +71,11 @@ add_task(async function test_httpsUpgradeCaptureFields_changePW() { info( "Check that we prompt to change when capturing an upgraded login with a new PW" ); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); // Sanity check the HTTP login exists. let logins = Services.logins.getAllLogins(); Assert.equal(logins.length, 1, "Should have the HTTP login"); await testSubmittingLoginForm( @@ -129,12 +129,11 @@ add_task( async function test_httpsUpgradeCaptureFields_changePWWithBothSchemesSaved() { info( "Check that we prompt to change and properly save when capturing an upgraded login with a new PW when an http login also exists for that username" ); - Services.logins.addLogin(login1); - Services.logins.addLogin(login1HTTPS); + await Services.logins.addLogins([login1, login1HTTPS]); let logins = Services.logins.getAllLogins(); Assert.equal(logins.length, 2, "Should have both HTTP and HTTPS logins"); await testSubmittingLoginForm( @@ -211,11 +210,11 @@ } ); add_task(async function test_httpsUpgradeCaptureFields_captureMatchingHTTP() { info("Capture a new HTTP login which matches a stored HTTPS one."); - Services.logins.addLogin(login1HTTPS); + await Services.logins.addLoginAsync(login1HTTPS); await testSubmittingLoginFormHTTP( "subtst_notifications_1.html", async function(fieldValues) { Assert.equal( diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_multipage_form.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_multipage_form.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_multipage_form.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_multipage_form.js @@ -94,11 +94,11 @@ password, expectOutcome, } = testData; // Add a login for the origin of the form if testing a change notification. if (oldPassword) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: typeof oldUsername !== "undefined" ? oldUsername : username, password: oldPassword, diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_password_edits.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_password_edits.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_password_edits.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_password_edits.js @@ -69,22 +69,22 @@ await cleanupDoorhanger(); await cleanupPasswordNotifications(); // Create the pre-existing logins when needed. if (testCase.usernameInPageExists) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: testCase.usernameInPage, password: testCase.passwordInStorage, }) ); } if (testCase.usernameChangedToExists) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: testCase.usernameChangedTo, password: testCase.passwordChangedTo, diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_remembering.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_remembering.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_remembering.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_remembering.js @@ -417,11 +417,11 @@ ); }); add_task(async function test_pwOnlyNewLoginMatchesUPForm() { info("Check for update popup when new existing pw-only login matches form."); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); await testSubmittingLoginFormHTTP( "subtst_notifications_1.html", async function(fieldValues) { Assert.equal( fieldValues.username, @@ -471,11 +471,11 @@ Services.logins.removeLogin(login); }); add_task(async function test_pwOnlyOldLoginMatchesUPForm() { info("Check for update popup when old existing pw-only login matches form."); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); // Change the timePasswordChanged to be old so that the password won't be // revealed in the doorhanger. let oldTimeMS = new Date("2009-11-15").getTime(); Services.logins.modifyLogin( @@ -540,11 +540,11 @@ add_task(async function test_pwOnlyFormMatchesLogin() { info( "Check for no notification popup when pw-only form matches existing login." ); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await testSubmittingLoginFormHTTP("subtst_notifications_6.html", function( fieldValues ) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); @@ -569,11 +569,11 @@ add_task(async function test_pwOnlyFormDoesntMatchExisting() { info( "Check for notification popup when pw-only form doesn't match existing login." ); - Services.logins.addLogin(login1B); + await Services.logins.addLoginAsync(login1B); await testSubmittingLoginFormHTTP( "subtst_notifications_6.html", async function(fieldValues) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); @@ -599,11 +599,11 @@ Services.logins.removeLogin(login1B); }); add_task(async function test_changeUPLoginOnUPForm_dont() { info("Check for change-password popup, u+p login on u+p form. (not changed)"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await testSubmittingLoginFormHTTP( "subtst_notifications_8.html", async function(fieldValues) { Assert.equal( @@ -640,11 +640,11 @@ Services.logins.removeLogin(login1); }); add_task(async function test_changeUPLoginOnUPForm_remove() { info("Check for change-password popup, u+p login on u+p form. (remove)"); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await testSubmittingLoginFormHTTP( "subtst_notifications_8.html", async function(fieldValues, browser) { Assert.equal( @@ -681,11 +681,11 @@ Assert.equal(logins.length, 0, "Should have 0 logins"); }); add_task(async function test_changeUPLoginOnUPForm_change() { info("Check for change-password popup, u+p login on u+p form."); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await testSubmittingLoginFormHTTP( "subtst_notifications_8.html", async function(fieldValues) { Assert.equal( @@ -737,11 +737,11 @@ login1.password = "notifyp1"; }); add_task(async function test_changePLoginOnUPForm() { info("Check for change-password popup, p-only login on u+p form (empty u)."); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); await testSubmittingLoginFormHTTP( "subtst_notifications_9.html", async function(fieldValues) { Assert.equal(fieldValues.username, "", "Checking submitted username"); @@ -925,11 +925,11 @@ info( "Check for notification popup when a form with 2 password fields (no username) " + "is submitted and there is a saved login with a username and different password." ); - Services.logins.addLogin(login1B); + await Services.logins.addLoginAsync(login1B); await testSubmittingLoginFormHTTP( "subtst_notifications_2pw_0un.html", async function(fieldValues) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); @@ -959,11 +959,11 @@ info( "Check for notification popup when a form with 2 password fields (no username) " + "is submitted and there is a saved login with no username and different password." ); - Services.logins.addLogin(login2B); + await Services.logins.addLoginAsync(login2B); await testSubmittingLoginFormHTTP( "subtst_notifications_2pw_0un.html", async function(fieldValues) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); @@ -993,11 +993,11 @@ info( "Check for no notification popup when a form with 2 password fields (no username) " + "is submitted and there is a saved login with a username and the same password." ); - Services.logins.addLogin(login2); + await Services.logins.addLoginAsync(login2); await testSubmittingLoginFormHTTP( "subtst_notifications_2pw_0un.html", function(fieldValues) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); @@ -1023,11 +1023,11 @@ Services.logins.removeLogin(login2); }); add_task(async function test_changeUPLoginOnPUpdateForm() { info("Check for change-password popup, u+p login on password update form."); - Services.logins.addLogin(login1); + await Services.logins.addLoginAsync(login1); await testSubmittingLoginFormHTTP( "subtst_notifications_change_p.html", async function(fieldValues) { Assert.equal(fieldValues.username, "null", "Checking submitted username"); diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_save_password.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_save_password.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_save_password.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_save_password.js @@ -87,11 +87,11 @@ password, expectOutcome, } = testData; // Add a login for the origin of the form if testing a change notification. if (oldPassword) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: typeof oldUsername !== "undefined" ? oldUsername : username, password: oldPassword, diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_submit_telemetry.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_submit_telemetry.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_submit_telemetry.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_submit_telemetry.js @@ -274,11 +274,11 @@ } } async function test_submit_telemetry(tc) { if (tc.savedLogin) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: tc.savedLogin.username, password: tc.savedLogin.password, diff --git a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_username_edits.js b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_username_edits.js --- a/toolkit/components/passwordmgr/test/browser/browser_doorhanger_username_edits.js +++ b/toolkit/components/passwordmgr/test/browser/browser_doorhanger_username_edits.js @@ -55,22 +55,22 @@ await cleanupDoorhanger(); await cleanupPasswordNotifications(); // Create the pre-existing logins when needed. if (testCase.usernameInPageExists) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: testCase.usernameInPage, password: "old password", }) ); } if (testCase.usernameChangedToExists) { - Services.logins.addLogin( + await Services.logins.addLoginAsync( LoginTestUtils.testData.formLogin({ origin: "https://example.com", formActionOrigin: "https://example.com", username: testCase.usernameChangedTo, password: "old password", diff --git a/toolkit/components/passwordmgr/test/browser/browser_focus_before_first_DOMContentLoaded.js b/toolkit/components/passwordmgr/test/browser/browser_focus_before_first_DOMContentLoaded.js --- a/toolkit/components/passwordmgr/test/browser/browser_focus_before_first_DOMContentLoaded.js +++ b/toolkit/components/passwordmgr/test/browser/browser_focus_before_first_DOMContentLoaded.js @@ -3,11 +3,11 @@ * focused before DOMContentLoaded in a new browser and process. */ "use strict"; -add_setup(function() { +add_setup(async () => { let nsLoginInfo = Components.Constructor( "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init" ); @@ -28,12 +28,11 @@ null, "testuser2", "testpass2" ); - Services.logins.addLogin(login1); - Services.logins.addLogin(login2); + await Services.logins.addLogins([login1, login2]); }); add_task(async function test_autocompleteFromUsername() { let autocompletePopup = document.getElementById("PopupAutoComplete"); let autocompletePopupShown = BrowserTestUtils.waitForEvent( diff --git a/toolkit/components/passwordmgr/test/browser/browser_localip_frame.js b/toolkit/components/passwordmgr/test/browser/browser_localip_frame.js --- a/toolkit/components/passwordmgr/test/browser/browser_localip_frame.js +++ b/toolkit/components/passwordmgr/test/browser/browser_localip_frame.js @@ -1,23 +1,21 @@ "use strict"; -add_setup(async function() { - let login = LoginTestUtils.testData.formLogin({ +add_setup(async () => { + const login1 = LoginTestUtils.testData.formLogin({ origin: "http://10.0.0.0", formActionOrigin: "https://example.org", username: "username1", password: "password1", }); - Services.logins.addLogin(login); - - login = LoginTestUtils.testData.formLogin({ + const login2 = LoginTestUtils.testData.formLogin({ origin: "https://example.org", formActionOrigin: "https://example.org", username: "username2", password: "password2", }); - Services.logins.addLogin(login); + await Services.logins.addLogins([login1, login2]); }); add_task(async function test_warningForLocalIP() { let tests = [ /* when the url of top-level and iframe are both ip address, do not show insecure warning */ diff --git a/toolkit/components/passwordmgr/test/browser/browser_private_window.js b/toolkit/components/passwordmgr/test/browser/browser_private_window.js --- a/toolkit/components/passwordmgr/test/browser/browser_private_window.js +++ b/toolkit/components/passwordmgr/test/browser/browser_private_window.js @@ -326,11 +326,11 @@ "test 3: run with a login, outside of private mode, " + "match existing username/password: no popup notification should appear" ); Services.logins.removeAllUserFacingLogins(); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let allLogins = Services.logins.getAllLogins(); // Sanity check the HTTP login exists. Assert.equal(allLogins.length, 1, "Should have the HTTP login"); let timeLastUsed = allLogins[0].timeLastUsed; let loginGuid = allLogins[0].guid; @@ -385,11 +385,11 @@ "test 3b: run with a login, in private mode," + " match existing username/password: no popup notification should appear" ); Services.logins.removeAllUserFacingLogins(); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let allLogins = Services.logins.getAllLogins(); // Sanity check the HTTP login exists. Assert.equal(allLogins.length, 1, "Should have the HTTP login"); let timeLastUsed = allLogins[0].timeLastUsed; let loginGuid = allLogins[0].guid; @@ -445,11 +445,11 @@ info( "test 4: run with a login, outside of private mode," + " add a new password: popup notification should appear" ); Services.logins.removeAllUserFacingLogins(); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); let allLogins = Services.logins.getAllLogins(); // Sanity check the HTTP login exists. Assert.equal(allLogins.length, 1, "Should have the HTTP login"); let timeLastUsed = allLogins[0].timeLastUsed; let loginGuid = allLogins[0].guid; @@ -618,11 +618,11 @@ ); }); add_task(async function test_normal_autofilled_7() { info("test 7: verify that the user/pass pair was autofilled"); - Services.logins.addLogin(login); + await Services.logins.addLoginAsync(login); // Sanity check the HTTP login exists. Assert.equal( Services.logins.getAllLogins().length, 1, diff --git a/toolkit/components/passwordmgr/test/browser/browser_username_select_dialog.js b/toolkit/components/passwordmgr/test/browser/browser_username_select_dialog.js --- a/toolkit/components/passwordmgr/test/browser/browser_username_select_dialog.js +++ b/toolkit/components/passwordmgr/test/browser/browser_username_select_dialog.js @@ -57,12 +57,11 @@ add_task(async function test_changeUPLoginOnPUpdateForm_accept() { info( "Select an u+p login from multiple logins, on password update form, and accept." ); - Services.logins.addLogin(login1); - Services.logins.addLogin(login1B); + await Services.logins.addLogins([login1, login1B]); let selectDialogPromise = TestUtils.topicObserved("select-dialog-loaded"); await testSubmittingLoginForm( "subtst_notifications_change_p.html", @@ -120,12 +119,11 @@ add_task(async function test_changeUPLoginOnPUpdateForm_cancel() { info( "Select an u+p login from multiple logins, on password update form, and cancel." ); - Services.logins.addLogin(login1); - Services.logins.addLogin(login1B); + await Services.logins.addLogins([login1, login1B]); let selectDialogPromise = TestUtils.topicObserved("select-dialog-loaded"); await testSubmittingLoginForm( "subtst_notifications_change_p.html", diff --git a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js --- a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js +++ b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js @@ -705,31 +705,29 @@ /** Initialize with a list of logins. The logins are added within the parent chrome process. * @param {array} aLogins - a list of logins to add. Each login is an array of the arguments * that would be passed to nsLoginInfo.init(). */ -function addLoginsInParent(...aLogins) { +async function addLoginsInParent(...aLogins) { let script = runInParent(function addLoginsInParentInner() { /* eslint-env mozilla/chrome-script */ - addMessageListener("addLogins", logins => { + addMessageListener("addLogins", async logins => { let nsLoginInfo = Components.Constructor( "@mozilla.org/login-manager/loginInfo;1", Ci.nsILoginInfo, "init" ); - for (let login of logins) { - let loginInfo = new nsLoginInfo(...login); - try { - Services.logins.addLogin(loginInfo); - } catch (e) { - assert.ok(false, "addLogin threw: " + e); - } + const loginInfos = logins.map(login => new nsLoginInfo(...login)); + try { + await Services.logins.addLogins(loginInfos); + } catch (e) { + assert.ok(false, "addLogins threw: " + e); } }); }); - script.sendQuery("addLogins", aLogins); + await script.sendQuery("addLogins", aLogins); return script; } /* * gTestDependsOnDeprecatedLogin Set this global to true if your test relies diff --git a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common_parent.js b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common_parent.js --- a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common_parent.js +++ b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common_parent.js @@ -38,11 +38,11 @@ * Init with a common login * If selfFilling is true or non-undefined, fires an event at the page so that * the test can start checking filled-in values. Tests that check observer * notifications might be confused by this. */ -function commonInit(selfFilling, testDependsOnDeprecatedLogin) { +async function commonInit(selfFilling, testDependsOnDeprecatedLogin) { var pwmgr = Services.logins; assert.ok(pwmgr != null, "Access LoginManager"); // Check that initial state has no logins var logins = pwmgr.getAllLogins(); @@ -67,11 +67,11 @@ "testuser", "testpass", "uname", "pword" ); - pwmgr.addLogin(login); + await pwmgr.addLoginAsync(login); } // Last sanity check logins = pwmgr.getAllLogins(); assert.equal( @@ -143,12 +143,15 @@ // Begin message listeners addMessageListener( "setupParent", - ({ selfFilling = false, testDependsOnDeprecatedLogin = false } = {}) => { - commonInit(selfFilling, testDependsOnDeprecatedLogin); + async ({ + selfFilling = false, + testDependsOnDeprecatedLogin = false, + } = {}) => { + await commonInit(selfFilling, testDependsOnDeprecatedLogin); sendAsyncMessage("doneSetup"); } ); addMessageListener("loadRecipes", async function(recipes) { diff --git a/toolkit/components/passwordmgr/test/mochitest/test_DOMInputPasswordAdded_fired_between_DOMContentLoaded_and_load_events.html b/toolkit/components/passwordmgr/test/mochitest/test_DOMInputPasswordAdded_fired_between_DOMContentLoaded_and_load_events.html --- a/toolkit/components/passwordmgr/test/mochitest/test_DOMInputPasswordAdded_fired_between_DOMContentLoaded_and_load_events.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_DOMInputPasswordAdded_fired_between_DOMContentLoaded_and_load_events.html @@ -38,11 +38,11 @@ await DOMContentLoadedPromise; } async function test_password_autofilled() { info("Adding one login for the page"); - addLoginsInParent([DEFAULT_ORIGIN, DEFAULT_ORIGIN, null, "user", "omgsecret!"]); + await addLoginsInParent([DEFAULT_ORIGIN, DEFAULT_ORIGIN, null, "user", "omgsecret!"]); let numLogins = await LoginManager.countLogins(DEFAULT_ORIGIN, DEFAULT_ORIGIN, null); is(numLogins, 1, "Correct number of logins"); let win = window.open("about:blank"); diff --git a/toolkit/components/passwordmgr/test/mochitest/test_LoginManagerContent_passwordEditedOrGenerated.html b/toolkit/components/passwordmgr/test/mochitest/test_LoginManagerContent_passwordEditedOrGenerated.html --- a/toolkit/components/passwordmgr/test/mochitest/test_LoginManagerContent_passwordEditedOrGenerated.html +++ b/toolkit/components/passwordmgr/test/mochitest/test_LoginManagerContent_passwordEditedOrGenerated.html @@ -9,16 +9,16 @@
Login Manager test: no duplicate logins when using autofill and autocomplete with related realms -