Bug 1361760 - Enable some Mozilla ESLint recommended rules for dom/indexedDB/test/unit. r=bevis

MozReview-Commit-ID: CM8apJcdRVs

--HG--
extra : rebase_source : 06d8d2b291dbd608ba68e5f7f9c622592cfd3cb6
This commit is contained in:
Mark Banner 2017-04-25 21:53:00 +01:00
parent 01417acb4d
commit 2451fe6f08
18 changed files with 70 additions and 21 deletions

View File

@ -0,0 +1,31 @@
"use strict";
module.exports = {
"extends": [
"plugin:mozilla/recommended",
"plugin:mozilla/xpcshell-test",
],
"plugins": [
"mozilla"
],
"rules": {
"brace-style": "off",
"comma-spacing": "off",
"func-call-spacing": "off",
"key-spacing": "off",
"keyword-spacing": "off",
"no-extra-semi": "off",
"no-lonely-if": "off",
"no-mixed-spaces-and-tabs": "off",
"no-multi-spaces": "off",
"no-shadow": "off",
"no-trailing-spaces": "off",
"no-unused-vars": "off",
"object-shorthand": "off",
"quotes": "off",
"spaced-comment": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-infix-ops": "off"
}
};

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* import-globals-from xpcshell-head-parent-process.js */
function ok(cond, msg) {
dump("ok(" + cond + ", \"" + msg + "\")");
do_check_true(!!cond, Components.stack.caller);

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* import-globals-from xpcshell-head-parent-process.js */
function runTest() {
const name = "Splendid Test";

View File

@ -36,11 +36,11 @@ function* testSteps()
{ autoIncrement: autoincrement,
keyPath: (keypath ? "id" : null) });
test = " for test " + JSON.stringify({ autoincrement: autoincrement,
keypath: keypath,
method: method,
explicit: explicit === undefined ? "undefined" : explicit,
existing: existing });
let test = " for test " + JSON.stringify({ autoincrement: autoincrement,
keypath: keypath,
method: method,
explicit: explicit === undefined ? "undefined" : explicit,
existing: existing });
// Insert "existing" data if needed
if (existing) {
@ -64,7 +64,7 @@ function* testSteps()
}
// Which arguments are passed to function
args = [value];
let args = [value];
if (explicit === true) {
args.push(5);
}
@ -138,7 +138,7 @@ function* testSteps()
}
}
function expectedResult(method, keypath, explicit, autoincrement, existing) {
if (keypath && explicit)
return "throw";

View File

@ -202,7 +202,7 @@ function* testSteps()
// Test separate transactions doesn't generate overlapping numbers
test = " for test non-overlapping counts";
trans = db.transaction("store1", RW);
trans2 = db.transaction("store1", RW);
let trans2 = db.transaction("store1", RW);
trans2.objectStore("store1").put({ over: 2 }).onsuccess =
genCheck(c1 + 1, { over: 2 }, "first" + test,
{ trans: trans2 });

View File

@ -100,7 +100,7 @@ function* testSteps()
let store = stores[indexName];
try {
request = store.add(info.value);
var request = store.add(info.value);
ok("key" in info, "successfully created request to insert value" + test);
} catch (e) {
ok(!("key" in info), "threw when attempted to insert" + test);
@ -185,18 +185,18 @@ function* testSteps()
continue;
}
}
let index = indexes[indexName];
request = store.add(info.value, 1);
if ("key" in info) {
index.getKey(info.key).onsuccess = grabEventAndContinueHandler;
e = yield undefined;
let e = yield undefined;
is(e.target.result, 1, "found value when reading" + test);
}
else {
index.count().onsuccess = grabEventAndContinueHandler;
e = yield undefined;
let e = yield undefined;
is(e.target.result, 0, "should be empty" + test);
}

View File

@ -26,11 +26,11 @@ function* testSteps()
let info = objectStoreInfo[i];
ok(true, "1");
request = indexedDB.open(name, i + 1);
let request = indexedDB.open(name, i + 1);
request.onerror = errorHandler;
request.onupgradeneeded = grabEventAndContinueHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
let event = yield undefined;
let db = event.target.result;
@ -95,4 +95,3 @@ function* testSteps()
finishTest();
}

View File

@ -215,7 +215,7 @@ function* testSteps()
continueToNextStep();
});
readRequestError = yield undefined;
let readRequestError = yield undefined;
if (readRequestError) {
txn.onerror = grabEventAndContinueHandler;

View File

@ -3,6 +3,8 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
/* import-globals-from ../file.js */
var disableWorkerTest = "FileHandle doesn't work in workers yet";
var testGenerator = testSteps();

View File

@ -17,6 +17,7 @@ function* testSteps()
}
// Test for IDBKeyRange and indexedDB availability in JS modules.
/* import-globals-from GlobalObjectsModule.jsm */
Cu.import(getSpec("GlobalObjectsModule.jsm"));
let test = new GlobalObjectsModule();
test.ok = ok;

View File

@ -45,12 +45,12 @@ function* testSteps()
let trans = db.transaction("data", "readwrite");
objectStore = trans.objectStore("data");
index = objectStore.index("set");
let index = objectStore.index("set");
request = index.get("bar");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result, "bar", "Got correct result");
@ -64,7 +64,7 @@ function* testSteps()
request = index.get("foopy");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.target.result, "foopy", "Got correct result");

View File

@ -39,6 +39,7 @@ function* testSteps()
request.onupgradeneeded = function(event) {
info("Got upgradeneeded event for db 2");
expectUncaughtException(true);
// eslint-disable-next-line no-undef
trigger_js_exception_by_calling_a_nonexistent_function();
};
event = yield undefined;

View File

@ -89,6 +89,7 @@ function* testSteps() {
info("Adding duplicate entry without preventDefault()");
if ("SimpleTest" in this) {
/* global SimpleTest */
SimpleTest.expectUncaughtException();
} else if ("DedicatedWorkerGlobalScope" in self &&
self instanceof DedicatedWorkerGlobalScope) {

View File

@ -31,7 +31,7 @@ function* testSteps()
is(event.type, "success", "expect a success event");
for (let autoIncrement of [false, true]) {
objectStore = db.transaction(autoIncrement, "readwrite")
let objectStore = db.transaction(autoIncrement, "readwrite")
.objectStore(autoIncrement);
request = objectStore.put({ id: 5, index: 6 });

View File

@ -15,6 +15,8 @@ function run_test() {
let thisTest = _TEST_FILE.toString().replace(/\\/g, "/");
thisTest = thisTest.substring(thisTest.lastIndexOf("/") + 1);
// This is defined globally via xpcshell.
/* global _HEAD_FILES */
_HEAD_FILES.push(do_get_file(INDEXEDDB_HEAD_FILE).path.replace(/\\/g, "/"));

View File

@ -3,6 +3,9 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Tests using testGenerator are expected to define it themselves.
/* global testGenerator */
var { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components;
if (!("self" in this)) {

View File

@ -16,6 +16,9 @@ module.exports = {
"ChromeWindow": false,
"ChromeWorker": false,
"Components": false,
"DedicatedWorkerGlobalScope": false,
"IDBLocaleAwareKeyRange": false,
"IDBMutableFile": false,
"ImageDocument": false,
"InstallTrigger": false,
// Specific to Firefox
@ -31,6 +34,7 @@ module.exports = {
// Note: StopIteration will likely be removed as part of removing legacy
// generators, see bug 968038.
"StopIteration": false,
"WebAssembly": false,
// Non-standard, specific to Firefox.
"XULElement": false,
"dump": true,

View File

@ -389,7 +389,8 @@ module.exports = {
let names =
fs.readdirSync(dir)
.filter(name => name.startsWith("head") && name.endsWith(".js"))
.filter(name => (name.startsWith("head") ||
name.startsWith("xpcshell-head")) && name.endsWith(".js"))
.map(name => path.join(dir, name));
return names;
},