Skip to content

Commit 3d2384f

Browse files
committed
Bug 1824112 - switch to addLoginAsync in tests r=credential-management-reviewers,sync-reviewers,sgalich,markh
Differential Revision: https://phabricator.services.mozilla.com/D175704
1 parent 5ef33a8 commit 3d2384f

File tree

86 files changed

+728
-938
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+728
-938
lines changed

browser/components/aboutlogins/tests/browser/browser_loginItemErrors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ add_task(async function test_showLoginItemErrors() {
2121
"user2",
2222
"pass2"
2323
);
24-
LOGIN_TO_UPDATE = Services.logins.addLogin(LOGIN_TO_UPDATE);
24+
LOGIN_TO_UPDATE = await Services.logins.addLoginAsync(LOGIN_TO_UPDATE);
2525
EXPECTED_ERROR_MESSAGE = "This login already exists.";
2626
const LOGIN_UPDATES = {
2727
origin: "https://example.com",

browser/components/aboutlogins/tests/browser/browser_openFiltered.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ add_setup(async function() {
66
"passwordmgr-storage-changed",
77
(_, data) => data == "addLogin"
88
);
9-
TEST_LOGIN1 = Services.logins.addLogin(TEST_LOGIN1);
9+
TEST_LOGIN1 = await Services.logins.addLoginAsync(TEST_LOGIN1);
1010
await storageChangedPromised;
1111
storageChangedPromised = TestUtils.topicObserved(
1212
"passwordmgr-storage-changed",
1313
(_, data) => data == "addLogin"
1414
);
15-
TEST_LOGIN2 = Services.logins.addLogin(TEST_LOGIN2);
15+
TEST_LOGIN2 = await Services.logins.addLoginAsync(TEST_LOGIN2);
1616
await storageChangedPromised;
1717
let tabOpenedPromise = BrowserTestUtils.waitForNewTab(
1818
gBrowser,

browser/components/aboutlogins/tests/browser/head.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,12 @@ let TEST_LOGIN3 = new nsLoginInfo(
5454
TEST_LOGIN3.QueryInterface(Ci.nsILoginMetaInfo).timePasswordChanged = 123456;
5555

5656
async function addLogin(login) {
57-
let storageChangedPromised = TestUtils.topicObserved(
58-
"passwordmgr-storage-changed",
59-
(_, data) => data == "addLogin"
60-
);
61-
login = Services.logins.addLogin(login);
62-
await storageChangedPromised;
57+
const result = await Services.logins.addLoginAsync(login);
6358
registerCleanupFunction(() => {
6459
let matchData = Cc["@mozilla.org/hash-property-bag;1"].createInstance(
6560
Ci.nsIWritablePropertyBag2
6661
);
67-
matchData.setPropertyAsAUTF8String("guid", login.guid);
62+
matchData.setPropertyAsAUTF8String("guid", result.guid);
6863

6964
let logins = Services.logins.searchLogins(matchData);
7065
if (!logins.length) {
@@ -76,7 +71,7 @@ async function addLogin(login) {
7671
// matches the login that it will be removing.
7772
Services.logins.removeLogin(logins[0]);
7873
});
79-
return login;
74+
return result;
8075
}
8176

8277
let EXPECTED_BREACH = null;

browser/components/aboutlogins/tests/unit/test_getPotentialBreachesByLoginGUID.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const LOGIN_WITH_NON_STANDARD_URI = LoginTestUtils.testData.formLogin({
110110
});
111111

112112
add_task(async function test_notBreachedLogin() {
113-
Services.logins.addLogin(NOT_BREACHED_LOGIN);
113+
await Services.logins.addLoginAsync(NOT_BREACHED_LOGIN);
114114
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
115115
[NOT_BREACHED_LOGIN],
116116
TEST_BREACHES
@@ -123,7 +123,7 @@ add_task(async function test_notBreachedLogin() {
123123
});
124124

125125
add_task(async function test_breachedLogin() {
126-
Services.logins.addLogin(BREACHED_LOGIN);
126+
await Services.logins.addLoginAsync(BREACHED_LOGIN);
127127
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
128128
[NOT_BREACHED_LOGIN, BREACHED_LOGIN],
129129
TEST_BREACHES
@@ -141,7 +141,7 @@ add_task(async function test_breachedLogin() {
141141
});
142142

143143
add_task(async function test_breachedLoginAfterCrashingUriLogin() {
144-
Services.logins.addLogin(CRASHING_URI_LOGIN);
144+
await Services.logins.addLoginAsync(CRASHING_URI_LOGIN);
145145

146146
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
147147
[CRASHING_URI_LOGIN, BREACHED_LOGIN],
@@ -160,7 +160,7 @@ add_task(async function test_breachedLoginAfterCrashingUriLogin() {
160160
});
161161

162162
add_task(async function test_notBreachedSubdomain() {
163-
Services.logins.addLogin(NOT_BREACHED_SUBDOMAIN_LOGIN);
163+
await Services.logins.addLoginAsync(NOT_BREACHED_SUBDOMAIN_LOGIN);
164164

165165
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
166166
[NOT_BREACHED_LOGIN, NOT_BREACHED_SUBDOMAIN_LOGIN],
@@ -174,7 +174,7 @@ add_task(async function test_notBreachedSubdomain() {
174174
});
175175

176176
add_task(async function test_breachedSubdomain() {
177-
Services.logins.addLogin(BREACHED_SUBDOMAIN_LOGIN);
177+
await Services.logins.addLoginAsync(BREACHED_SUBDOMAIN_LOGIN);
178178

179179
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
180180
[NOT_BREACHED_SUBDOMAIN_LOGIN, BREACHED_SUBDOMAIN_LOGIN],
@@ -188,7 +188,9 @@ add_task(async function test_breachedSubdomain() {
188188
});
189189

190190
add_task(async function test_breachedSiteWithoutPasswords() {
191-
Services.logins.addLogin(LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS);
191+
await Services.logins.addLoginAsync(
192+
LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS
193+
);
192194

193195
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
194196
[LOGIN_FOR_BREACHED_SITE_WITHOUT_PASSWORDS],
@@ -252,7 +254,7 @@ add_task(async function test_newBreachAfterDismissal() {
252254
});
253255

254256
add_task(async function test_ExceptionsThrownByNonStandardURIsAreCaught() {
255-
Services.logins.addLogin(LOGIN_WITH_NON_STANDARD_URI);
257+
await Services.logins.addLoginAsync(LOGIN_WITH_NON_STANDARD_URI);
256258

257259
const breachesByLoginGUID = await LoginBreaches.getPotentialBreachesByLoginGUID(
258260
[LOGIN_WITH_NON_STANDARD_URI, BREACHED_LOGIN],

browser/components/extensions/test/xpcshell/test_ext_browsingData_passwords.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ const NEW_HOST = "http://mozilla.com";
1010
const FXA_HOST = "chrome://FirefoxAccounts";
1111

1212
function checkLoginExists(host, shouldExist) {
13-
let logins = Services.logins.findLogins(host, "", null);
13+
const logins = Services.logins.findLogins(host, "", null);
1414
equal(
1515
logins.length,
1616
shouldExist ? 1 : 0,
1717
`Login was ${shouldExist ? "" : "not "} found.`
1818
);
1919
}
2020

21-
function addLogin(host, timestamp) {
21+
async function addLogin(host, timestamp) {
2222
checkLoginExists(host, false);
2323
let login = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
2424
Ci.nsILoginInfo
2525
);
2626
login.init(host, "", null, LOGIN_USERNAME, LOGIN_PASSWORD);
2727
login.QueryInterface(Ci.nsILoginMetaInfo);
2828
login.timePasswordChanged = timestamp;
29-
Services.logins.addLogin(login);
29+
await Services.logins.addLoginAsync(login);
3030
checkLoginExists(host, true);
3131
}
3232

3333
async function setupPasswords() {
3434
Services.logins.removeAllUserFacingLogins();
35-
addLogin(FXA_HOST, REFERENCE_DATE);
36-
addLogin(NEW_HOST, REFERENCE_DATE);
37-
addLogin(OLD_HOST, REFERENCE_DATE - 10000);
35+
await addLogin(FXA_HOST, REFERENCE_DATE);
36+
await addLogin(NEW_HOST, REFERENCE_DATE);
37+
await addLogin(OLD_HOST, REFERENCE_DATE - 10000);
3838
}
3939

4040
add_task(async function testPasswords() {
@@ -49,7 +49,7 @@ add_task(async function testPasswords() {
4949
});
5050
}
5151

52-
let extension = ExtensionTestUtils.loadExtension({
52+
const extension = ExtensionTestUtils.loadExtension({
5353
background,
5454
manifest: {
5555
permissions: ["browsingData"],

browser/components/migration/tests/marionette/test_refresh_firefox.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ class TestFirefoxRefresh(MarionetteTestCase):
4040
_expectedURLs = ["about:robots", "about:mozilla"]
4141

4242
def savePassword(self):
43-
self.runCode(
43+
self.runAsyncCode(
4444
"""
45+
let [username, password, resolve] = arguments;
4546
let myLogin = new global.LoginInfo(
4647
"test.marionette.mozilla.com",
4748
"http://test.marionette.mozilla.com/some/form/",
4849
null,
49-
arguments[0],
50-
arguments[1],
50+
username,
51+
password,
5152
"username",
5253
"password"
5354
);
54-
Services.logins.addLogin(myLogin)
55+
Services.logins.addLoginAsync(myLogin)
56+
.then(() => resolve(false), resolve);
5557
""",
5658
script_args=(self._username, self._password),
5759
)

browser/components/migration/tests/unit/test_Chrome_passwords.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ var loginCrypto;
104104
var dbConn;
105105

106106
async function promiseSetPassword(login) {
107-
let encryptedString = await loginCrypto.encryptData(
107+
const encryptedString = await loginCrypto.encryptData(
108108
login.password,
109109
login.version
110110
);
111111
info(`promiseSetPassword: ${encryptedString}`);
112-
let passwordValue = new Uint8Array(
112+
const passwordValue = new Uint8Array(
113113
loginCrypto.stringToArray(encryptedString)
114114
);
115115
return dbConn.execute(
@@ -177,7 +177,7 @@ function checkLoginsAreEqual(passwordManagerLogin, chromeLogin, id) {
177177
}
178178

179179
function generateDifferentLogin(login) {
180-
let newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
180+
const newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].createInstance(
181181
Ci.nsILoginInfo
182182
);
183183

@@ -206,13 +206,13 @@ add_task(async function setup() {
206206
// would block the test from finishing if Chrome has already created a matching
207207
// Keychain entry. This allows us to still exercise the keychain lookup code.
208208
// The mock encryption passphrase is used when the Keychain item isn't found.
209-
let mockMacOSKeychain = {
209+
const mockMacOSKeychain = {
210210
passphrase: "bW96aWxsYWZpcmVmb3g=",
211211
serviceName: "TESTING Chrome Safe Storage",
212212
accountName: "TESTING Chrome",
213213
};
214214
if (AppConstants.platform == "macosx") {
215-
let { ChromeMacOSLoginCrypto } = ChromeUtils.importESModule(
215+
const { ChromeMacOSLoginCrypto } = ChromeUtils.importESModule(
216216
"resource:///modules/ChromeMacOSLoginCrypto.sys.mjs"
217217
);
218218
loginCrypto = new ChromeMacOSLoginCrypto(
@@ -230,7 +230,7 @@ add_task(async function setup() {
230230
"Login Data",
231231
];
232232
} else if (AppConstants.platform == "win") {
233-
let { ChromeWindowsLoginCrypto } = ChromeUtils.importESModule(
233+
const { ChromeWindowsLoginCrypto } = ChromeUtils.importESModule(
234234
"resource:///modules/ChromeWindowsLoginCrypto.sys.mjs"
235235
);
236236
loginCrypto = new ChromeWindowsLoginCrypto("Chrome");
@@ -246,18 +246,18 @@ add_task(async function setup() {
246246
} else {
247247
throw new Error("Not implemented");
248248
}
249-
let dirSvcFile = do_get_file(dirSvcPath);
249+
const dirSvcFile = do_get_file(dirSvcPath);
250250
registerFakePath(pathId, dirSvcFile);
251251

252252
info(PathUtils.join(dirSvcFile.path, ...profilePathSegments));
253-
let loginDataFilePath = PathUtils.join(
253+
const loginDataFilePath = PathUtils.join(
254254
dirSvcFile.path,
255255
...profilePathSegments
256256
);
257257
dbConn = await Sqlite.openConnection({ path: loginDataFilePath });
258258

259259
if (AppConstants.platform == "macosx") {
260-
let migrator = await MigrationUtils.getMigrator("chrome");
260+
const migrator = await MigrationUtils.getMigrator("chrome");
261261
Object.assign(migrator, {
262262
_keychainServiceName: mockMacOSKeychain.serviceName,
263263
_keychainAccountName: mockMacOSKeychain.accountName,
@@ -275,11 +275,11 @@ add_task(async function setup() {
275275
});
276276

277277
add_task(async function test_importIntoEmptyDB() {
278-
for (let login of TEST_LOGINS) {
278+
for (const login of TEST_LOGINS) {
279279
await promiseSetPassword(login);
280280
}
281281

282-
let migrator = await MigrationUtils.getMigrator("chrome");
282+
const migrator = await MigrationUtils.getMigrator("chrome");
283283
Assert.ok(
284284
await migrator.isSourceAvailable(),
285285
"Sanity check the source exists"
@@ -315,7 +315,7 @@ add_task(async function test_importIntoEmptyDB() {
315315

316316
// Test that existing logins for the same primary key don't get overwritten
317317
add_task(async function test_importExistingLogins() {
318-
let migrator = await MigrationUtils.getMigrator("chrome");
318+
const migrator = await MigrationUtils.getMigrator("chrome");
319319
Assert.ok(
320320
await migrator.isSourceAvailable(),
321321
"Sanity check the source exists"
@@ -329,7 +329,7 @@ add_task(async function test_importExistingLogins() {
329329
"There are no logins after removing all of them"
330330
);
331331

332-
let newLogins = [];
332+
const newLogins = [];
333333

334334
// Create 3 new logins that are different but where the key properties are still the same.
335335
for (let i = 0; i < 3; i++) {

browser/components/protections/test/browser/browser_protections_lockwise.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ const { AboutProtectionsParent } = ChromeUtils.importESModule(
1212
const ABOUT_LOGINS_URL = "about:logins";
1313

1414
add_task(async function testNoLoginsLockwiseCardUI() {
15-
let tab = await BrowserTestUtils.openNewForegroundTab({
15+
const tab = await BrowserTestUtils.openNewForegroundTab({
1616
url: "about:protections",
1717
gBrowser,
1818
});
19-
let aboutLoginsPromise = BrowserTestUtils.waitForNewTab(
19+
const aboutLoginsPromise = BrowserTestUtils.waitForNewTab(
2020
gBrowser,
2121
ABOUT_LOGINS_URL
2222
);
@@ -76,26 +76,26 @@ add_task(async function testNoLoginsLockwiseCardUI() {
7676
);
7777
savePasswordsButton.click();
7878
});
79-
let loginsTab = await aboutLoginsPromise;
79+
const loginsTab = await aboutLoginsPromise;
8080
info("about:logins was successfully opened in a new tab");
8181
gBrowser.removeTab(loginsTab);
8282
gBrowser.removeTab(tab);
8383
});
8484

8585
add_task(async function testLockwiseCardUIWithLogins() {
86-
let tab = await BrowserTestUtils.openNewForegroundTab({
86+
const tab = await BrowserTestUtils.openNewForegroundTab({
8787
url: "about:protections",
8888
gBrowser,
8989
});
90-
let aboutLoginsPromise = BrowserTestUtils.waitForNewTab(
90+
const aboutLoginsPromise = BrowserTestUtils.waitForNewTab(
9191
gBrowser,
9292
ABOUT_LOGINS_URL
9393
);
9494

9595
info(
9696
"Add a login and check that lockwise card content for a logged in user is displayed correctly"
9797
);
98-
Services.logins.addLogin(TEST_LOGIN1);
98+
await Services.logins.addLoginAsync(TEST_LOGIN1);
9999
await BrowserTestUtils.reloadTab(tab);
100100

101101
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
@@ -172,14 +172,14 @@ add_task(async function testLockwiseCardUIWithLogins() {
172172
);
173173
managePasswordsButton.click();
174174
});
175-
let loginsTab = await aboutLoginsPromise;
175+
const loginsTab = await aboutLoginsPromise;
176176
info("about:logins was successfully opened in a new tab");
177177
gBrowser.removeTab(loginsTab);
178178

179179
info(
180180
"Add another login and check that the scanned text about stored logins is updated after reload."
181181
);
182-
Services.logins.addLogin(TEST_LOGIN2);
182+
await Services.logins.addLoginAsync(TEST_LOGIN2);
183183
await BrowserTestUtils.reloadTab(tab);
184184

185185
await SpecialPowers.spawn(tab.linkedBrowser, [], async function() {
@@ -204,11 +204,11 @@ add_task(async function testLockwiseCardUIWithBreachedLogins() {
204204
info(
205205
"Add a breached login and test that the lockwise scanned text is displayed correctly"
206206
);
207-
let tab = await BrowserTestUtils.openNewForegroundTab({
207+
const tab = await BrowserTestUtils.openNewForegroundTab({
208208
url: "about:protections",
209209
gBrowser,
210210
});
211-
Services.logins.addLogin(TEST_LOGIN1);
211+
await Services.logins.addLoginAsync(TEST_LOGIN1);
212212

213213
info("Mock monitor data with a breached login to test the Lockwise UI");
214214
AboutProtectionsParent.setTestOverride(
@@ -261,7 +261,7 @@ add_task(async function testLockwiseCardUIWithBreachedLogins() {
261261
});
262262

263263
add_task(async function testLockwiseCardPref() {
264-
let tab = await BrowserTestUtils.openNewForegroundTab({
264+
const tab = await BrowserTestUtils.openNewForegroundTab({
265265
url: "about:protections",
266266
gBrowser,
267267
});

0 commit comments

Comments
 (0)