Bug 1786094 - Enable ESlint rule no-unused-vars on the global scope for dom/localstorage xpcshell-tests. r=asuth

Differential Revision: https://phabricator.services.mozilla.com/D155122
This commit is contained in:
Mark Banner 2022-08-23 21:10:15 +00:00
parent a76d24cb29
commit 66dfc61a41
35 changed files with 70 additions and 105 deletions

View File

@ -190,7 +190,6 @@ module.exports = {
// investigation or different solutions. They are also likely to be // investigation or different solutions. They are also likely to be
// a reasonable size. // a reasonable size.
"dom/indexedDB/**", "dom/indexedDB/**",
"dom/localstorage/**",
], ],
rules: { rules: {
// No declaring variables that are never used // No declaring variables that are never used

View File

@ -38,17 +38,9 @@ if (!window.runTest) {
await requestFinished(clearAllDatabases()); await requestFinished(clearAllDatabases());
ok(typeof testSteps === "function", "There should be a testSteps function");
ok(
testSteps.constructor.name === "AsyncFunction",
"testSteps should be an async function"
);
SimpleTest.registerCleanupFunction(async function() { SimpleTest.registerCleanupFunction(async function() {
await requestFinished(clearAllDatabases()); await requestFinished(clearAllDatabases());
}); });
add_task(testSteps);
}; };
} }

View File

@ -16,36 +16,15 @@ function ok(cond, msg) {
Assert.ok(!!cond, msg); Assert.ok(!!cond, msg);
} }
function run_test() { add_setup(function() {
runTest();
}
if (!this.runTest) {
this.runTest = function() {
do_get_profile(); do_get_profile();
enableTesting(); enableTesting();
Cu.importGlobalProperties(["crypto"]); Cu.importGlobalProperties(["crypto"]);
Assert.ok(
typeof testSteps === "function",
"There should be a testSteps function"
);
Assert.ok(
testSteps.constructor.name === "AsyncFunction",
"testSteps should be an async function"
);
registerCleanupFunction(resetTesting); registerCleanupFunction(resetTesting);
});
add_task(testSteps);
// Since we defined run_test, we must invoke run_next_test() to start the
// async test.
run_next_test();
};
}
function returnToEventLoop() { function returnToEventLoop() {
return new Promise(function(resolve) { return new Promise(function(resolve) {

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const lsArchiveFile = "storage/ls-archive.sqlite"; const lsArchiveFile = "storage/ls-archive.sqlite";
const principalInfo = { const principalInfo = {
@ -75,4 +75,4 @@ async function testSteps() {
ok(fileSize > 0, "archive file size is greater than zero"); ok(fileSize > 0, "archive file size is greater than zero");
checkStorage(); checkStorage();
} });

View File

@ -8,7 +8,7 @@
* We turn on client validation for LocalStorage and ensure that we don't have * We turn on client validation for LocalStorage and ensure that we don't have
* access to LocalStorage. * access to LocalStorage.
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal = getPrincipal("http://example.com"); const principal = getPrincipal("http://example.com");
info("Setting prefs"); info("Setting prefs");
@ -29,4 +29,4 @@ async function testSteps() {
is(ex.name, "NS_ERROR_FAILURE", "Threw right Exception"); is(ex.name, "NS_ERROR_FAILURE", "Threw right Exception");
is(ex.result, Cr.NS_ERROR_FAILURE, "Threw with right result"); is(ex.result, Cr.NS_ERROR_FAILURE, "Threw with right result");
} }
} });

View File

@ -36,7 +36,7 @@ async function doTest(profile) {
is(request.result.usage, 0, "Correct usage"); is(request.result.usage, 0, "Correct usage");
} }
async function testSteps() { add_task(async function testSteps() {
info("Setting pref"); info("Setting pref");
Services.prefs.setBoolPref( Services.prefs.setBoolPref(
@ -70,4 +70,4 @@ async function testSteps() {
for (const profile of profiles) { for (const profile of profiles) {
await doTest(profile); await doTest(profile);
} }
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
enableNextGenLocalStorage(); enableNextGenLocalStorage();
storeData(); storeData();
@ -20,4 +20,4 @@ async function testSteps() {
exportShadowDatabase("shadowdb.sqlite"); exportShadowDatabase("shadowdb.sqlite");
// The shadow database is now prepared for test_databaseShadowing2.js // The shadow database is now prepared for test_databaseShadowing2.js
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
// The shadow database was prepared in test_databaseShadowing1.js // The shadow database was prepared in test_databaseShadowing1.js
disableNextGenLocalStorage(); disableNextGenLocalStorage();
@ -14,4 +14,4 @@ async function testSteps() {
ok(importShadowDatabase("shadowdb.sqlite"), "Import succeeded"); ok(importShadowDatabase("shadowdb.sqlite"), "Import succeeded");
verifyData([], /* migrated */ true); verifyData([], /* migrated */ true);
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
enableNextGenLocalStorage(); enableNextGenLocalStorage();
storeData(); storeData();
@ -27,4 +27,4 @@ async function testSteps() {
// The shadow database is now prepared for // The shadow database is now prepared for
// test_databaseShadowing_clearOrigin2.js // test_databaseShadowing_clearOrigin2.js
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
// The shadow database was prepared in test_databaseShadowing_clearOrigin1.js // The shadow database was prepared in test_databaseShadowing_clearOrigin1.js
disableNextGenLocalStorage(); disableNextGenLocalStorage();
@ -14,4 +14,4 @@ async function testSteps() {
ok(importShadowDatabase("shadowdb-clearedOrigin.sqlite"), "Import succeeded"); ok(importShadowDatabase("shadowdb-clearedOrigin.sqlite"), "Import succeeded");
verifyData([1], /* migrated */ true); verifyData([1], /* migrated */ true);
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
enableNextGenLocalStorage(); enableNextGenLocalStorage();
storeData(); storeData();
@ -26,4 +26,4 @@ async function testSteps() {
// The shadow database is now prepared for // The shadow database is now prepared for
// test_databaseShadowing_clearOriginsByPattern2.js // test_databaseShadowing_clearOriginsByPattern2.js
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
// The shadow database was prepared in // The shadow database was prepared in
// test_databaseShadowing_clearOriginsByPattern1.js // test_databaseShadowing_clearOriginsByPattern1.js
@ -18,4 +18,4 @@ async function testSteps() {
); );
verifyData([4, 5, 6], /* migrated */ true); verifyData([4, 5, 6], /* migrated */ true);
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
enableNextGenLocalStorage(); enableNextGenLocalStorage();
storeData(); storeData();
@ -25,4 +25,4 @@ async function testSteps() {
// The shadow database is now prepared for // The shadow database is now prepared for
// test_databaseShadowing_clearOriginsByPrefix2.js // test_databaseShadowing_clearOriginsByPrefix2.js
} });

View File

@ -6,7 +6,7 @@
/* import-globals-from databaseShadowing-shared.js */ /* import-globals-from databaseShadowing-shared.js */
loadSubscript("databaseShadowing-shared.js"); loadSubscript("databaseShadowing-shared.js");
async function testSteps() { add_task(async function testSteps() {
// The shadow database was prepared in // The shadow database was prepared in
// test_databaseShadowing_clearOriginsByPrefix1.js // test_databaseShadowing_clearOriginsByPrefix1.js
@ -18,4 +18,4 @@ async function testSteps() {
); );
verifyData([2, 3], /* migrated */ true); verifyData([2, 3], /* migrated */ true);
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const globalLimitKB = 5 * 1024; const globalLimitKB = 5 * 1024;
const data = {}; const data = {};
@ -88,4 +88,4 @@ async function testSteps() {
await requestFinished(request); await requestFinished(request);
is(request.result.usage, 0, "Zero usage"); is(request.result.usage, 0, "Zero usage");
} });

View File

@ -9,7 +9,7 @@
* database in the event of early return due to error. See bug 1559029. * database in the event of early return due to error. See bug 1559029.
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal1 = getPrincipal("http://example1.com"); const principal1 = getPrincipal("http://example1.com");
const usageFile1 = getRelativeFile( const usageFile1 = getRelativeFile(
@ -69,4 +69,4 @@ async function testSteps() {
// Wait for all database connections to close. // Wait for all database connections to close.
let request = reset(); let request = reset();
await requestFinished(request); await requestFinished(request);
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const groupLimitKB = 10 * 1024; const groupLimitKB = 10 * 1024;
const globalLimitKB = groupLimitKB * 5; const globalLimitKB = groupLimitKB * 5;
@ -82,4 +82,4 @@ async function testSteps() {
for (let i = 0; i < urls.length; i++) { for (let i = 0; i < urls.length; i++) {
storages[i].setItem("B", ""); storages[i].setItem("B", "");
} }
} });

View File

@ -9,7 +9,7 @@
* quota object. See bug 1516333. * quota object. See bug 1516333.
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal = getPrincipal("https://foo.bar.mozilla-iot.org"); const principal = getPrincipal("https://foo.bar.mozilla-iot.org");
info("Clearing"); info("Clearing");
@ -42,4 +42,4 @@ async function testSteps() {
info("Adding item"); info("Adding item");
storage.setItem("foo", "bar"); storage.setItem("foo", "bar");
} });

View File

@ -10,7 +10,7 @@
* IPC message size limit would be exceeded, resulting in a crash. * IPC message size limit would be exceeded, resulting in a crash.
*/ */
async function testSteps() { add_task(async function testSteps() {
const globalLimitKB = 5 * 1024; const globalLimitKB = 5 * 1024;
// 18 and more iterations would produce an IPC message with size greater than // 18 and more iterations would produce an IPC message with size greater than
@ -85,4 +85,4 @@ async function testSteps() {
await returnToEventLoop(); await returnToEventLoop();
ok(!storage.hasSnapshot, "Snapshot successfully finished"); ok(!storage.hasSnapshot, "Snapshot successfully finished");
} });

View File

@ -8,7 +8,6 @@
* can lead to a data loss in a combination with disabled shadow writes. * can lead to a data loss in a combination with disabled shadow writes.
*/ */
// eslint-disable-next-line no-unused-vars add_task(async function testSteps() {
async function testSteps() {
ok(Services.domStorageManager.nextGenLocalStorageEnabled, "LSNG enabled"); ok(Services.domStorageManager.nextGenLocalStorageEnabled, "LSNG enabled");
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const principalInfos = [ const principalInfos = [
{ url: "http://localhost", attrs: {} }, { url: "http://localhost", attrs: {} },
{ url: "http://www.mozilla.org", attrs: {} }, { url: "http://www.mozilla.org", attrs: {} },
@ -124,4 +124,4 @@ async function testSteps() {
verifyData(clearedOrigins); verifyData(clearedOrigins);
} }
} });

View File

@ -3,8 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
// eslint-disable-next-line no-unused-vars add_task(async function testSteps() {
async function testSteps() {
const data = { const data = {
key: "foo", key: "foo",
value: "", value: "",
@ -35,4 +34,4 @@ async function testSteps() {
info("Verifying data"); info("Verifying data");
is(storage.getItem(data.key), data.value, "Correct value"); is(storage.getItem(data.key), data.value, "Correct value");
} });

View File

@ -8,11 +8,10 @@
* implementations has no effect anymore. * implementations has no effect anymore.
*/ */
// eslint-disable-next-line no-unused-vars add_task(async function testSteps() {
async function testSteps() {
info("Setting pref"); info("Setting pref");
Services.prefs.setBoolPref("dom.storage.next_gen", false); Services.prefs.setBoolPref("dom.storage.next_gen", false);
ok(Services.domStorageManager.nextGenLocalStorageEnabled, "LSNG enabled"); ok(Services.domStorageManager.nextGenLocalStorageEnabled, "LSNG enabled");
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const url = "http://example.com"; const url = "http://example.com";
info("Setting pref"); info("Setting pref");
@ -67,4 +67,4 @@ async function testSteps() {
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
is(keys[i], savedKeys[i], "Correct key"); is(keys[i], savedKeys[i], "Correct key");
} }
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const storageDirName = "storage"; const storageDirName = "storage";
const persistenceTypeDefaultDirName = "default"; const persistenceTypeDefaultDirName = "default";
const persistenceTypePersistentDirName = "permanent"; const persistenceTypePersistentDirName = "permanent";
@ -369,4 +369,4 @@ async function testSteps() {
ok(exists, "ls directory in permanent origin directory does exist"); ok(exists, "ls directory in permanent origin directory does exist");
await clearPersistentTestOrigin(); await clearPersistentTestOrigin();
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const principals = [ const principals = [
getPrincipal("http://example.com", {}), getPrincipal("http://example.com", {}),
getPrincipal("http://example.com", { privateBrowsingId: 1 }), getPrincipal("http://example.com", { privateBrowsingId: 1 }),
@ -81,4 +81,4 @@ async function testSteps() {
"Data is not preloaded after clearing origin" "Data is not preloaded after clearing origin"
); );
} }
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const url = "http://example.com"; const url = "http://example.com";
info("Setting pref"); info("Setting pref");
@ -36,4 +36,4 @@ async function testSteps() {
let storage = getLocalStorage(getPrincipal(url)); let storage = getLocalStorage(getPrincipal(url));
storage.open(); storage.open();
} });

View File

@ -2,9 +2,8 @@
* Any copyright is dedicated to the Public Domain. * Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
/* eslint no-unused-vars: ["warn", { "varsIgnorePattern": "(testSteps)" }]*/
async function testSteps() { add_task(async function testSteps() {
const url = "http://example.com"; const url = "http://example.com";
info("Setting pref"); info("Setting pref");
@ -37,4 +36,4 @@ async function testSteps() {
let storage = getLocalStorage(getPrincipal(url)); let storage = getLocalStorage(getPrincipal(url));
storage.open(); storage.open();
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const url = "http://example.com"; const url = "http://example.com";
info("Setting pref"); info("Setting pref");
@ -327,4 +327,4 @@ async function testSteps() {
await returnToEventLoop(); await returnToEventLoop();
} }
} }
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal = getPrincipal("http://example.org"); const principal = getPrincipal("http://example.org");
const data = {}; const data = {};
@ -71,4 +71,4 @@ async function testSteps() {
value = storage.getItem(data.secondKey); value = storage.getItem(data.secondKey);
ok(value.length === data.value.length, "Correct string length"); ok(value.length === data.value.length, "Correct string length");
} });

View File

@ -8,7 +8,7 @@
* database values containing NULs. See bug 1541681. * database values containing NULs. See bug 1541681.
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal = getPrincipal("http://example.org"); const principal = getPrincipal("http://example.org");
const data = {}; const data = {};
@ -76,4 +76,4 @@ async function testSteps() {
value = storage.getItem(data.secondKey); value = storage.getItem(data.secondKey);
ok(value.length === data.value.length, "Correct string length"); ok(value.length === data.value.length, "Correct string length");
} });

View File

@ -135,8 +135,7 @@ const fetchFromNewSnapshotNewDatastore = async (itemKey, sample) => {
}); });
}; };
/* eslint no-unused-vars: ["warn", { "varsIgnorePattern": "(testSteps)" }]*/ add_task(async function testSteps() {
async function testSteps() {
/* This test is based on bug 1681300 */ /* This test is based on bug 1681300 */
Services.prefs.setBoolPref( Services.prefs.setBoolPref(
"dom.storage.enable_unsupported_legacy_implementation", "dom.storage.enable_unsupported_legacy_implementation",
@ -203,4 +202,4 @@ async function testSteps() {
"NewSnapshotNewDatastore", "NewSnapshotNewDatastore",
fetchFromNewSnapshotNewDatastore fetchFromNewSnapshotNewDatastore
); );
} });

View File

@ -11,7 +11,7 @@
* of a null quota object. See bug 1516333. * of a null quota object. See bug 1516333.
*/ */
async function testSteps() { add_task(async function testSteps() {
/** /**
* The edge cases are specified in this array of origins. Each edge case must * The edge cases are specified in this array of origins. Each edge case must
* contain two properties uri and path (origin directory path relative to the * contain two properties uri and path (origin directory path relative to the
@ -66,4 +66,4 @@ async function testSteps() {
ok(originDir.exists(), `The origin directory ${origin.path} should exist`); ok(originDir.exists(), `The origin directory ${origin.path} should exist`);
} }
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const data = {}; const data = {};
data.key = "key1"; data.key = "key1";
data.value = "value1"; data.value = "value1";
@ -66,4 +66,4 @@ async function testSteps() {
await requestFinished(request); await requestFinished(request);
is(request.result.usage, 0, "Correct usage"); is(request.result.usage, 0, "Correct usage");
} });

View File

@ -3,7 +3,7 @@
* http://creativecommons.org/publicdomain/zero/1.0/ * http://creativecommons.org/publicdomain/zero/1.0/
*/ */
async function testSteps() { add_task(async function testSteps() {
const principal = getPrincipal("http://example.com"); const principal = getPrincipal("http://example.com");
const dataFile = getRelativeFile( const dataFile = getRelativeFile(
@ -161,4 +161,4 @@ async function testSteps() {
verifyData(); verifyData();
await verifyUsage(/* success */ true); await verifyUsage(/* success */ true);
} });