Bug 1251916 - Use standard JavaScript features in toolkit/components/passwordmgr to pass eslint checks: replace legacy generators with ES6 generators. r=MattN

MozReview-Commit-ID: KxMSovx0mfl

--HG--
extra : rebase_source : 4b033e20af1efca9e6d16e0764a33a0f264f645f
This commit is contained in:
Sebastian Hengst 2016-02-28 14:11:17 -08:00
parent 5782a0a117
commit 3427f91e14
11 changed files with 50 additions and 50 deletions

View File

@ -160,7 +160,7 @@ LoginStore.prototype = {
*/
load: function ()
{
return Task.spawn(function () {
return Task.spawn(function* () {
try {
let bytes = yield OS.File.read(this.path);
@ -302,7 +302,7 @@ LoginStore.prototype = {
*/
save: function ()
{
return Task.spawn(function () {
return Task.spawn(function* () {
// Create or overwrite the file.
let bytes = gTextEncoder.encode(JSON.stringify(this.data));
yield OS.File.writeAtomic(this.path, bytes,

View File

@ -164,7 +164,7 @@ LoginManager.prototype = {
delete this._pwmgr._prefBranch;
this._pwmgr = null;
} else if (topic == "passwordmgr-storage-replace") {
Task.spawn(function () {
Task.spawn(function* () {
yield this._pwmgr._storage.terminate();
this._pwmgr._initStorage();
yield this._pwmgr.initializationPromise;

View File

@ -52,7 +52,7 @@ this.LoginManagerStorage_json.prototype = {
"logins.json");
this._store = new LoginStore(jsonPath);
return Task.spawn(function () {
return Task.spawn(function* () {
// Load the data asynchronously.
this.log("Opening database at", this._store.path);
yield this._store.load();

View File

@ -36,7 +36,7 @@ this.LoginTestUtils = {
* Forces the storage module to save all data, and the Login Manager service
* to replace the storage module with a newly initialized instance.
*/
reloadData() {
* reloadData() {
Services.obs.notifyObservers(null, "passwordmgr-storage-replace", null);
yield TestUtils.topicObserved("passwordmgr-storage-replace-complete");
},

View File

@ -165,7 +165,7 @@ const MockDocument = {
//// Initialization functions common to all tests
add_task(function test_common_initialize()
add_task(function* test_common_initialize()
{
// Before initializing the service for the first time, we should copy the key
// file required to decrypt the logins contained in the SQLite databases used

View File

@ -145,12 +145,12 @@ add_task(function test_rememberSignons()
/**
* Tests storing disabled hosts containing non-ASCII characters.
*/
add_task(function test_storage_setLoginSavingEnabled_nonascii()
add_task(function* test_storage_setLoginSavingEnabled_nonascii()
{
let hostname = "http://" + String.fromCharCode(355) + ".example.com";
Services.logins.setLoginSavingEnabled(hostname, false);
yield LoginTestUtils.reloadData();
yield* LoginTestUtils.reloadData();
LoginTestUtils.assertDisabledHostsEqual(Services.logins.getAllDisabledHosts(),
[hostname]);
LoginTestUtils.clearData();

View File

@ -275,9 +275,9 @@ add_task(function test_searchLogins_metainfo()
* Tests that the default nsILoginManagerStorage module attached to the Login
* Manager service is able to save and reload nsILoginMetaInfo properties.
*/
add_task(function test_storage_metainfo()
add_task(function* test_storage_metainfo()
{
yield LoginTestUtils.reloadData();
yield* LoginTestUtils.reloadData();
LoginTestUtils.checkLogins([gLoginInfo1, gLoginInfo2, gLoginInfo3]);
assertMetaInfoEqual(retrieveLoginMatching(gLoginInfo1), gLoginMetaInfo1);

View File

@ -36,7 +36,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "gUUIDGenerator",
*/
function promiseCreateDatabaseSchema(aConnection)
{
return Task.spawn(function () {
return Task.spawn(function* () {
yield aConnection.setSchemaVersion(5);
yield aConnection.execute("CREATE TABLE moz_logins (" +
"id INTEGER PRIMARY KEY," +
@ -113,7 +113,7 @@ function promiseInsertDisabledHost(aConnection, aHostname)
/**
* Imports login data from a SQLite file constructed using the test data.
*/
add_task(function test_import()
add_task(function* test_import()
{
let store = new LoginStore(getTempFile("test-import.json").path);
let loginsSqlite = getTempFile("test-logins.sqlite").path;
@ -177,7 +177,7 @@ add_task(function test_import()
/**
* Tests imports of NULL values due to a downgraded database.
*/
add_task(function test_import_downgraded()
add_task(function* test_import_downgraded()
{
let store = new LoginStore(getTempFile("test-import-downgraded.json").path);
let loginsSqlite = getTempFile("test-logins-downgraded.sqlite").path;
@ -215,7 +215,7 @@ add_task(function test_import_downgraded()
/**
* Verifies that importing from a SQLite file with database version 2 fails.
*/
add_task(function test_import_v2()
add_task(function* test_import_v2()
{
let store = new LoginStore(getTempFile("test-import-v2.json").path);
let loginsSqlite = do_get_file("data/signons-v2.sqlite").path;
@ -231,7 +231,7 @@ add_task(function test_import_v2()
/**
* Imports login data from a SQLite file, with database version 3.
*/
add_task(function test_import_v3()
add_task(function* test_import_v3()
{
let store = new LoginStore(getTempFile("test-import-v3.json").path);
let loginsSqlite = do_get_file("data/signons-v3.sqlite").path;

View File

@ -23,7 +23,7 @@ const TEST_STORE_FILE_NAME = "test-logins.json";
/**
* Saves login data to a file, then reloads it.
*/
add_task(function test_save_reload()
add_task(function* test_save_reload()
{
let storeForSave = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);
@ -74,7 +74,7 @@ add_task(function test_save_reload()
/**
* Checks that loading from a missing file results in empty arrays.
*/
add_task(function test_load_empty()
add_task(function* test_load_empty()
{
let store = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);
@ -91,7 +91,7 @@ add_task(function test_load_empty()
/**
* Checks that saving empty data still overwrites any existing file.
*/
add_task(function test_save_empty()
add_task(function* test_save_empty()
{
let store = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);
@ -109,7 +109,7 @@ add_task(function test_save_empty()
* Loads data from a string in a predefined format. The purpose of this test is
* to verify that the JSON format used in previous versions can be loaded.
*/
add_task(function test_load_string_predefined()
add_task(function* test_load_string_predefined()
{
let store = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);
@ -161,7 +161,7 @@ add_task(function test_load_string_predefined()
/**
* Loads login data from a malformed JSON string.
*/
add_task(function test_load_string_malformed()
add_task(function* test_load_string_malformed()
{
let store = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);
@ -186,7 +186,7 @@ add_task(function test_load_string_malformed()
* Loads login data from a malformed JSON string, using the synchronous
* initialization path.
*/
add_task(function test_load_string_malformed_sync()
add_task(function* test_load_string_malformed_sync()
{
let store = new LoginStore(getTempFile(TEST_STORE_FILE_NAME).path);

View File

@ -14,7 +14,7 @@
////////////////////////////////////////////////////////////////////////////////
//// Globals
function reloadAndCheckLogins(aExpectedLogins)
function* reloadAndCheckLoginsGen(aExpectedLogins)
{
yield LoginTestUtils.reloadData();
LoginTestUtils.checkLogins(aExpectedLogins);
@ -27,7 +27,7 @@ function reloadAndCheckLogins(aExpectedLogins)
/**
* Tests addLogin with valid non-ASCII characters.
*/
add_task(function test_storage_addLogin_nonascii()
add_task(function* test_storage_addLogin_nonascii()
{
let hostname = "http://" + String.fromCharCode(355) + ".example.com";
@ -41,27 +41,27 @@ add_task(function test_storage_addLogin_nonascii()
passwordField: "field_" + String.fromCharCode(421, 259, 349, 537),
});
Services.logins.addLogin(loginInfo);
yield reloadAndCheckLogins([loginInfo]);
yield* reloadAndCheckLoginsGen([loginInfo]);
// Store the string "test" using similarly looking glyphs.
loginInfo = TestData.authLogin({
httpRealm: String.fromCharCode(355, 277, 349, 357),
});
Services.logins.addLogin(loginInfo);
yield reloadAndCheckLogins([loginInfo]);
yield* reloadAndCheckLoginsGen([loginInfo]);
});
/**
* Tests addLogin with newline characters in the username and password.
*/
add_task(function test_storage_addLogin_newlines()
add_task(function* test_storage_addLogin_newlines()
{
let loginInfo = TestData.formLogin({
username: "user\r\nname",
password: "password\r\n",
});
Services.logins.addLogin(loginInfo);
yield reloadAndCheckLogins([loginInfo]);
yield* reloadAndCheckLoginsGen([loginInfo]);
});
/**
@ -69,15 +69,15 @@ add_task(function test_storage_addLogin_newlines()
*
* These tests exist to verify the legacy "signons.txt" storage format.
*/
add_task(function test_storage_addLogin_dot()
add_task(function* test_storage_addLogin_dot()
{
let loginInfo = TestData.formLogin({ hostname: ".", passwordField: "." });
Services.logins.addLogin(loginInfo);
yield reloadAndCheckLogins([loginInfo]);
yield* reloadAndCheckLoginsGen([loginInfo]);
loginInfo = TestData.authLogin({ httpRealm: "." });
Services.logins.addLogin(loginInfo);
yield reloadAndCheckLogins([loginInfo]);
yield* reloadAndCheckLoginsGen([loginInfo]);
});
/**
@ -85,7 +85,7 @@ add_task(function test_storage_addLogin_dot()
*
* These tests exist to verify the legacy "signons.txt" storage format.
*/
add_task(function test_storage_addLogin_parentheses()
add_task(function* test_storage_addLogin_parentheses()
{
let loginList = [
TestData.authLogin({ httpRealm: "(realm" }),
@ -100,5 +100,5 @@ add_task(function test_storage_addLogin_parentheses()
for (let loginInfo of loginList) {
Services.logins.addLogin(loginInfo);
}
yield reloadAndCheckLogins(loginList);
yield* reloadAndCheckLoginsGen(loginList);
});

View File

@ -11,11 +11,11 @@ const ENCTYPE_SDR = 1;
// kept in sync with the version there (or else the tests fail).
const CURRENT_SCHEMA = 5;
function copyFile(aLeafName)
function* copyFile(aLeafName)
{
yield OS.File.copy(OS.Path.join(do_get_file("data").path, aLeafName),
OS.Path.join(OS.Constants.Path.profileDir, aLeafName));
};
}
function openDB(aLeafName)
{
@ -23,7 +23,7 @@ function openDB(aLeafName)
dbFile.append(aLeafName);
return Services.storage.openDatabase(dbFile);
};
}
function deleteFile(pathname, filename)
{
@ -37,13 +37,13 @@ function deleteFile(pathname, filename)
if (file.exists())
file.remove(false);
} catch (e) {}
};
}
function reloadStorage(aInputPathName, aInputFileName)
{
var inputFile = null;
if (aInputFileName) {
var inputFile = Cc["@mozilla.org/file/local;1"].
inputFile = Cc["@mozilla.org/file/local;1"].
createInstance(Ci.nsILocalFile);
inputFile.initWithPath(aInputPathName);
inputFile.append(aInputFileName);
@ -56,16 +56,16 @@ function reloadStorage(aInputPathName, aInputFileName)
.initWithFile(inputFile);
return storage;
};
}
function checkStorageData(storage, ref_disabledHosts, ref_logins)
{
LoginTestUtils.assertLoginListsEqual(storage.getAllLogins(), ref_logins);
LoginTestUtils.assertDisabledHostsEqual(storage.getAllDisabledHosts(),
ref_disabledHosts);
};
}
add_task(function test_execute()
add_task(function* test_execute()
{
const OUTDIR = OS.Constants.Path.profileDir;
@ -122,7 +122,7 @@ testuser5.init("http://test.gov", "http://test.gov", null,
testnum++;
testdesc = "Test downgrade from v999 storage"
yield copyFile("signons-v999.sqlite");
yield* copyFile("signons-v999.sqlite");
// Verify the schema version in the test file.
dbConnection = openDB("signons-v999.sqlite");
do_check_eq(999, dbConnection.schemaVersion);
@ -147,7 +147,7 @@ var origFile = OS.Path.join(OUTDIR, "signons-v999-2.sqlite");
var failFile = OS.Path.join(OUTDIR, "signons-v999-2.sqlite.corrupt");
// Make sure we always start clean in a clean state.
yield copyFile("signons-v999-2.sqlite");
yield* copyFile("signons-v999-2.sqlite");
yield OS.File.remove(failFile);
Assert.throws(() => reloadStorage(OUTDIR, "signons-v999-2.sqlite"),
@ -163,7 +163,7 @@ yield OS.File.remove(failFile);
testnum++;
testdesc = "Test upgrade from v1->v2 storage"
yield copyFile("signons-v1.sqlite");
yield* copyFile("signons-v1.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v1.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
@ -190,7 +190,7 @@ testdesc = "Test upgrade v2->v1 storage";
// are upgrading it again. Any logins added by the v1 code must be properly
// upgraded.
yield copyFile("signons-v1v2.sqlite");
yield* copyFile("signons-v1v2.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v1v2.sqlite");
do_check_eq(1, dbConnection.schemaVersion);
@ -222,7 +222,7 @@ deleteFile(OUTDIR, "signons-v1v2.sqlite");
testnum++;
testdesc = "Test upgrade from v2->v3 storage"
yield copyFile("signons-v2.sqlite");
yield* copyFile("signons-v2.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v2.sqlite");
do_check_eq(2, dbConnection.schemaVersion);
@ -250,7 +250,7 @@ testdesc = "Test upgrade v3->v2 storage";
// are upgrading it again. Any logins added by the v2 code must be properly
// upgraded.
yield copyFile("signons-v2v3.sqlite");
yield* copyFile("signons-v2v3.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v2v3.sqlite");
do_check_eq(2, dbConnection.schemaVersion);
@ -282,7 +282,7 @@ deleteFile(OUTDIR, "signons-v2v3.sqlite");
testnum++;
testdesc = "Test upgrade from v3->v4 storage"
yield copyFile("signons-v3.sqlite");
yield* copyFile("signons-v3.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v3.sqlite");
do_check_eq(3, dbConnection.schemaVersion);
@ -306,7 +306,7 @@ for (var i = 0; i < 2; i++) {
testnum++;
testdesc = "Test upgrade from v3->v4->v3 storage"
yield copyFile("signons-v3v4.sqlite");
yield* copyFile("signons-v3v4.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v3v4.sqlite");
do_check_eq(3, dbConnection.schemaVersion);
@ -317,7 +317,7 @@ do_check_eq(CURRENT_SCHEMA, dbConnection.schemaVersion);
// testuser1 already has timestamps, testuser2 does not.
checkStorageData(storage, [], [testuser1, testuser2]);
var logins = storage.getAllLogins();
logins = storage.getAllLogins();
var t1, t2;
if (logins[0].username == "testuser1") {
@ -346,7 +346,7 @@ LoginTestUtils.assertTimeIsAboutNow(t2.timePasswordChanged);
testnum++;
testdesc = "Test upgrade from v4 storage"
yield copyFile("signons-v4.sqlite");
yield* copyFile("signons-v4.sqlite");
// Sanity check the test file.
dbConnection = openDB("signons-v4.sqlite");
do_check_eq(4, dbConnection.schemaVersion);