new file mode 100644
--- /dev/null
+++ b/toolkit/components/satchel/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+ rules: {
+ curly: ["error", "all"],
+ },
+};
\ No newline at end of file
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -331,18 +331,19 @@ function makeMoveToDeletedStatement(aGui
let query = "INSERT INTO moz_deleted_formhistory (guid, timeDeleted)";
let queryTerms = makeQueryPredicates(aData);
if (aGuid) {
query += " VALUES (:guid, :timeDeleted)";
} else {
// TODO: Add these items to the deleted items table once we've sorted
// out the issues from bug 756701
- if (!queryTerms)
+ if (!queryTerms) {
return undefined;
+ }
query += " SELECT guid, :timeDeleted FROM moz_formhistory WHERE " + queryTerms;
}
aData.timeDeleted = aNow;
return dbCreateAsyncStatement(query, aData, aBindingArrays);
}
@@ -378,18 +379,19 @@ XPCOMUtils.defineLazyGetter(this, "dbCon
try {
dbFile = Services.dirsvc.get("ProfD", Ci.nsIFile).clone();
dbFile.append("formhistory.sqlite");
log("Opening database at " + dbFile.path);
_dbConnection = Services.storage.openUnsharedDatabase(dbFile);
dbInit();
} catch (e) {
- if (e.result != Cr.NS_ERROR_FILE_CORRUPTED)
+ if (e.result != Cr.NS_ERROR_FILE_CORRUPTED) {
throw e;
+ }
dbCleanup(dbFile);
_dbConnection = Services.storage.openUnsharedDatabase(dbFile);
dbInit();
}
return _dbConnection;
});
--- a/toolkit/components/satchel/test/parent_utils.js
+++ b/toolkit/components/satchel/test/parent_utils.js
@@ -29,34 +29,37 @@ var ParentUtils = {
updateFormHistory(changes) {
let handler = {
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("formHistoryUpdated", { ok: false });
},
handleCompletion(reason) {
- if (!reason)
+ if (!reason) {
sendAsyncMessage("formHistoryUpdated", { ok: true });
+ }
},
};
FormHistory.update(changes, handler);
},
popupshownListener() {
let results = this.getMenuEntries();
sendAsyncMessage("onpopupshown", { results });
},
countEntries(name, value) {
let obj = {};
- if (name)
+ if (name) {
obj.fieldname = name;
- if (value)
+ }
+ if (value) {
obj.value = value;
+ }
let count = 0;
let listener = {
handleResult(result) { count = result },
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("entriesCounted", { ok: false });
},
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -39,18 +39,19 @@ function $_(formNum, name) {
// Mochitest gives us a sendKey(), but it's targeted to a specific element.
// This basically sends an untargeted key event, to whatever's focused.
function doKey(aKey, modifier) {
var keyName = "DOM_VK_" + aKey.toUpperCase();
var key = SpecialPowers.Ci.nsIDOMKeyEvent[keyName];
// undefined --> null
- if (!modifier)
- modifier = null;
+ if (!modifier) {
+ modifier = null;
+ }
// Window utils for sending fake key events.
var wutils = SpecialPowers.getDOMWindowUtils(window);
if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
wutils.sendKeyEvent("keypress", key, 0, modifier);
}
wutils.sendKeyEvent("keyup", key, 0, modifier);
@@ -71,43 +72,46 @@ function getMenuEntries() {
var results = gLastAutoCompleteResults;
gLastAutoCompleteResults = null;
return results;
}
function checkArrayValues(actualValues, expectedValues, msg) {
is(actualValues.length, expectedValues.length, "Checking array values: " + msg);
- for (var i = 0; i < expectedValues.length; i++)
+ for (var i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], msg + " Checking array entry #" + i);
+ }
}
var checkObserver = {
verifyStack: [],
callback: null,
init() {
gChromeScript.sendAsyncMessage("addObserver");
gChromeScript.addMessageListener("satchel-storage-changed", this.observe.bind(this));
},
uninit() {
gChromeScript.sendAsyncMessage("removeObserver");
},
waitForChecks(callback) {
- if (this.verifyStack.length == 0)
+ if (this.verifyStack.length == 0) {
callback();
- else
+ } else {
this.callback = callback;
+ }
},
observe({ subject, topic, data }) {
- if (data != "formhistory-add" && data != "formhistory-update")
+ if (data != "formhistory-add" && data != "formhistory-update") {
return;
+ }
ok(this.verifyStack.length > 0, "checking if saved form data was expected");
// Make sure that every piece of data we expect to be saved is saved, and no
// more. Here it is assumed that for every entry satchel saves or modifies, a
// message is sent.
//
// We don't actually check the content of the message, but just that the right
// quantity of messages is received.
@@ -257,18 +261,19 @@ function promiseACShown() {
});
}
function satchelCommonSetup() {
var chromeURL = SimpleTest.getTestFileURL("parent_utils.js");
gChromeScript = SpecialPowers.loadChromeScript(chromeURL);
gChromeScript.addMessageListener("onpopupshown", ({ results }) => {
gLastAutoCompleteResults = results;
- if (gPopupShownListener)
+ if (gPopupShownListener) {
gPopupShownListener({results});
+ }
});
SimpleTest.registerCleanupFunction(() => {
gChromeScript.sendAsyncMessage("cleanup");
gChromeScript.destroy();
});
}
--- a/toolkit/components/satchel/test/subtst_form_submission_1.html
+++ b/toolkit/components/satchel/test/subtst_form_submission_1.html
@@ -12,18 +12,19 @@
</form>
<script>
function checkSubmit(num) {
return SpecialPowers.wrap(parent).wrappedJSObject.checkSubmit(num);
}
function clickButton(num) {
- if (num == 100)
+ if (num == 100) {
document.querySelectorAll("button")[0].click();
+ }
}
// set the input's value (can't use a default value, as satchel will ignore it)
document.getElementById("subtest2").value = "subtestValue";
</script>
</body>
</html>
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -78,18 +78,19 @@ function doKeyUnprivileged(key) {
let keycode, charcode, alwaysval;
if (key.length == 1) {
keycode = 0;
charcode = key.charCodeAt(0);
alwaysval = charcode;
} else {
keycode = KeyEvent[keyName];
- if (!keycode)
- throw "invalid keyname in test";
+ if (!keycode) {
+ throw "invalid keyname in test";
+ }
charcode = 0;
alwaysval = keycode;
}
let dnEvent = document.createEvent("KeyboardEvent");
let prEvent = document.createEvent("KeyboardEvent");
let upEvent = document.createEvent("KeyboardEvent");
--- a/toolkit/components/satchel/test/test_datalist_with_caching.html
+++ b/toolkit/components/satchel/test/test_datalist_with_caching.html
@@ -90,18 +90,19 @@ function waitForMenuChange(expectedCount
});
}
registerPopupShownListener(popupShownListener);
function checkMenuEntries(expectedValues) {
var actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNum + " Checking length of expected menu");
- for (var i = 0; i < expectedValues.length; i++)
+ for (var i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #" + i);
+ }
}
async function runTests() {
testNum++;
restoreForm();
doKey("down");
await expectPopup();
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -424,20 +424,21 @@ function runTest() { // eslint-disable-l
case 50:
checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
// Delete the first entry (of 4)
setForm("value");
doKey("down");
// On OS X, shift-backspace and shift-delete work, just delete does not.
// On Win/Linux, shift-backspace does not work, delete and shift-delete do.
- if (SpecialPowers.OS == "Darwin")
- doKey("back_space", shiftModifier);
- else
- doKey("delete", shiftModifier);
+ if (SpecialPowers.OS == "Darwin") {
+ doKey("back_space", shiftModifier);
+ } else {
+ doKey("delete", shiftModifier);
+ }
// This tests that on OS X shift-backspace didn't delete the last character
// in the input (bug 480262).
waitForMenuChange(3);
break;
case 51:
checkForm("value");
@@ -1027,33 +1028,35 @@ function runTest() { // eslint-disable-l
function addEntry(name, value) {
updateFormHistory({ op: "add", fieldname: name, value }, runTest);
}
// Runs the next test when scroll event occurs
function waitForScroll() {
addEventListener("scroll", function() {
- if (!window.pageYOffset)
- return;
+ if (!window.pageYOffset) {
+ return;
+ }
removeEventListener("scroll", arguments.callee, false);
setTimeout(runTest, 100);
}, false);
}
function waitForMenuChange(expectedCount, expectedFirstValue) {
notifyMenuChanged(expectedCount, expectedFirstValue, runTest);
}
function checkMenuEntries(expectedValues, testNumber) {
var actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNumber + " Checking length of expected menu");
- for (var i = 0; i < expectedValues.length; i++)
+ for (var i = 0; i < expectedValues.length; i++) {
is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
+ }
}
function startTest() {
setupFormHistory(function() {
runTest();
});
}
--- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
@@ -483,18 +483,19 @@ function runTest() {
function waitForMenuChange(expectedCount) {
notifyMenuChanged(expectedCount, null, runTest);
}
function checkMenuEntries(expectedValues, testNumber) {
var actualValues = getMenuEntries();
is(actualValues.length, expectedValues.length, testNumber + " Checking length of expected menu");
- for (var i = 0; i < expectedValues.length; i++)
- is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
+ for (var i = 0; i < expectedValues.length; i++) {
+ is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
+ }
}
function startTest() {
setupFormHistory(runTest);
}
window.onload = startTest;
--- a/toolkit/components/satchel/test/unit/head_satchel.js
+++ b/toolkit/components/satchel/test/unit/head_satchel.js
@@ -35,61 +35,77 @@ const isGUID = /[A-Za-z0-9\+\/]{16}/;
// Find form history entries.
function searchEntries(terms, params, iter) {
let results = [];
FormHistory.search(terms, params, { handleResult: result => results.push(result),
handleError(error) {
do_throw("Error occurred searching form history: " + error);
},
- handleCompletion(reason) { if (!reason) iter.next(results); }
+ handleCompletion(reason) {
+ if (!reason) {
+ iter.next(results);
+ }
+ }
});
}
// Count the number of entries with the given name and value, and call then(number)
// when done. If name or value is null, then the value of that field does not matter.
function countEntries(name, value, then) {
var obj = {};
- if (name !== null)
+ if (name !== null) {
obj.fieldname = name;
- if (value !== null)
+ }
+ if (value !== null) {
obj.value = value;
+ }
let count = 0;
FormHistory.count(obj, { handleResult: result => count = result,
handleError(error) {
do_throw("Error occurred searching form history: " + error);
},
- handleCompletion(reason) { if (!reason) then(count); }
+ handleCompletion(reason) {
+ if (!reason) {
+ then(count);
+ }
+ }
});
}
// Perform a single form history update and call then() when done.
function updateEntry(op, name, value, then) {
var obj = { op };
- if (name !== null)
+ if (name !== null) {
obj.fieldname = name;
- if (value !== null)
+ }
+ if (value !== null) {
obj.value = value;
+ }
updateFormHistory(obj, then);
}
// Add a single form history entry with the current time and call then() when done.
function addEntry(name, value, then) {
let now = Date.now() * 1000;
updateFormHistory({ op: "add", fieldname: name, value, timesUsed: 1,
firstUsed: now, lastUsed: now }, then);
}
// Wrapper around FormHistory.update which handles errors. Calls then() when done.
function updateFormHistory(changes, then) {
FormHistory.update(changes, { handleError(error) {
do_throw("Error occurred updating form history: " + error);
},
- handleCompletion(reason) { if (!reason) then(); },
+ handleCompletion(reason) {
+ if (!reason) {
+ then();
+ }
+ },
});
}
/**
* Logs info to the console in the standard way (includes the filename).
*
* @param aMessage
* The message to log to the console.
--- a/toolkit/components/satchel/test/unit/test_async_expire.js
+++ b/toolkit/components/satchel/test/unit/test_async_expire.js
@@ -24,18 +24,19 @@ var TestObserver = {
if (data == "formhistory-expireoldentries") {
next_test();
}
}
};
function test_finished() {
// Make sure we always reset prefs.
- if (Services.prefs.prefHasUserValue("browser.formfill.expire_days"))
+ if (Services.prefs.prefHasUserValue("browser.formfill.expire_days")) {
Services.prefs.clearUserPref("browser.formfill.expire_days");
+ }
do_test_finished();
}
var iter = tests();
function run_test() {
do_test_pending();
@@ -51,18 +52,19 @@ function* tests() {
// ===== test init =====
var testfile = do_get_file("asyncformhistory_expire.sqlite");
var profileDir = do_get_profile();
// Cleanup from any previous tests or failures.
dbFile = profileDir.clone();
dbFile.append("formhistory.sqlite");
- if (dbFile.exists())
+ if (dbFile.exists()) {
dbFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
do_check_true(dbFile.exists());
// We're going to clear this at the end, so it better have the default value now.
do_check_false(Services.prefs.prefHasUserValue("browser.formfill.expire_days"));
// Sanity check initial state
--- a/toolkit/components/satchel/test/unit/test_autocomplete.js
+++ b/toolkit/components/satchel/test/unit/test_autocomplete.js
@@ -9,18 +9,19 @@ var fac;
var prefs;
var numRecords, timeGroupingSize, now;
const DEFAULT_EXPIRE_DAYS = 180;
function padLeft(number, length) {
var str = number + "";
- while (str.length < length)
- str = "0" + str;
+ while (str.length < length) {
+ str = "0" + str;
+ }
return str;
}
function getFormExpiryDays() {
if (prefs.prefHasUserValue("browser.formfill.expire_days")) {
return prefs.getIntPref("browser.formfill.expire_days");
}
return DEFAULT_EXPIRE_DAYS;
@@ -29,18 +30,19 @@ function getFormExpiryDays() {
function run_test() {
// ===== test init =====
var testfile = do_get_file("formhistory_autocomplete.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
fac = Cc["@mozilla.org/satchel/form-autocomplete;1"].
getService(Ci.nsIFormAutoComplete);
prefs = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefBranch);
--- a/toolkit/components/satchel/test/unit/test_db_corrupt.js
+++ b/toolkit/components/satchel/test/unit/test_db_corrupt.js
@@ -7,23 +7,25 @@ var bakFile;
function run_test() {
// ===== test init =====
let testfile = do_get_file("formhistory_CORRUPT.sqlite");
let profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
let destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
bakFile = profileDir.clone();
bakFile.append("formhistory.sqlite.corrupt");
- if (bakFile.exists())
+ if (bakFile.exists()) {
bakFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
run_next_test();
}
add_test(function test_corruptFormHistoryDB_lazyCorruptInit1() {
do_log_info("ensure FormHistory backs up a corrupt DB on initialization.");
--- a/toolkit/components/satchel/test/unit/test_db_update_v4.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4.js
@@ -17,18 +17,19 @@ function* next_test() {
// ===== test init =====
var testfile = do_get_file("formhistory_v3.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
do_check_eq(3, getDBVersion(testfile));
// ===== 1 =====
testnum++;
destFile = profileDir.clone();
--- a/toolkit/components/satchel/test/unit/test_db_update_v4b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4b.js
@@ -17,18 +17,19 @@ function* next_test() {
// ===== test init =====
var testfile = do_get_file("formhistory_v3v4.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
do_check_eq(3, getDBVersion(testfile));
// ===== 1 =====
testnum++;
destFile = profileDir.clone();
--- a/toolkit/components/satchel/test/unit/test_db_update_v999a.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999a.js
@@ -28,18 +28,19 @@ function* tests() {
// ===== test init =====
var testfile = do_get_file("formhistory_v999a.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
do_check_eq(999, getDBVersion(testfile));
let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
// ===== 1 =====
--- a/toolkit/components/satchel/test/unit/test_db_update_v999b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999b.js
@@ -28,23 +28,25 @@ function* tests() {
// ===== test init =====
var testfile = do_get_file("formhistory_v999b.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
var bakFile = profileDir.clone();
bakFile.append("formhistory.sqlite.corrupt");
- if (bakFile.exists())
+ if (bakFile.exists()) {
bakFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
do_check_eq(999, getDBVersion(testfile));
let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
// ===== 1 =====
--- a/toolkit/components/satchel/test/unit/test_history_api.js
+++ b/toolkit/components/satchel/test/unit/test_history_api.js
@@ -43,20 +43,22 @@ function checkTimeDeleted(guid, checkFun
stmt.finalize();
}
});
});
}
function promiseUpdateEntry(op, name, value) {
var change = { op };
- if (name !== null)
+ if (name !== null) {
change.fieldname = name;
- if (value !== null)
+ }
+ if (value !== null) {
change.value = value;
+ }
return promiseUpdate(change);
}
function promiseUpdate(change) {
return new Promise((resolve, reject) => {
FormHistory.update(change, {
handleError(error) {
this._error = error;
@@ -76,17 +78,21 @@ function promiseSearchEntries(terms, par
return new Promise((resolve, reject) => {
let results = [];
FormHistory.search(terms, params,
{ handleResult: result => results.push(result),
handleError(error) {
do_throw("Error occurred searching form history: " + error);
reject(error);
},
- handleCompletion(reason) { if (!reason) resolve(results); }
+ handleCompletion(reason) {
+ if (!reason) {
+ resolve(results);
+ }
+ }
});
});
}
function promiseCountEntries(name, value, checkFn) {
return new Promise(resolve => {
countEntries(name, value, function(result) { checkFn(result); resolve(); } );
});
@@ -100,18 +106,19 @@ add_task(async function() {
// ===== test init =====
var testfile = do_get_file("formhistory_apitest.sqlite");
var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
// Cleanup from any previous tests or failures.
var destFile = profileDir.clone();
destFile.append("formhistory.sqlite");
- if (destFile.exists())
+ if (destFile.exists()) {
destFile.remove(false);
+ }
testfile.copyTo(profileDir, "formhistory.sqlite");
function checkExists(num) { do_check_true(num > 0); }
function checkNotExists(num) { do_check_true(num == 0); }
// ===== 1 =====
// Check initial state is as expected
@@ -162,17 +169,21 @@ add_task(async function() {
// Cannot use promiseCountEntries when name and value are null because it treats null values as not set
// and here a search should be done explicity for null.
deferred = Promise.defer();
await FormHistory.count({ fieldname: null, value: null },
{ handleResult: result => checkNotExists(result),
handleError(error) {
do_throw("Error occurred searching form history: " + error);
},
- handleCompletion(reason) { if (!reason) deferred.resolve() }
+ handleCompletion(reason) {
+ if (!reason) {
+ deferred.resolve()
+ }
+ }
});
await deferred.promise;
// ===== 3 =====
// Test removeEntriesForName with a single matching value
testnum++;
await promiseUpdateEntry("remove", "name-A", null);
--- a/toolkit/components/satchel/test/unit/test_notify.js
+++ b/toolkit/components/satchel/test/unit/test_notify.js
@@ -134,17 +134,21 @@ do_check_eq(expectedNotification, null);
/* ========== 8 ========== */
testnum++;
testdesc = "removeEntriesByTimeframe";
expectedNotification = "formhistory-remove";
expectedData = [10, 99999999999];
yield FormHistory.update({ op: "remove", firstUsedStart: expectedData[0], firstUsedEnd: expectedData[1] },
- { handleCompletion(reason) { if (!reason) next_test() },
+ { handleCompletion(reason) {
+ if (!reason) {
+ next_test()
+ }
+ },
handleErrors(error) {
do_throw("Error occurred updating form history: " + error);
}
});
do_check_eq(expectedNotification, null);
os.removeObserver(TestObserver, "satchel-storage-changed");