--- a/toolkit/components/satchel/.eslintrc.js
+++ b/toolkit/components/satchel/.eslintrc.js
@@ -1,7 +1,22 @@
"use strict";
module.exports = {
rules: {
curly: ["error", "all"],
+ indent: ["error", 2, {
+ SwitchCase: 1,
+ CallExpression: {
+ arguments: "first",
+ },
+ FunctionExpression: {
+ parameters: "first",
+ },
+ FunctionDeclaration: {
+ parameters: "first",
+ },
+ // XXX: following line is used in eslint v4 to not throw an error when chaining methods
+ //MemberExpression: "off",
+ outerIIFEBody: 0,
+ }],
},
};
\ No newline at end of file
--- a/toolkit/components/satchel/AutoCompletePopup.jsm
+++ b/toolkit/components/satchel/AutoCompletePopup.jsm
@@ -12,18 +12,20 @@ Cu.import("resource://gre/modules/XPCOMU
Cu.import("resource://gre/modules/Services.jsm");
// AutoCompleteResultView is an abstraction around a list of results
// we got back up from browser-content.js. It implements enough of
// nsIAutoCompleteController and nsIAutoCompleteInput to make the
// richlistbox popup work.
var AutoCompleteResultView = {
// nsISupports
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIAutoCompleteController,
- Ci.nsIAutoCompleteInput]),
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsIAutoCompleteController,
+ Ci.nsIAutoCompleteInput
+ ]),
// Private variables
results: [],
// nsIAutoCompleteController
get matchCount() {
return this.results.length;
},
@@ -234,18 +236,22 @@ this.AutoCompletePopup = {
if (this.openedPopup) {
this.openedPopup.selectedIndex = index;
}
break;
}
case "FormAutoComplete:MaybeOpenPopup": {
let { results, rect, dir } = message.data;
- this.showPopupWithResults({ browser: message.target, rect, dir,
- results });
+ this.showPopupWithResults({
+ browser: message.target,
+ rect,
+ dir,
+ results
+ });
break;
}
case "FormAutoComplete:Invalidate": {
let { results } = message.data;
this.invalidate(results);
break;
}
@@ -290,18 +296,19 @@ this.AutoCompletePopup = {
* sends it a message. Otherwise, this is a no-op.
*
* @param {string} msgName
* The name of the message to send.
* @param {object} data
* The optional data to send with the message.
*/
sendMessageToBrowser(msgName, data) {
- let browser = this.weakBrowser ? this.weakBrowser.get()
- : null;
+ let browser = this.weakBrowser ?
+ this.weakBrowser.get() :
+ null;
if (browser) {
browser.messageManager.sendAsyncMessage(msgName, data);
}
},
stopSearch() {},
/**
--- a/toolkit/components/satchel/FormHistory.jsm
+++ b/toolkit/components/satchel/FormHistory.jsm
@@ -158,19 +158,19 @@ const dbSchema = {
"fieldname": "TEXT NOT NULL",
"value": "TEXT NOT NULL",
"timesUsed": "INTEGER",
"firstUsed": "INTEGER",
"lastUsed": "INTEGER",
"guid": "TEXT",
},
moz_deleted_formhistory: {
- "id": "INTEGER PRIMARY KEY",
- "timeDeleted": "INTEGER",
- "guid": "TEXT"
+ "id": "INTEGER PRIMARY KEY",
+ "timeDeleted": "INTEGER",
+ "guid": "TEXT"
}
},
indices: {
moz_formhistory_index: {
table: "moz_formhistory",
columns: [ "fieldname" ]
},
moz_formhistory_lastused_index: {
@@ -729,27 +729,26 @@ function updateFormHistoryWrite(aChanges
/**
* expireOldEntriesDeletion
*
* Removes entries from database.
*/
function expireOldEntriesDeletion(aExpireTime, aBeginningCount) {
log("expireOldEntriesDeletion(" + aExpireTime + "," + aBeginningCount + ")");
- FormHistory.update([
- {
- op: "remove",
- lastUsedEnd: aExpireTime,
- }], {
- handleCompletion() {
- expireOldEntriesVacuum(aExpireTime, aBeginningCount);
- },
- handleError(aError) {
- log("expireOldEntriesDeletionFailure");
- }
+ FormHistory.update([{
+ op: "remove",
+ lastUsedEnd: aExpireTime,
+ }], {
+ handleCompletion() {
+ expireOldEntriesVacuum(aExpireTime, aBeginningCount);
+ },
+ handleError(aError) {
+ log("expireOldEntriesDeletionFailure");
+ }
});
}
/**
* expireOldEntriesVacuum
*
* Counts number of entries removed and shrinks database as necessary.
*/
@@ -978,42 +977,42 @@ this.FormHistory = {
},
getAutoCompleteResults(searchString, params, aCallbacks) {
// only do substring matching when the search string contains more than one character
let searchTokens;
let where = ""
let boundaryCalc = "";
if (searchString.length > 1) {
- searchTokens = searchString.split(/\s+/);
+ searchTokens = searchString.split(/\s+/);
- // build up the word boundary and prefix match bonus calculation
- boundaryCalc = "MAX(1, :prefixWeight * (value LIKE :valuePrefix ESCAPE '/') + (";
- // for each word, calculate word boundary weights for the SELECT clause and
- // add word to the WHERE clause of the query
- let tokenCalc = [];
- let searchTokenCount = Math.min(searchTokens.length, MAX_SEARCH_TOKENS);
- for (let i = 0; i < searchTokenCount; i++) {
- tokenCalc.push("(value LIKE :tokenBegin" + i + " ESCAPE '/') + " +
+ // build up the word boundary and prefix match bonus calculation
+ boundaryCalc = "MAX(1, :prefixWeight * (value LIKE :valuePrefix ESCAPE '/') + (";
+ // for each word, calculate word boundary weights for the SELECT clause and
+ // add word to the WHERE clause of the query
+ let tokenCalc = [];
+ let searchTokenCount = Math.min(searchTokens.length, MAX_SEARCH_TOKENS);
+ for (let i = 0; i < searchTokenCount; i++) {
+ tokenCalc.push("(value LIKE :tokenBegin" + i + " ESCAPE '/') + " +
"(value LIKE :tokenBoundary" + i + " ESCAPE '/')");
- where += "AND (value LIKE :tokenContains" + i + " ESCAPE '/') ";
- }
- // add more weight if we have a traditional prefix match and
- // multiply boundary bonuses by boundary weight
- boundaryCalc += tokenCalc.join(" + ") + ") * :boundaryWeight)";
+ where += "AND (value LIKE :tokenContains" + i + " ESCAPE '/') ";
+ }
+ // add more weight if we have a traditional prefix match and
+ // multiply boundary bonuses by boundary weight
+ boundaryCalc += tokenCalc.join(" + ") + ") * :boundaryWeight)";
} else if (searchString.length == 1) {
- where = "AND (value LIKE :valuePrefix ESCAPE '/') ";
- boundaryCalc = "1";
- delete params.prefixWeight;
- delete params.boundaryWeight;
+ where = "AND (value LIKE :valuePrefix ESCAPE '/') ";
+ boundaryCalc = "1";
+ delete params.prefixWeight;
+ delete params.boundaryWeight;
} else {
- where = "";
- boundaryCalc = "1";
- delete params.prefixWeight;
- delete params.boundaryWeight;
+ where = "";
+ boundaryCalc = "1";
+ delete params.prefixWeight;
+ delete params.boundaryWeight;
}
params.now = Date.now() * 1000; // convert from ms to microseconds
/* Three factors in the frecency calculation for an entry (in order of use in calculation):
* 1) average number of times used - items used more are ranked higher
* 2) how recently it was last used - items used recently are ranked higher
* 3) additional weight for aged entries surviving expiry - these entries are relevant
--- a/toolkit/components/satchel/formSubmitListener.js
+++ b/toolkit/components/satchel/formSubmitListener.js
@@ -8,19 +8,21 @@
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
var satchelFormListener = {
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver,
- Ci.nsIObserver,
- Ci.nsISupportsWeakReference]),
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsIFormSubmitObserver,
+ Ci.nsIObserver,
+ Ci.nsISupportsWeakReference
+ ]),
debug: true,
enabled: true,
init() {
Services.obs.addObserver(this, "earlyformsubmit");
Services.obs.addObserver(this, "xpcom-shutdown");
Services.prefs.addObserver("browser.formfill.", this);
--- a/toolkit/components/satchel/nsFormAutoComplete.js
+++ b/toolkit/components/satchel/nsFormAutoComplete.js
@@ -194,18 +194,20 @@ FormAutoComplete.prototype = {
this._maxTimeGroupings = this._prefBranch.getIntPref("maxTimeGroupings");
this._timeGroupingSize = this._prefBranch.getIntPref("timeGroupingSize") * 1000 * 1000;
this._expireDays = this._prefBranch.getIntPref("expire_days");
},
observer: {
_self: null,
- QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
- Ci.nsISupportsWeakReference]),
+ QueryInterface: XPCOMUtils.generateQI([
+ Ci.nsIObserver,
+ Ci.nsISupportsWeakReference
+ ]),
observe(subject, topic, data) {
let self = this._self;
if (topic == "nsPref:changed") {
let prefName = data;
self.log("got change to " + prefName + " preference");
@@ -288,23 +290,21 @@ FormAutoComplete.prototype = {
}
if (typeof aUntrimmedSearchString === "object") {
aUntrimmedSearchString = "";
}
let client = new FormHistoryClient({ formField: aField, inputName: aInputName });
// If we have datalist results, they become our "empty" result.
- let emptyResult = aDatalistResult || new FormAutoCompleteResult(
- client,
- [],
- aInputName,
- aUntrimmedSearchString,
- null
- );
+ let emptyResult = aDatalistResult || new FormAutoCompleteResult(client,
+ [],
+ aInputName,
+ aUntrimmedSearchString,
+ null);
if (!this._enabled) {
if (aListener) {
aListener.onSearchCompletion(emptyResult);
}
return;
}
// don't allow form inputs (aField != null) to get results from search bar history
@@ -455,19 +455,23 @@ FormAutoComplete.prototype = {
// This is ugly: there are two FormAutoCompleteResult classes in the
// tree, one in a module and one in this file. Datalist results need to
// use the one defined in the module but the rest of this file assumes
// that we use the one defined here. To get around that, we explicitly
// import the module here, out of the way of the other uses of
// FormAutoCompleteResult.
let {FormAutoCompleteResult} = Cu.import("resource://gre/modules/nsFormAutoCompleteResult.jsm", {});
return new FormAutoCompleteResult(datalistResult.searchString,
- Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
- 0, "", finalValues, finalLabels,
- finalComments, historyResult);
+ Ci.nsIAutoCompleteResult.RESULT_SUCCESS,
+ 0,
+ "",
+ finalValues,
+ finalLabels,
+ finalComments,
+ historyResult);
},
stopAutoCompleteSearch() {
if (this._pendingClient) {
this._pendingClient.cancel();
this._pendingClient = null;
}
},
--- a/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
+++ b/toolkit/components/satchel/nsFormAutoCompleteResult.jsm
@@ -3,39 +3,33 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
this.EXPORTED_SYMBOLS = [ "FormAutoCompleteResult" ];
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-this.FormAutoCompleteResult =
- function FormAutoCompleteResult(searchString,
- searchResult,
- defaultIndex,
- errorDescription,
- values,
- labels,
- comments,
- prevResult) {
+this.FormAutoCompleteResult = function FormAutoCompleteResult(searchString,
+ searchResult,
+ defaultIndex,
+ errorDescription,
+ values,
+ labels,
+ comments,
+ prevResult) {
this.searchString = searchString;
this._searchResult = searchResult;
this._defaultIndex = defaultIndex;
this._errorDescription = errorDescription;
this._values = values;
this._labels = labels;
this._comments = comments;
this._formHistResult = prevResult;
-
- if (prevResult) {
- this.entries = prevResult.wrappedJSObject.entries;
- } else {
- this.entries = [];
- }
+ this.entries = prevResult ? prevResult.wrappedJSObject.entries : [];
}
FormAutoCompleteResult.prototype = {
// The user's query string
searchString: "",
// The result code of this result object, see |get searchResult| for possible values.
--- a/toolkit/components/satchel/nsInputListAutoComplete.js
+++ b/toolkit/components/satchel/nsInputListAutoComplete.js
@@ -11,23 +11,29 @@ Cu.import("resource://gre/modules/nsForm
function InputListAutoComplete() {}
InputListAutoComplete.prototype = {
classID: Components.ID("{bf1e01d0-953e-11df-981c-0800200c9a66}"),
QueryInterface: XPCOMUtils.generateQI([Ci.nsIInputListAutoComplete]),
autoCompleteSearch(aUntrimmedSearchString, aField) {
let [values, labels] = this.getListSuggestions(aField);
- let searchResult = values.length > 0 ? Ci.nsIAutoCompleteResult.RESULT_SUCCESS
- : Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
+ let searchResult = values.length > 0 ?
+ Ci.nsIAutoCompleteResult.RESULT_SUCCESS :
+ Ci.nsIAutoCompleteResult.RESULT_NOMATCH;
let defaultIndex = values.length > 0 ? 0 : -1;
return new FormAutoCompleteResult(aUntrimmedSearchString,
- searchResult, defaultIndex, "",
- values, labels, [], null);
+ searchResult,
+ defaultIndex,
+ "",
+ values,
+ labels,
+ [],
+ null);
},
getListSuggestions(aField) {
let values = [];
let labels = [];
if (!aField || !aField.list) {
return [values, labels];
}
--- a/toolkit/components/satchel/test/satchel_common.js
+++ b/toolkit/components/satchel/test/satchel_common.js
@@ -35,31 +35,31 @@ function $_(formNum, name) {
}
return element;
}
// 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];
+ var keyName = "DOM_VK_" + aKey.toUpperCase();
+ var key = SpecialPowers.Ci.nsIDOMKeyEvent[keyName];
- // undefined --> null
- if (!modifier) {
- modifier = null;
- }
+ // undefined --> null
+ if (!modifier) {
+ modifier = null;
+ }
- // Window utils for sending fake key events.
- var wutils = SpecialPowers.getDOMWindowUtils(window);
+ // 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);
+ if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
+ wutils.sendKeyEvent("keypress", key, 0, modifier);
+ }
+ wutils.sendKeyEvent("keyup", key, 0, modifier);
}
function registerPopupShownListener(listener) {
if (gPopupShownListener) {
ok(false, "got too many popupshownlisteners");
return;
}
gPopupShownListener = listener;
@@ -116,24 +116,24 @@ var checkObserver = {
// We don't actually check the content of the message, but just that the right
// quantity of messages is received.
// - if there are too few messages, test will time out
// - if there are too many messages, test will error out here
//
var expected = this.verifyStack.shift();
countEntries(expected.name, expected.value,
- function(num) {
- ok(num > 0, expected.message);
- if (checkObserver.verifyStack.length == 0) {
- var callback = checkObserver.callback;
- checkObserver.callback = null;
- callback();
- }
- });
+ function(num) {
+ ok(num > 0, expected.message);
+ if (checkObserver.verifyStack.length == 0) {
+ var callback = checkObserver.callback;
+ checkObserver.callback = null;
+ callback();
+ }
+ });
}
};
function checkForSave(name, value, message) {
checkObserver.verifyStack.push({ name, value, message });
}
function getFormSubmitButton(formNum) {
@@ -188,18 +188,18 @@ function updateFormHistory(changes, then
resolve();
});
});
}
function notifyMenuChanged(expectedCount, expectedFirstValue, then = null) {
return new Promise(resolve => {
gChromeScript.sendAsyncMessage("waitForMenuChange",
- { expectedCount,
- expectedFirstValue });
+ { expectedCount,
+ expectedFirstValue });
gChromeScript.addMessageListener("gotMenuChange", function changed({ results }) {
gChromeScript.removeMessageListener("gotMenuChange", changed);
gLastAutoCompleteResults = results;
if (then) {
then(results);
}
resolve(results);
});
--- a/toolkit/components/satchel/test/test_bug_511615.html
+++ b/toolkit/components/satchel/test/test_bug_511615.html
@@ -73,26 +73,26 @@ function checkSelectedIndexAfterResponse
});
}
function doKeyUnprivileged(key) {
let keyName = "DOM_VK_" + key.toUpperCase();
let keycode, charcode, alwaysval;
if (key.length == 1) {
- keycode = 0;
- charcode = key.charCodeAt(0);
- alwaysval = charcode;
+ keycode = 0;
+ charcode = key.charCodeAt(0);
+ alwaysval = charcode;
} else {
- keycode = KeyEvent[keyName];
- if (!keycode) {
- throw "invalid keyname in test";
- }
- charcode = 0;
- alwaysval = keycode;
+ keycode = KeyEvent[keyName];
+ 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");
/* eslint-disable no-multi-spaces */
dnEvent.initKeyEvent("keydown", true, true, null, false, false, false, false, alwaysval, 0);
--- a/toolkit/components/satchel/test/test_bug_787624.html
+++ b/toolkit/components/satchel/test/test_bug_787624.html
@@ -73,17 +73,17 @@ add_task(async function test_popup_not_m
let popupShown = waitForNextPopup();
input.focus();
doKey("down");
await popupShown;
var newRect = input.getBoundingClientRect();
is(newRect.left, rect.left,
- "autocomplete popup does not disturb the input position");
+ "autocomplete popup does not disturb the input position");
is(newRect.top, rect.top,
- "autocomplete popup does not disturb the input position");
+ "autocomplete popup does not disturb the input position");
});
</script>
</pre>
</body>
</html>
--- a/toolkit/components/satchel/test/test_form_autocomplete.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete.html
@@ -236,761 +236,761 @@ registerPopupShownListener(popupShownLis
*/
function runTest() { // eslint-disable-line complexity
testNum++;
ok(true, "Starting test #" + testNum);
switch (testNum) {
case 1:
- // Make sure initial form is empty.
- checkForm("");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Make sure initial form is empty.
+ checkForm("");
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 2:
- checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
- // Check first entry
- doKey("down");
- checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
- checkForm("value1");
+ checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
+ // Check first entry
+ doKey("down");
+ checkForm(""); // value shouldn't update
+ doKey("return"); // not "enter"!
+ checkForm("value1");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 3:
- // Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
- checkForm("value2");
+ // Check second entry
+ doKey("down");
+ doKey("down");
+ doKey("return"); // not "enter"!
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 4:
- // Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("value3");
+ // Check third entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("value3");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 5:
- // Check fourth entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("value4");
+ // Check fourth entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("value4");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 6:
- // Check first entry (wraparound)
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down"); // deselects
- doKey("down");
- doKey("return");
- checkForm("value1");
+ // Check first entry (wraparound)
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("down"); // deselects
+ doKey("down");
+ doKey("return");
+ checkForm("value1");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 7:
- // Check the last entry via arrow-up
- doKey("up");
- doKey("return");
- checkForm("value4");
+ // Check the last entry via arrow-up
+ doKey("up");
+ doKey("return");
+ checkForm("value4");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 8:
- // Check the last entry via arrow-up
- doKey("down"); // select first entry
- doKey("up"); // selects nothing!
- doKey("up"); // select last entry
- doKey("return");
- checkForm("value4");
+ // Check the last entry via arrow-up
+ doKey("down"); // select first entry
+ doKey("up"); // selects nothing!
+ doKey("up"); // select last entry
+ doKey("return");
+ checkForm("value4");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 9:
- // Check the last entry via arrow-up (wraparound)
- doKey("down");
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("up");
- doKey("up");
- doKey("up"); // first entry
- doKey("up"); // deselects
- doKey("up"); // last entry
- doKey("return");
- checkForm("value4");
+ // Check the last entry via arrow-up (wraparound)
+ doKey("down");
+ doKey("up"); // deselects
+ doKey("up"); // last entry
+ doKey("up");
+ doKey("up");
+ doKey("up"); // first entry
+ doKey("up"); // deselects
+ doKey("up"); // last entry
+ doKey("return");
+ checkForm("value4");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 10:
- // Set first entry w/o triggering autocomplete
- doKey("down");
- doKey("right");
- checkForm("value1");
+ // Set first entry w/o triggering autocomplete
+ doKey("down");
+ doKey("right");
+ checkForm("value1");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 11:
- // Set first entry w/o triggering autocomplete
- doKey("down");
- doKey("left");
- checkForm("value1");
+ // Set first entry w/o triggering autocomplete
+ doKey("down");
+ doKey("left");
+ checkForm("value1");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 12:
- // Check first entry (page up)
- doKey("down");
- doKey("down");
- doKey("page_up");
- doKey("return");
- checkForm("value1");
+ // Check first entry (page up)
+ doKey("down");
+ doKey("down");
+ doKey("page_up");
+ doKey("return");
+ checkForm("value1");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 13:
- // Check last entry (page down)
- doKey("down");
- doKey("page_down");
- doKey("return");
- checkForm("value4");
+ // Check last entry (page down)
+ doKey("down");
+ doKey("page_down");
+ doKey("return");
+ checkForm("value4");
- // Trigger autocomplete popup
- testNum = 49;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ testNum = 49;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
/* Test removing entries from the dropdown */
case 50:
- checkMenuEntries(["value1", "value2", "value3", "value4"], testNum);
- // Delete the first entry (of 4)
- setForm("value");
- doKey("down");
+ 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);
- }
+ // 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);
+ }
- // This tests that on OS X shift-backspace didn't delete the last character
- // in the input (bug 480262).
- waitForMenuChange(3);
- break;
+ // 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");
- countEntries("field1", "value1",
- function(num) {
- ok(!num, testNum + " checking that f1/v1 was deleted");
- runTest();
- });
- break;
+ checkForm("value");
+ countEntries("field1", "value1",
+ function(num) {
+ ok(!num, testNum + " checking that f1/v1 was deleted");
+ runTest();
+ });
+ break;
case 52:
- doKey("return");
- checkForm("value2");
+ doKey("return");
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 53:
- checkMenuEntries(["value2", "value3", "value4"], testNum);
- // Check the new first entry (of 3)
- doKey("down");
- doKey("return");
- checkForm("value2");
+ checkMenuEntries(["value2", "value3", "value4"], testNum);
+ // Check the new first entry (of 3)
+ doKey("down");
+ doKey("return");
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 54:
- // Delete the second entry (of 3)
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
- waitForMenuChange(2);
- break;
+ // Delete the second entry (of 3)
+ doKey("down");
+ doKey("down");
+ doKey("delete", shiftModifier);
+ waitForMenuChange(2);
+ break;
case 55:
- checkForm("");
- countEntries("field1", "value3",
- function(num) {
- ok(!num, testNum + " checking that f1/v3 was deleted");
- runTest();
- });
- break;
+ checkForm("");
+ countEntries("field1", "value3",
+ function(num) {
+ ok(!num, testNum + " checking that f1/v3 was deleted");
+ runTest();
+ });
+ break;
case 56:
- doKey("return");
- checkForm("value4")
+ doKey("return");
+ checkForm("value4")
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 57:
- checkMenuEntries(["value2", "value4"], testNum);
- // Check the new first entry (of 2)
- doKey("down");
- doKey("return");
- checkForm("value2");
+ checkMenuEntries(["value2", "value4"], testNum);
+ // Check the new first entry (of 2)
+ doKey("down");
+ doKey("return");
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 58:
- // Delete the last entry (of 2)
- doKey("down");
- doKey("down");
- doKey("delete", shiftModifier);
- checkForm("");
- waitForMenuChange(1);
- break;
+ // Delete the last entry (of 2)
+ doKey("down");
+ doKey("down");
+ doKey("delete", shiftModifier);
+ checkForm("");
+ waitForMenuChange(1);
+ break;
case 59:
- countEntries("field1", "value4",
- function(num) {
- ok(!num, testNum + " checking that f1/v4 was deleted");
- runTest();
- });
- break;
+ countEntries("field1", "value4",
+ function(num) {
+ ok(!num, testNum + " checking that f1/v4 was deleted");
+ runTest();
+ });
+ break;
case 60:
- doKey("return");
- checkForm("value2");
+ doKey("return");
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 61:
- checkMenuEntries(["value2"], testNum);
- // Check the new first entry (of 1)
- doKey("down");
- doKey("return");
- checkForm("value2");
+ checkMenuEntries(["value2"], testNum);
+ // Check the new first entry (of 1)
+ doKey("down");
+ doKey("return");
+ checkForm("value2");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 62:
- // Delete the only remaining entry
- doKey("down");
- doKey("delete", shiftModifier);
- waitForMenuChange(0);
- break;
+ // Delete the only remaining entry
+ doKey("down");
+ doKey("delete", shiftModifier);
+ waitForMenuChange(0);
+ break;
case 63:
- checkForm("");
- countEntries("field1", "value2",
- function(num) {
- ok(!num, testNum + " checking that f1/v2 was deleted");
- runTest();
- });
- break;
+ checkForm("");
+ countEntries("field1", "value2",
+ function(num) {
+ ok(!num, testNum + " checking that f1/v2 was deleted");
+ runTest();
+ });
+ break;
case 64:
- // Look at form 2, trigger autocomplete popup
- input = $_(2, "field2");
- testNum = 99;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Look at form 2, trigger autocomplete popup
+ input = $_(2, "field2");
+ testNum = 99;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
/* Test entries with autocomplete=off */
case 100:
- // Select first entry
- doKey("down");
- doKey("return");
- checkForm("value1");
+ // Select first entry
+ doKey("down");
+ doKey("return");
+ checkForm("value1");
- // Look at form 3, try to trigger autocomplete popup
- input = $_(3, "field2");
- restoreForm();
- // Sometimes, this will fail if scrollTo(0, 0) is called, so that doesn't
- // happen here. Fortunately, a different input is used from the last test,
- // so a scroll should still occur.
- doKey("down");
- waitForScroll();
- break;
+ // Look at form 3, try to trigger autocomplete popup
+ input = $_(3, "field2");
+ restoreForm();
+ // Sometimes, this will fail if scrollTo(0, 0) is called, so that doesn't
+ // happen here. Fortunately, a different input is used from the last test,
+ // so a scroll should still occur.
+ doKey("down");
+ waitForScroll();
+ break;
case 101:
- // Ensure there's no autocomplete dropdown (autocomplete=off is present)
- doKey("down");
- doKey("return");
- checkForm("");
+ // Ensure there's no autocomplete dropdown (autocomplete=off is present)
+ doKey("down");
+ doKey("return");
+ checkForm("");
- // Look at form 4, try to trigger autocomplete popup
- input = $_(4, "field2");
- restoreForm();
- doKey("down");
- waitForMenuChange(0);
- break;
+ // Look at form 4, try to trigger autocomplete popup
+ input = $_(4, "field2");
+ restoreForm();
+ doKey("down");
+ waitForMenuChange(0);
+ break;
case 102:
- // Ensure there's no autocomplete dropdown (autocomplete=off is present)
- doKey("down");
- doKey("return");
- checkForm("");
+ // Ensure there's no autocomplete dropdown (autocomplete=off is present)
+ doKey("down");
+ doKey("return");
+ checkForm("");
- // Look at form 5, try to trigger autocomplete popup
- input = $_(5, "field3");
- restoreForm();
- testNum = 199;
- expectPopup();
- input.focus();
- sendChar("a");
- break;
+ // Look at form 5, try to trigger autocomplete popup
+ input = $_(5, "field3");
+ restoreForm();
+ testNum = 199;
+ expectPopup();
+ input.focus();
+ sendChar("a");
+ break;
/* Test filtering as characters are typed. */
case 200:
- checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum);
- input.focus();
- sendChar("a");
- waitForMenuChange(3);
- break;
+ checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum);
+ input.focus();
+ sendChar("a");
+ waitForMenuChange(3);
+ break;
case 201:
- checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
- input.focus();
- sendChar("\xc6");
- waitForMenuChange(1);
- break;
+ checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
+ input.focus();
+ sendChar("\xc6");
+ waitForMenuChange(1);
+ break;
case 202:
- checkMenuEntries(["aa\xe6"], testNum);
- doKey("back_space");
- waitForMenuChange(3);
- break;
+ checkMenuEntries(["aa\xe6"], testNum);
+ doKey("back_space");
+ waitForMenuChange(3);
+ break;
case 203:
- checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
- doKey("back_space");
- waitForMenuChange(5);
- break;
+ checkMenuEntries(["aa", "aaz", "aa\xe6"], testNum);
+ doKey("back_space");
+ waitForMenuChange(5);
+ break;
case 204:
- checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum);
- input.focus();
- sendChar("z");
- waitForMenuChange(2);
- break;
+ checkMenuEntries(["a", "aa", "aaz", "aa\xe6", "az"], testNum);
+ input.focus();
+ sendChar("z");
+ waitForMenuChange(2);
+ break;
case 205:
- checkMenuEntries(["az", "aaz"], testNum);
- input.focus();
- doKey("left");
- expectPopup();
- // Check case-insensitivity.
- sendChar("A");
- break;
+ checkMenuEntries(["az", "aaz"], testNum);
+ input.focus();
+ doKey("left");
+ expectPopup();
+ // Check case-insensitivity.
+ sendChar("A");
+ break;
case 206:
- checkMenuEntries(["aaz"], testNum);
- addEntry("field3", "aazq");
- break;
+ checkMenuEntries(["aaz"], testNum);
+ addEntry("field3", "aazq");
+ break;
case 207:
- // check that results were cached
- input.focus();
- doKey("right");
- sendChar("q");
- waitForMenuChange(0);
- break;
+ // check that results were cached
+ input.focus();
+ doKey("right");
+ sendChar("q");
+ waitForMenuChange(0);
+ break;
case 208:
- // check that results were cached
- checkMenuEntries([], testNum);
- addEntry("field3", "aazqq");
- break;
+ // check that results were cached
+ checkMenuEntries([], testNum);
+ addEntry("field3", "aazqq");
+ break;
case 209:
- input.focus();
- window.scrollTo(0, 0);
- sendChar("q");
- waitForMenuChange(0);
- break;
+ input.focus();
+ window.scrollTo(0, 0);
+ sendChar("q");
+ waitForMenuChange(0);
+ break;
case 210:
- // check that empty results were cached - bug 496466
- checkMenuEntries([], testNum);
- doKey("escape");
+ // check that empty results were cached - bug 496466
+ checkMenuEntries([], testNum);
+ doKey("escape");
- // Look at form 6, try to trigger autocomplete popup
- input = $_(6, "field4");
- restoreForm();
- testNum = 249;
- expectPopup();
- input.focus();
- sendChar("a");
- break;
+ // Look at form 6, try to trigger autocomplete popup
+ input = $_(6, "field4");
+ restoreForm();
+ testNum = 249;
+ expectPopup();
+ input.focus();
+ sendChar("a");
+ break;
/* Test substring matches and word boundary bonuses */
case 250:
- // alphabetical results for first character
- checkMenuEntries(["aa a\xe6", "aba\xe6", "a\xe6"], testNum);
- input.focus();
+ // alphabetical results for first character
+ checkMenuEntries(["aa a\xe6", "aba\xe6", "a\xe6"], testNum);
+ input.focus();
- sendChar("\xe6");
- waitForMenuChange(3, "a\xe6");
- break;
+ sendChar("\xe6");
+ waitForMenuChange(3, "a\xe6");
+ break;
case 251:
- // prefix match comes first, then word boundary match
- // followed by substring match
- checkMenuEntries(["a\xe6", "aa a\xe6", "aba\xe6"], testNum);
+ // prefix match comes first, then word boundary match
+ // followed by substring match
+ checkMenuEntries(["a\xe6", "aa a\xe6", "aba\xe6"], testNum);
- restoreForm();
- input.focus();
- sendChar("b");
- waitForMenuChange(1, "bc d\xe6");
- break;
+ restoreForm();
+ input.focus();
+ sendChar("b");
+ waitForMenuChange(1, "bc d\xe6");
+ break;
case 252:
- checkMenuEntries(["bc d\xe6"], testNum);
- input.focus();
- sendChar(" ");
- waitForMenuChange(1);
- break;
+ checkMenuEntries(["bc d\xe6"], testNum);
+ input.focus();
+ sendChar(" ");
+ waitForMenuChange(1);
+ break;
case 253:
- // check that trailing space has no effect after single char.
- checkMenuEntries(["bc d\xe6"], testNum);
- input.focus();
- sendChar("\xc6");
- waitForMenuChange(2);
- break;
+ // check that trailing space has no effect after single char.
+ checkMenuEntries(["bc d\xe6"], testNum);
+ input.focus();
+ sendChar("\xc6");
+ waitForMenuChange(2);
+ break;
case 254:
- // check multi-word substring matches
- checkMenuEntries(["bc d\xe6", "aba\xe6"]);
- input.focus();
- expectPopup();
- doKey("left");
- sendChar("d");
- break;
+ // check multi-word substring matches
+ checkMenuEntries(["bc d\xe6", "aba\xe6"]);
+ input.focus();
+ expectPopup();
+ doKey("left");
+ sendChar("d");
+ break;
case 255:
- // check inserting in multi-word searches
- checkMenuEntries(["bc d\xe6"], testNum);
- input.focus();
- sendChar("z");
- waitForMenuChange(0);
- break;
+ // check inserting in multi-word searches
+ checkMenuEntries(["bc d\xe6"], testNum);
+ input.focus();
+ sendChar("z");
+ waitForMenuChange(0);
+ break;
case 256:
- checkMenuEntries([], testNum);
+ checkMenuEntries([], testNum);
- // Look at form 7, try to trigger autocomplete popup
- input = $_(7, "field5");
- testNum = 299;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Look at form 7, try to trigger autocomplete popup
+ input = $_(7, "field5");
+ testNum = 299;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 300:
- checkMenuEntries(["1", "12", "123", "1234"], testNum);
- input.maxLength = 4;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12", "123", "1234"], testNum);
+ input.maxLength = 4;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 301:
- checkMenuEntries(["1", "12", "123", "1234"], testNum);
- input.maxLength = 3;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12", "123", "1234"], testNum);
+ input.maxLength = 3;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 302:
- checkMenuEntries(["1", "12", "123"], testNum);
- input.maxLength = 2;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12", "123"], testNum);
+ input.maxLength = 2;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 303:
- checkMenuEntries(["1", "12"], testNum);
- input.maxLength = 1;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12"], testNum);
+ input.maxLength = 1;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 304:
- checkMenuEntries(["1"], testNum);
- input.maxLength = 0;
- doKey("escape");
- doKey("down");
- waitForMenuChange(0);
- break;
+ checkMenuEntries(["1"], testNum);
+ input.maxLength = 0;
+ doKey("escape");
+ doKey("down");
+ waitForMenuChange(0);
+ break;
case 305:
- checkMenuEntries([], testNum);
- input.maxLength = 4;
+ checkMenuEntries([], testNum);
+ input.maxLength = 4;
- // now again with a character typed
- input.focus();
- sendChar("1");
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ // now again with a character typed
+ input.focus();
+ sendChar("1");
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 306:
- checkMenuEntries(["1", "12", "123", "1234"], testNum);
- input.maxLength = 3;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12", "123", "1234"], testNum);
+ input.maxLength = 3;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 307:
- checkMenuEntries(["1", "12", "123"], testNum);
- input.maxLength = 2;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12", "123"], testNum);
+ input.maxLength = 2;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 308:
- checkMenuEntries(["1", "12"], testNum);
- input.maxLength = 1;
- expectPopup();
- doKey("escape");
- doKey("down");
- break;
+ checkMenuEntries(["1", "12"], testNum);
+ input.maxLength = 1;
+ expectPopup();
+ doKey("escape");
+ doKey("down");
+ break;
case 309:
- checkMenuEntries(["1"], testNum);
- input.maxLength = 0;
- doKey("escape");
- doKey("down");
- waitForMenuChange(0);
- break;
+ checkMenuEntries(["1"], testNum);
+ input.maxLength = 0;
+ doKey("escape");
+ doKey("down");
+ waitForMenuChange(0);
+ break;
case 310:
- checkMenuEntries([], testNum);
+ checkMenuEntries([], testNum);
- input = $_(8, "field6");
- testNum = 399;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ input = $_(8, "field6");
+ testNum = 399;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 400:
case 401:
case 402:
case 403:
- checkMenuEntries(["value"], testNum);
- doKey("down");
- doKey("return");
- checkForm("value");
+ checkMenuEntries(["value"], testNum);
+ doKey("down");
+ doKey("return");
+ checkForm("value");
- if (testNum == 400) {
- input = $_(9, "field7");
- } else if (testNum == 401) {
- input = $_(10, "field8");
- } else if (testNum == 402) {
- input = $_(11, "field9");
- } else if (testNum == 403) {
- todo(false, "Fix input type=number");
- input = $_(12, "field10");
- }
+ if (testNum == 400) {
+ input = $_(9, "field7");
+ } else if (testNum == 401) {
+ input = $_(10, "field8");
+ } else if (testNum == 402) {
+ input = $_(11, "field9");
+ } else if (testNum == 403) {
+ todo(false, "Fix input type=number");
+ input = $_(12, "field10");
+ }
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 404:
- checkMenuEntries(["42"], testNum);
- doKey("down");
- doKey("return");
- checkForm("42");
+ checkMenuEntries(["42"], testNum);
+ doKey("down");
+ doKey("return");
+ checkForm("42");
- input = $_(14, "field11");
- restoreForm();
- waitForMenuChange(0);
- break;
+ input = $_(14, "field11");
+ restoreForm();
+ waitForMenuChange(0);
+ break;
case 405:
- checkMenuEntries([]); // type=date with it's own control frame does not
- // have a drop down menu for now
- checkForm("");
+ checkMenuEntries([]); // type=date with it's own control frame does not
+ // have a drop down menu for now
+ checkForm("");
- input = $_(15, "field12");
- restoreForm();
- waitForMenuChange(0);
- break;
+ input = $_(15, "field12");
+ restoreForm();
+ waitForMenuChange(0);
+ break;
case 406:
- checkMenuEntries([]); // type=time with it's own control frame does not
- // have a drop down menu for now
- checkForm("");
+ checkMenuEntries([]); // type=time with it's own control frame does not
+ // have a drop down menu for now
+ checkForm("");
- input = $_(16, "field13");
- restoreForm();
- doKey("down");
- waitForMenuChange(0);
- break;
+ input = $_(16, "field13");
+ restoreForm();
+ doKey("down");
+ waitForMenuChange(0);
+ break;
case 407:
- checkMenuEntries([]); // type=range does not have a drop down menu
- doKey("down");
- doKey("return");
- checkForm("30"); // default (midway between minimum (0) and maximum (64)) - step
+ checkMenuEntries([]); // type=range does not have a drop down menu
+ doKey("down");
+ doKey("return");
+ checkForm("30"); // default (midway between minimum (0) and maximum (64)) - step
- input = $_(17, "field14");
- restoreForm();
- waitForMenuChange(0);
- break;
+ input = $_(17, "field14");
+ restoreForm();
+ waitForMenuChange(0);
+ break;
case 408:
- checkMenuEntries([]); // type=color does not have a drop down menu
- checkForm("#000000"); // default color value
+ checkMenuEntries([]); // type=color does not have a drop down menu
+ checkForm("#000000"); // default color value
- input = $_(18, "field15");
- restoreForm();
- expectPopup();
- doKey("down");
- break;
+ input = $_(18, "field15");
+ restoreForm();
+ expectPopup();
+ doKey("down");
+ break;
case 409:
- checkMenuEntries(["2016-08"]);
- doKey("down");
- doKey("return");
- checkForm("2016-08");
+ checkMenuEntries(["2016-08"]);
+ doKey("down");
+ doKey("return");
+ checkForm("2016-08");
- input = $_(19, "field16");
- restoreForm();
- expectPopup();
- doKey("down");
- break;
+ input = $_(19, "field16");
+ restoreForm();
+ expectPopup();
+ doKey("down");
+ break;
case 410:
- checkMenuEntries(["2016-W32"]);
- doKey("down");
- doKey("return");
- checkForm("2016-W32");
+ checkMenuEntries(["2016-W32"]);
+ doKey("down");
+ doKey("return");
+ checkForm("2016-W32");
- input = $_(20, "field17");
- restoreForm();
- expectPopup();
- doKey("down");
- break;
+ input = $_(20, "field17");
+ restoreForm();
+ expectPopup();
+ doKey("down");
+ break;
case 411:
- checkMenuEntries(["2016-10-21T10:10"]);
- doKey("down");
- doKey("return");
- checkForm("2016-10-21T10:10");
+ checkMenuEntries(["2016-10-21T10:10"]);
+ doKey("down");
+ doKey("return");
+ checkForm("2016-10-21T10:10");
- addEntry("field1", "value1");
- break;
+ addEntry("field1", "value1");
+ break;
case 412:
- input = $_(1, "field1");
- // Go to test 500.
- testNum = 499;
+ input = $_(1, "field1");
+ // Go to test 500.
+ testNum = 499;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
// Check that the input event is fired.
case 500:
input.addEventListener("input", function(event) {
ok(true, testNum + " oninput should have been received");
ok(event.bubbles, testNum + " input event should bubble");
ok(event.cancelable, testNum + " input event should be cancelable");
}, {once: true});
@@ -999,70 +999,70 @@ function runTest() { // eslint-disable-l
checkForm("");
doKey("return");
checkForm("value1");
testNum = 599;
setTimeout(runTest, 100);
break;
case 600:
- // check we don't show autocomplete for searchbar-history
- input = $_(13, "searchbar-history");
+ // check we don't show autocomplete for searchbar-history
+ input = $_(13, "searchbar-history");
- // Trigger autocomplete popup
- checkForm("");
- restoreForm();
- doKey("down");
- waitForMenuChange(0);
- break;
+ // Trigger autocomplete popup
+ checkForm("");
+ restoreForm();
+ doKey("down");
+ waitForMenuChange(0);
+ break;
case 601:
- checkMenuEntries([], testNum);
- input.blur();
- SimpleTest.finish();
- return;
+ checkMenuEntries([], testNum);
+ input.blur();
+ SimpleTest.finish();
+ return;
default:
- ok(false, "Unexpected invocation of test #" + testNum);
- SimpleTest.finish();
+ ok(false, "Unexpected invocation of test #" + testNum);
+ SimpleTest.finish();
}
}
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;
+ return;
}
removeEventListener("scroll", arguments.callee, false);
setTimeout(runTest, 100);
}, false);
}
function waitForMenuChange(expectedCount, expectedFirstValue) {
- notifyMenuChanged(expectedCount, expectedFirstValue, runTest);
+ 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++) {
- is(actualValues[i], expectedValues[i], testNumber + " Checking menu entry #" + i);
- }
+ 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);
+ }
}
function startTest() {
- setupFormHistory(function() {
- runTest();
- });
+ setupFormHistory(function() {
+ runTest();
+ });
}
window.onload = startTest;
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");
</script>
</pre>
--- a/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
+++ b/toolkit/components/satchel/test/test_form_autocomplete_with_list.html
@@ -53,29 +53,29 @@ function setupFormHistory(aCallback) {
updateFormHistory([
{ op: "remove" },
{ op: "add", fieldname: "field1", value: "historyvalue" },
{ op: "add", fieldname: "field2", value: "othervalue" },
], aCallback);
}
function setForm(value) {
- input.value = value;
- input.focus();
+ input.value = value;
+ input.focus();
}
// Restore the form to the default state.
function restoreForm() {
- setForm("");
+ setForm("");
}
// Check for expected form data.
function checkForm(expectedValue) {
- var formID = input.parentNode.id;
- is(input.value, expectedValue, "Checking " + formID + " input");
+ var formID = input.parentNode.id;
+ is(input.value, expectedValue, "Checking " + formID + " input");
}
var testNum = 0;
var prevValue;
var expectingPopup = false;
function expectPopup() {
info("expecting popup for test " + testNum);
@@ -98,230 +98,230 @@ registerPopupShownListener(popupShownLis
* Main section of test...
*
* This is a bit hacky, as many operations happen asynchronously.
* Various mechanisms call runTests as a result of operations:
* - set expectingPopup to true, and the next test will occur when the autocomplete popup is shown
* - call waitForMenuChange(x) to run the next test when the autocomplete popup to have x items in it
*/
function runTest() {
- testNum++;
+ testNum++;
- info("Starting test #" + testNum);
+ info("Starting test #" + testNum);
- switch (testNum) {
+ switch (testNum) {
case 1:
- // Make sure initial form is empty.
- checkForm("");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Make sure initial form is empty.
+ checkForm("");
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 2:
- checkMenuEntries(["historyvalue", "PASS1", "PASS2", "final"], testNum);
- // Check first entry
- doKey("down");
- checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
- checkForm("historyvalue");
+ checkMenuEntries(["historyvalue", "PASS1", "PASS2", "final"], testNum);
+ // Check first entry
+ doKey("down");
+ checkForm(""); // value shouldn't update
+ doKey("return"); // not "enter"!
+ checkForm("historyvalue");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 3:
- // Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
- checkForm("Google");
+ // Check second entry
+ doKey("down");
+ doKey("down");
+ doKey("return"); // not "enter"!
+ checkForm("Google");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 4:
- // Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("Reddit");
+ // Check third entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("Reddit");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 5:
- // Check fourth entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("final");
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Check fourth entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("final");
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 6:
- // Delete the first entry (of 3)
- doKey("down");
- doKey("delete", shiftModifier);
- waitForMenuChange(3);
- break;
+ // Delete the first entry (of 3)
+ doKey("down");
+ doKey("delete", shiftModifier);
+ waitForMenuChange(3);
+ break;
case 7:
- checkForm("");
- countEntries("field1", "historyvalue",
- function(num) {
- ok(!num, testNum + " checking that form history value was deleted");
- runTest();
- });
- break;
+ checkForm("");
+ countEntries("field1", "historyvalue",
+ function(num) {
+ ok(!num, testNum + " checking that form history value was deleted");
+ runTest();
+ });
+ break;
case 8:
- doKey("return");
- checkForm("Google")
+ doKey("return");
+ checkForm("Google")
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 9:
- // Test deletion
- checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
- // Check the new first entry (of 3)
- doKey("down");
- doKey("return");
- checkForm("Google");
+ // Test deletion
+ checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
+ // Check the new first entry (of 3)
+ doKey("down");
+ doKey("return");
+ checkForm("Google");
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 10:
- // Test autocompletion of datalists with cached results.
- sendString("PAS");
- waitForMenuChange(2);
- break;
+ // Test autocompletion of datalists with cached results.
+ sendString("PAS");
+ waitForMenuChange(2);
+ break;
case 11:
- // Continuation of test 10
- sendString("S1");
- waitForMenuChange(1);
- break;
+ // Continuation of test 10
+ sendString("S1");
+ waitForMenuChange(1);
+ break;
case 12:
- doKey("down");
- doKey("return");
- checkForm("Google");
+ doKey("down");
+ doKey("return");
+ checkForm("Google");
- // Trigger autocomplete popup
- // Look at form 3, try to trigger autocomplete popup
- input.value = "";
- input = $_(3, "field2");
- testNum = 99;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ // Look at form 3, try to trigger autocomplete popup
+ input.value = "";
+ input = $_(3, "field2");
+ testNum = 99;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 100:
- checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
- // Check first entry
- doKey("down");
- checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
- checkForm("Google");
+ checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
+ // Check first entry
+ doKey("down");
+ checkForm(""); // value shouldn't update
+ doKey("return"); // not "enter"!
+ checkForm("Google");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 101:
- // Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
- checkForm("Reddit");
+ // Check second entry
+ doKey("down");
+ doKey("down");
+ doKey("return"); // not "enter"!
+ checkForm("Reddit");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 102:
- // Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("final");
+ // Check third entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("final");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 103:
- checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
- // Check first entry
- doKey("down");
- checkForm(""); // value shouldn't update
- doKey("return"); // not "enter"!
- checkForm("Google");
+ checkMenuEntries(["PASS1", "PASS2", "final"], testNum);
+ // Check first entry
+ doKey("down");
+ checkForm(""); // value shouldn't update
+ doKey("return"); // not "enter"!
+ checkForm("Google");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 104:
- // Check second entry
- doKey("down");
- doKey("down");
- doKey("return"); // not "enter"!
- checkForm("Reddit");
+ // Check second entry
+ doKey("down");
+ doKey("down");
+ doKey("return"); // not "enter"!
+ checkForm("Reddit");
- // Trigger autocomplete popup
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ // Trigger autocomplete popup
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
case 105:
- // Check third entry
- doKey("down");
- doKey("down");
- doKey("down");
- doKey("return");
- checkForm("final");
+ // Check third entry
+ doKey("down");
+ doKey("down");
+ doKey("down");
+ doKey("return");
+ checkForm("final");
- testNum = 199;
- expectPopup();
- restoreForm();
- doKey("down");
- break;
+ testNum = 199;
+ expectPopup();
+ restoreForm();
+ doKey("down");
+ break;
// Test dynamic updates.
// For some reasons, when there is an update of the list, the selection is
// lost so we need to go down like if we were at the beginning of the list
// again.
case 200:
// Removing the second element while on the first then going down and
// push enter. Value should be one from the third suggesion.
@@ -473,33 +473,33 @@ function runTest() {
doKey("down");
checkForm("");
doKey("return");
break;
default:
ok(false, "Unexpected invocation of test #" + testNum);
SimpleTest.finish();
- }
+ }
}
function waitForMenuChange(expectedCount) {
- notifyMenuChanged(expectedCount, null, runTest);
+ 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);
- }
+ 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);
+ }
}
function startTest() {
- setupFormHistory(runTest);
+ setupFormHistory(runTest);
}
window.onload = startTest;
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
--- a/toolkit/components/satchel/test/test_form_submission.html
+++ b/toolkit/components/satchel/test/test_form_submission.html
@@ -272,20 +272,20 @@ var ccNumbers = {
"6723210018630429", "4411962856225025",
"8276996369036686", "4449796938248871",
"3350852696538147", "5011802870046957"
],
};
function checkInitialState() {
countEntries(null, null,
- function(num) {
- ok(!num, "checking for initially empty storage");
- startTest();
- });
+ function(num) {
+ ok(!num, "checking for initially empty storage");
+ startTest();
+ });
}
function startTest() {
// Fill in values for the various fields. We could just set the <input>'s
// value attribute, but we don't save default form values (and we want to
// ensure unsaved values are because of autocomplete=off or whatever).
$_(1, "test1").value = "dontSaveThis";
$_(2, "test1").value = "dontSaveThis";
@@ -374,58 +374,58 @@ function checkSubmit(formNum) {
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
countEntries(null, null,
- function(num) {
- ok(!num, "checking for empty storage");
- submitForm(formNum);
- });
- return false;
+ function(num) {
+ ok(!num, "checking for empty storage");
+ submitForm(formNum);
+ });
+ return false;
case 100:
- checkForSave("subtest2", "subtestValue", "checking saved subtest value");
- break;
+ checkForSave("subtest2", "subtestValue", "checking saved subtest value");
+ break;
case 101:
- checkForSave("test1", "savedValue", "checking saved value");
- break;
+ checkForSave("test1", "savedValue", "checking saved value");
+ break;
case 102:
- checkForSave("test2", "savedValue", "checking saved value");
- break;
+ checkForSave("test2", "savedValue", "checking saved value");
+ break;
case 103:
- checkForSave("test3", "savedValue", "checking saved value");
- break;
+ checkForSave("test3", "savedValue", "checking saved value");
+ break;
case 104:
- checkForSave("test4", "trimTrailingAndLeadingSpace", "checking saved value is trimmed on both sides");
- break;
+ checkForSave("test4", "trimTrailingAndLeadingSpace", "checking saved value is trimmed on both sides");
+ break;
case 105:
- checkForSave("test5", "trimTrailingAndLeadingWhitespace", "checking saved value is trimmed on both sides");
- break;
+ checkForSave("test5", "trimTrailingAndLeadingWhitespace", "checking saved value is trimmed on both sides");
+ break;
case 106:
- checkForSave("test6", "00000000109181", "checking saved value");
- break;
+ checkForSave("test6", "00000000109181", "checking saved value");
+ break;
case 107:
- for (let i = 0; i != ccNumbers.invalid16.length; i++) {
- checkForSave("test7_" + (i + 1), ccNumbers.invalid16[i], "checking saved value");
- }
- break;
+ for (let i = 0; i != ccNumbers.invalid16.length; i++) {
+ checkForSave("test7_" + (i + 1), ccNumbers.invalid16[i], "checking saved value");
+ }
+ break;
case 108:
- for (let i = 0; i != ccNumbers.invalid15.length; i++) {
- checkForSave("test8_" + (i + 1), ccNumbers.invalid15[i], "checking saved value");
- }
- break;
+ for (let i = 0; i != ccNumbers.invalid15.length; i++) {
+ checkForSave("test8_" + (i + 1), ccNumbers.invalid15[i], "checking saved value");
+ }
+ break;
case 109:
- checkForSave("test9", "savedValue", "checking saved value");
- break;
+ checkForSave("test9", "savedValue", "checking saved value");
+ break;
default:
- ok(false, "Unexpected form submission");
- break;
+ ok(false, "Unexpected form submission");
+ break;
}
return submitForm(formNum);
}
function submitForm(formNum) {
// End the test now on SeaMonkey.
if (formNum == 20 && navigator.userAgent.match(/ SeaMonkey\//)) {
--- a/toolkit/components/satchel/test/test_form_submission_cap.html
+++ b/toolkit/components/satchel/test/test_form_submission_cap.html
@@ -26,20 +26,20 @@
field # numInputFields was not saved.
*/
var numSubmittedForms = 0;
var numInputFields = 101;
function checkInitialState() {
countEntries(null, null,
- function(num) {
- ok(!num, "checking for initially empty storage");
- startTest();
- });
+ function(num) {
+ ok(!num, "checking for initially empty storage");
+ startTest();
+ });
}
function startTest() {
var form = document.getElementById("form1");
for (let i = 1; i <= numInputFields; i++) {
var newField = document.createElement("input");
newField.setAttribute("type", "text");
newField.setAttribute("name", "test" + i);
--- a/toolkit/components/satchel/test/test_form_submission_cap2.html
+++ b/toolkit/components/satchel/test/test_form_submission_cap2.html
@@ -124,20 +124,20 @@
<script class="testbody" type="text/javascript">
/* import-globals-from satchel_common.js */
var numSubmittedForms = 0;
var numInputFields = 101;
function checkInitialState() {
countEntries(null, null,
- function(num) {
- ok(!num, "checking for initially empty storage");
- startTest();
- });
+ function(num) {
+ ok(!num, "checking for initially empty storage");
+ startTest();
+ });
}
function startTest() {
// Fill in values for the various fields. We could just set the <input>'s
// value attribute, but we don't save default form values (and we want to
// ensure unsaved values are because of autocomplete=off or whatever).
$_(1, "test" + numInputFields).value = numInputFields + " changed";
@@ -145,24 +145,24 @@ function startTest() {
var button = getFormSubmitButton(1);
button.click();
}
// Make sure that the first (numInputFields - 1) were not saved (as they were not changed).
// Call done() when finished.
function checkCountEntries(formNum, index, done) {
countEntries("test" + index, index,
- function(num) {
- ok(!num, "checking unsaved value " + index);
- if (index < numInputFields) {
- checkCountEntries(formNum, index + 1, done);
- } else {
- done(formNum);
- }
- });
+ function(num) {
+ ok(!num, "checking unsaved value " + index);
+ if (index < numInputFields) {
+ checkCountEntries(formNum, index + 1, done);
+ } else {
+ done(formNum);
+ }
+ });
}
// Called by each form's onsubmit handler.
function checkSubmit(formNum) {
ok(true, "form " + formNum + " submitted");
numSubmittedForms++;
// make sure that the field # numInputFields was saved
--- a/toolkit/components/satchel/test/unit/head_satchel.js
+++ b/toolkit/components/satchel/test/unit/head_satchel.js
@@ -7,74 +7,76 @@ const CURRENT_SCHEMA = 4;
const PR_HOURS = 60 * 60 * 1000000;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FormHistory.jsm");
do_get_profile();
-var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
- getService(Ci.nsIProperties);
+var dirSvc = Cc["@mozilla.org/file/directory_service;1"]
+ .getService(Ci.nsIProperties);
// Send the profile-after-change notification to the form history component to ensure
// that it has been initialized.
var formHistoryStartup = Cc["@mozilla.org/satchel/form-history-startup;1"].
getService(Ci.nsIObserver);
formHistoryStartup.observe(null, "profile-after-change", null);
function getDBVersion(dbfile) {
- var ss = Cc["@mozilla.org/storage/service;1"].
+ var ss = Cc["@mozilla.org/storage/service;1"].
getService(Ci.mozIStorageService);
- var dbConnection = ss.openDatabase(dbfile);
- var version = dbConnection.schemaVersion;
- dbConnection.close();
+ var dbConnection = ss.openDatabase(dbfile);
+ var version = dbConnection.schemaVersion;
+ dbConnection.close();
- return version;
+ return version;
}
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);
- }
- }
- });
+ 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);
+ }
+ }
+ });
}
// 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) {
obj.fieldname = name;
}
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);
- }
- }
- });
+ FormHistory.count(obj, {
+ handleResult: result => count = result,
+ handleError(error) {
+ do_throw("Error occurred searching form history: " + error);
+ },
+ 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) {
obj.fieldname = name;
}
@@ -82,31 +84,38 @@ function updateEntry(op, name, value, th
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);
+ 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();
- }
- },
- });
+ FormHistory.update(changes, {
+ handleError(error) {
+ do_throw("Error occurred updating form history: " + error);
+ },
+ 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_autocomplete.js
+++ b/toolkit/components/satchel/test/unit/test_autocomplete.js
@@ -8,261 +8,259 @@ var testnum = 0;
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;
- }
- return str;
+ var str = number + "";
+ 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;
+ if (prefs.prefHasUserValue("browser.formfill.expire_days")) {
+ return prefs.getIntPref("browser.formfill.expire_days");
+ }
+ return DEFAULT_EXPIRE_DAYS;
}
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()) {
- destFile.remove(false);
- }
+ // ===== test init =====
+ var testfile = do_get_file("formhistory_autocomplete.sqlite");
+ var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
- testfile.copyTo(profileDir, "formhistory.sqlite");
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- fac = Cc["@mozilla.org/satchel/form-autocomplete;1"].
- getService(Ci.nsIFormAutoComplete);
- prefs = Cc["@mozilla.org/preferences-service;1"].
- getService(Ci.nsIPrefBranch);
+ testfile.copyTo(profileDir, "formhistory.sqlite");
- timeGroupingSize = prefs.getIntPref("browser.formfill.timeGroupingSize") * 1000 * 1000;
+ fac = Cc["@mozilla.org/satchel/form-autocomplete;1"].getService(Ci.nsIFormAutoComplete);
+ prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
- run_next_test();
+ timeGroupingSize = prefs.getIntPref("browser.formfill.timeGroupingSize") * 1000 * 1000;
+
+ run_next_test();
}
add_test(function test0() {
- var maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings");
- var bucketSize = prefs.getIntPref("browser.formfill.bucketSize");
+ var maxTimeGroupings = prefs.getIntPref("browser.formfill.maxTimeGroupings");
+ var bucketSize = prefs.getIntPref("browser.formfill.bucketSize");
- // ===== Tests with constant timesUsed and varying lastUsed date =====
- // insert 2 records per bucket to check alphabetical sort within
- now = 1000 * Date.now();
- numRecords = Math.ceil(maxTimeGroupings / bucketSize) * 2;
+ // ===== Tests with constant timesUsed and varying lastUsed date =====
+ // insert 2 records per bucket to check alphabetical sort within
+ now = 1000 * Date.now();
+ numRecords = Math.ceil(maxTimeGroupings / bucketSize) * 2;
- let changes = [ ];
- for (let i = 0; i < numRecords; i += 2) {
- let useDate = now - (i / 2 * bucketSize * timeGroupingSize);
+ let changes = [ ];
+ for (let i = 0; i < numRecords; i += 2) {
+ let useDate = now - (i / 2 * bucketSize * timeGroupingSize);
- changes.push({ op: "add", fieldname: "field1", value: "value" + padLeft(numRecords - 1 - i, 2),
- timesUsed: 1, firstUsed: useDate, lastUsed: useDate });
- changes.push({ op: "add", fieldname: "field1", value: "value" + padLeft(numRecords - 2 - i, 2),
- timesUsed: 1, firstUsed: useDate, lastUsed: useDate });
- }
+ changes.push({ op: "add", fieldname: "field1", value: "value" + padLeft(numRecords - 1 - i, 2),
+ timesUsed: 1, firstUsed: useDate, lastUsed: useDate });
+ changes.push({ op: "add", fieldname: "field1", value: "value" + padLeft(numRecords - 2 - i, 2),
+ timesUsed: 1, firstUsed: useDate, lastUsed: useDate });
+ }
- updateFormHistory(changes, run_next_test);
+ updateFormHistory(changes, run_next_test);
});
add_test(function test1() {
- do_log_info("Check initial state is as expected");
+ do_log_info("Check initial state is as expected");
- countEntries(null, null, function() {
- countEntries("field1", null, function(count) {
- do_check_true(count > 0);
- run_next_test();
- });
+ countEntries(null, null, function() {
+ countEntries("field1", null, function(count) {
+ do_check_true(count > 0);
+ run_next_test();
});
+ });
});
add_test(function test2() {
- do_log_info("Check search contains all entries");
+ do_log_info("Check search contains all entries");
- fac.autoCompleteSearchAsync("field1", "", null, null, null, {
- onSearchCompletion(aResults) {
- do_check_eq(numRecords, aResults.matchCount);
- run_next_test();
- }
- });
+ fac.autoCompleteSearchAsync("field1", "", null, null, null, {
+ onSearchCompletion(aResults) {
+ do_check_eq(numRecords, aResults.matchCount);
+ run_next_test();
+ }
+ });
});
add_test(function test3() {
- do_log_info("Check search result ordering with empty search term");
+ do_log_info("Check search result ordering with empty search term");
- let lastFound = numRecords;
- fac.autoCompleteSearchAsync("field1", "", null, null, null, {
- onSearchCompletion(aResults) {
- for (let i = 0; i < numRecords; i += 2) {
- do_check_eq(parseInt(aResults.getValueAt(i + 1).substr(5), 10), --lastFound);
- do_check_eq(parseInt(aResults.getValueAt(i).substr(5), 10), --lastFound);
- }
- run_next_test();
- }
- });
+ let lastFound = numRecords;
+ fac.autoCompleteSearchAsync("field1", "", null, null, null, {
+ onSearchCompletion(aResults) {
+ for (let i = 0; i < numRecords; i += 2) {
+ do_check_eq(parseInt(aResults.getValueAt(i + 1).substr(5), 10), --lastFound);
+ do_check_eq(parseInt(aResults.getValueAt(i).substr(5), 10), --lastFound);
+ }
+ run_next_test();
+ }
+ });
});
add_test(function test4() {
- do_log_info("Check search result ordering with \"v\"");
+ do_log_info("Check search result ordering with \"v\"");
- let lastFound = numRecords;
- fac.autoCompleteSearchAsync("field1", "v", null, null, null, {
- onSearchCompletion(aResults) {
- for (let i = 0; i < numRecords; i += 2) {
- do_check_eq(parseInt(aResults.getValueAt(i + 1).substr(5), 10), --lastFound);
- do_check_eq(parseInt(aResults.getValueAt(i).substr(5), 10), --lastFound);
- }
- run_next_test();
- }
- });
+ let lastFound = numRecords;
+ fac.autoCompleteSearchAsync("field1", "v", null, null, null, {
+ onSearchCompletion(aResults) {
+ for (let i = 0; i < numRecords; i += 2) {
+ do_check_eq(parseInt(aResults.getValueAt(i + 1).substr(5), 10), --lastFound);
+ do_check_eq(parseInt(aResults.getValueAt(i).substr(5), 10), --lastFound);
+ }
+ run_next_test();
+ }
+ });
});
const timesUsedSamples = 20;
add_test(function test5() {
- do_log_info("Begin tests with constant use dates and varying timesUsed");
+ do_log_info("Begin tests with constant use dates and varying timesUsed");
- let changes = [];
- for (let i = 0; i < timesUsedSamples; i++) {
- let timesUsed = (timesUsedSamples - i);
- let change = { op: "add", fieldname: "field2", value: "value" + (timesUsedSamples - 1 - i),
- timesUsed: timesUsed * timeGroupingSize, firstUsed: now, lastUsed: now };
- changes.push(change);
- }
- updateFormHistory(changes, run_next_test);
+ let changes = [];
+ for (let i = 0; i < timesUsedSamples; i++) {
+ let timesUsed = (timesUsedSamples - i);
+ let change = { op: "add", fieldname: "field2", value: "value" + (timesUsedSamples - 1 - i),
+ timesUsed: timesUsed * timeGroupingSize, firstUsed: now, lastUsed: now };
+ changes.push(change);
+ }
+ updateFormHistory(changes, run_next_test);
});
add_test(function test6() {
- do_log_info("Check search result ordering with empty search term");
+ do_log_info("Check search result ordering with empty search term");
- let lastFound = timesUsedSamples;
- fac.autoCompleteSearchAsync("field2", "", null, null, null, {
- onSearchCompletion(aResults) {
- for (let i = 0; i < timesUsedSamples; i++) {
- do_check_eq(parseInt(aResults.getValueAt(i).substr(5)), --lastFound);
- }
- run_next_test();
- }
- });
+ let lastFound = timesUsedSamples;
+ fac.autoCompleteSearchAsync("field2", "", null, null, null, {
+ onSearchCompletion(aResults) {
+ for (let i = 0; i < timesUsedSamples; i++) {
+ do_check_eq(parseInt(aResults.getValueAt(i).substr(5)), --lastFound);
+ }
+ run_next_test();
+ }
+ });
});
add_test(function test7() {
- do_log_info("Check search result ordering with \"v\"");
+ do_log_info("Check search result ordering with \"v\"");
- let lastFound = timesUsedSamples;
- fac.autoCompleteSearchAsync("field2", "v", null, null, null, {
- onSearchCompletion(aResults) {
- for (let i = 0; i < timesUsedSamples; i++) {
- do_check_eq(parseInt(aResults.getValueAt(i).substr(5)), --lastFound);
- }
- run_next_test();
- }
- });
+ let lastFound = timesUsedSamples;
+ fac.autoCompleteSearchAsync("field2", "v", null, null, null, {
+ onSearchCompletion(aResults) {
+ for (let i = 0; i < timesUsedSamples; i++) {
+ do_check_eq(parseInt(aResults.getValueAt(i).substr(5)), --lastFound);
+ }
+ run_next_test();
+ }
+ });
});
add_test(function test8() {
- do_log_info("Check that \"senior citizen\" entries get a bonus (browser.formfill.agedBonus)");
+ do_log_info("Check that \"senior citizen\" entries get a bonus (browser.formfill.agedBonus)");
- let agedDate = 1000 * (Date.now() - getFormExpiryDays() * 24 * 60 * 60 * 1000);
+ let agedDate = 1000 * (Date.now() - getFormExpiryDays() * 24 * 60 * 60 * 1000);
- let changes = [ ];
- changes.push({ op: "add", fieldname: "field3", value: "old but not senior",
- timesUsed: 100, firstUsed: (agedDate + 60 * 1000 * 1000), lastUsed: now });
- changes.push({ op: "add", fieldname: "field3", value: "senior citizen",
- timesUsed: 100, firstUsed: (agedDate - 60 * 1000 * 1000), lastUsed: now });
- updateFormHistory(changes, run_next_test);
+ let changes = [ ];
+ changes.push({ op: "add", fieldname: "field3", value: "old but not senior",
+ timesUsed: 100, firstUsed: (agedDate + 60 * 1000 * 1000), lastUsed: now });
+ changes.push({ op: "add", fieldname: "field3", value: "senior citizen",
+ timesUsed: 100, firstUsed: (agedDate - 60 * 1000 * 1000), lastUsed: now });
+ updateFormHistory(changes, run_next_test);
});
add_test(function test9() {
- fac.autoCompleteSearchAsync("field3", "", null, null, null, {
- onSearchCompletion(aResults) {
- do_check_eq(aResults.getValueAt(0), "senior citizen");
- do_check_eq(aResults.getValueAt(1), "old but not senior");
- run_next_test();
- }
- });
+ fac.autoCompleteSearchAsync("field3", "", null, null, null, {
+ onSearchCompletion(aResults) {
+ do_check_eq(aResults.getValueAt(0), "senior citizen");
+ do_check_eq(aResults.getValueAt(1), "old but not senior");
+ run_next_test();
+ }
+ });
});
add_test(function test10() {
- do_log_info("Check entries that are really old or in the future");
+ do_log_info("Check entries that are really old or in the future");
- let changes = [ ];
- changes.push({ op: "add", fieldname: "field4", value: "date of 0",
- timesUsed: 1, firstUsed: 0, lastUsed: 0 });
- changes.push({ op: "add", fieldname: "field4", value: "in the future 1",
- timesUsed: 1, firstUsed: 0, lastUsed: now * 2 });
- changes.push({ op: "add", fieldname: "field4", value: "in the future 2",
- timesUsed: 1, firstUsed: now * 2, lastUsed: now * 2 });
- updateFormHistory(changes, run_next_test);
+ let changes = [ ];
+ changes.push({ op: "add", fieldname: "field4", value: "date of 0",
+ timesUsed: 1, firstUsed: 0, lastUsed: 0 });
+ changes.push({ op: "add", fieldname: "field4", value: "in the future 1",
+ timesUsed: 1, firstUsed: 0, lastUsed: now * 2 });
+ changes.push({ op: "add", fieldname: "field4", value: "in the future 2",
+ timesUsed: 1, firstUsed: now * 2, lastUsed: now * 2 });
+ updateFormHistory(changes, run_next_test);
});
add_test(function test11() {
- fac.autoCompleteSearchAsync("field4", "", null, null, null, {
- onSearchCompletion(aResults) {
- do_check_eq(aResults.matchCount, 3);
- run_next_test();
- }
- });
+ fac.autoCompleteSearchAsync("field4", "", null, null, null, {
+ onSearchCompletion(aResults) {
+ do_check_eq(aResults.matchCount, 3);
+ run_next_test();
+ }
+ });
});
var syncValues = ["sync1", "sync1a", "sync2", "sync3"]
add_test(function test12() {
- do_log_info("Check old synchronous api");
+ do_log_info("Check old synchronous api");
- let changes = [ ];
- for (let value of syncValues) {
- changes.push({ op: "add", fieldname: "field5", value });
- }
- updateFormHistory(changes, run_next_test);
+ let changes = [ ];
+ for (let value of syncValues) {
+ changes.push({ op: "add", fieldname: "field5", value });
+ }
+ updateFormHistory(changes, run_next_test);
});
add_test(function test_token_limit_DB() {
- function test_token_limit_previousResult(previousResult) {
- do_log_info("Check that the number of tokens used in a search is not capped to " +
+ function test_token_limit_previousResult(previousResult) {
+ do_log_info("Check that the number of tokens used in a search is not capped to " +
"MAX_SEARCH_TOKENS when using a previousResult");
- // This provide more accuracy since performance is less of an issue.
- // Search for a string where the first 10 tokens match the previous value but the 11th does not
- // when re-using a previous result.
- fac.autoCompleteSearchAsync("field_token_cap",
- "a b c d e f g h i j .",
- null, previousResult, null, {
- onSearchCompletion(aResults) {
- do_check_eq(aResults.matchCount, 0,
- "All search tokens should be used with " +
+ // This provide more accuracy since performance is less of an issue.
+ // Search for a string where the first 10 tokens match the previous value but the 11th does not
+ // when re-using a previous result.
+ fac.autoCompleteSearchAsync("field_token_cap",
+ "a b c d e f g h i j .",
+ null, previousResult, null, {
+ onSearchCompletion(aResults) {
+ do_check_eq(aResults.matchCount, 0,
+ "All search tokens should be used with " +
"previous results");
- run_next_test();
- }
- });
- }
+ run_next_test();
+ }
+ });
+ }
- do_log_info("Check that the number of tokens used in a search is capped to MAX_SEARCH_TOKENS " +
+ do_log_info("Check that the number of tokens used in a search is capped to MAX_SEARCH_TOKENS " +
"for performance when querying the DB");
- let changes = [ ];
- changes.push({ op: "add", fieldname: "field_token_cap",
- // value with 15 unique tokens
- value: "a b c d e f g h i j k l m n o",
- timesUsed: 1, firstUsed: 0, lastUsed: 0 });
- updateFormHistory(changes, () => {
- // Search for a string where the first 10 tokens match the value above but the 11th does not
- // (which would prevent the result from being returned if the 11th term was used).
- fac.autoCompleteSearchAsync("field_token_cap",
- "a b c d e f g h i j .",
- null, null, null, {
- onSearchCompletion(aResults) {
- do_check_eq(aResults.matchCount, 1,
- "Only the first MAX_SEARCH_TOKENS tokens " +
+ let changes = [ ];
+ changes.push({ op: "add", fieldname: "field_token_cap",
+ // value with 15 unique tokens
+ value: "a b c d e f g h i j k l m n o",
+ timesUsed: 1, firstUsed: 0, lastUsed: 0 });
+ updateFormHistory(changes, () => {
+ // Search for a string where the first 10 tokens match the value above but the 11th does not
+ // (which would prevent the result from being returned if the 11th term was used).
+ fac.autoCompleteSearchAsync("field_token_cap",
+ "a b c d e f g h i j .",
+ null, null, null, {
+ onSearchCompletion(aResults) {
+ do_check_eq(aResults.matchCount, 1,
+ "Only the first MAX_SEARCH_TOKENS tokens " +
"should be used for DB queries");
- test_token_limit_previousResult(aResults);
- }
- });
- });
+ test_token_limit_previousResult(aResults);
+ }
+ });
+ });
});
--- a/toolkit/components/satchel/test/unit/test_db_corrupt.js
+++ b/toolkit/components/satchel/test/unit/test_db_corrupt.js
@@ -63,29 +63,29 @@ add_test(function test_corruptFormHistor
}
});
});
add_test(function test_corruptFormHistoryDB_addEntry() {
do_log_info("test adding an entry to the empty DB.");
updateEntry("add", "name-A", "value-A",
- function() {
- countEntries("name-A", "value-A",
- function(count) {
- do_check_true(count == 1);
- run_next_test();
- });
- });
- });
+ function() {
+ countEntries("name-A", "value-A",
+ function(count) {
+ do_check_true(count == 1);
+ run_next_test();
+ });
+ });
+});
add_test(function test_corruptFormHistoryDB_removeEntry() {
do_log_info("test removing an entry to the empty DB.");
updateEntry("remove", "name-A", "value-A",
- function() {
- countEntries("name-A", "value-A",
- function(count) {
- do_check_true(count == 0);
- run_next_test();
- });
- });
- });
+ function() {
+ countEntries("name-A", "value-A",
+ function(count) {
+ do_check_true(count == 0);
+ run_next_test();
+ });
+ });
+});
--- a/toolkit/components/satchel/test/unit/test_db_update_v4.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4.js
@@ -11,49 +11,49 @@ function run_test() {
iter = next_test();
iter.next();
}
function* next_test() {
try {
// ===== test init =====
- var testfile = do_get_file("formhistory_v3.sqlite");
- var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
+ 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()) {
- destFile.remove(false);
- }
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- testfile.copyTo(profileDir, "formhistory.sqlite");
- do_check_eq(3, getDBVersion(testfile));
+ testfile.copyTo(profileDir, "formhistory.sqlite");
+ do_check_eq(3, getDBVersion(testfile));
- // ===== 1 =====
- testnum++;
+ // ===== 1 =====
+ testnum++;
- destFile = profileDir.clone();
- destFile.append("formhistory.sqlite");
- let dbConnection = Services.storage.openUnsharedDatabase(destFile);
+ destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ let dbConnection = Services.storage.openUnsharedDatabase(destFile);
- // check for upgraded schema.
- do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
+ // check for upgraded schema.
+ do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
- // Check that the index was added
- do_check_true(dbConnection.tableExists("moz_deleted_formhistory"));
- dbConnection.close();
+ // Check that the index was added
+ do_check_true(dbConnection.tableExists("moz_deleted_formhistory"));
+ dbConnection.close();
- // check for upgraded schema.
- do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
- // check that an entry still exists
- yield countEntries("name-A", "value-A",
- function(num) {
- do_check_true(num > 0);
- do_test_finished();
- }
- );
+ // check for upgraded schema.
+ do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
+ // check that an entry still exists
+ yield countEntries("name-A", "value-A",
+ function(num) {
+ do_check_true(num > 0);
+ do_test_finished();
+ }
+ );
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;
}
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v4b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v4b.js
@@ -11,47 +11,47 @@ function run_test() {
iter = next_test();
iter.next();
}
function* next_test() {
try {
// ===== test init =====
- var testfile = do_get_file("formhistory_v3v4.sqlite");
- var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
+ 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()) {
- destFile.remove(false);
- }
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- testfile.copyTo(profileDir, "formhistory.sqlite");
- do_check_eq(3, getDBVersion(testfile));
+ testfile.copyTo(profileDir, "formhistory.sqlite");
+ do_check_eq(3, getDBVersion(testfile));
- // ===== 1 =====
- testnum++;
+ // ===== 1 =====
+ testnum++;
- destFile = profileDir.clone();
- destFile.append("formhistory.sqlite");
- let dbConnection = Services.storage.openUnsharedDatabase(destFile);
+ destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ let dbConnection = Services.storage.openUnsharedDatabase(destFile);
- // check for upgraded schema.
- do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
+ // check for upgraded schema.
+ do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
- // Check that the index was added
- do_check_true(dbConnection.tableExists("moz_deleted_formhistory"));
- dbConnection.close();
+ // Check that the index was added
+ do_check_true(dbConnection.tableExists("moz_deleted_formhistory"));
+ dbConnection.close();
- // check that an entry still exists
- yield countEntries("name-A", "value-A",
- function(num) {
- do_check_true(num > 0);
- do_test_finished();
- }
- );
+ // check that an entry still exists
+ yield countEntries("name-A", "value-A",
+ function(num) {
+ do_check_true(num > 0);
+ do_test_finished();
+ }
+ );
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;
}
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v999a.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999a.js
@@ -19,55 +19,55 @@ function run_test() {
}
function next_test() {
iter.next();
}
function* tests() {
try {
- var testnum = 0;
+ var testnum = 0;
- // ===== test init =====
- var testfile = do_get_file("formhistory_v999a.sqlite");
- var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
+ // ===== 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()) {
- destFile.remove(false);
- }
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- testfile.copyTo(profileDir, "formhistory.sqlite");
- do_check_eq(999, getDBVersion(testfile));
+ 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(); }
+ let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
+ let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
- // ===== 1 =====
- testnum++;
- // Check for expected contents.
- yield countEntries(null, null, function(num) { do_check_true(num > 0); next_test(); });
- yield countEntries("name-A", "value-A", checkOne);
- yield countEntries("name-B", "value-B", checkOne);
- yield countEntries("name-C", "value-C1", checkOne);
- yield countEntries("name-C", "value-C2", checkOne);
- yield countEntries("name-E", "value-E", checkOne);
+ // ===== 1 =====
+ testnum++;
+ // Check for expected contents.
+ yield countEntries(null, null, function(num) { do_check_true(num > 0); next_test(); });
+ yield countEntries("name-A", "value-A", checkOne);
+ yield countEntries("name-B", "value-B", checkOne);
+ yield countEntries("name-C", "value-C1", checkOne);
+ yield countEntries("name-C", "value-C2", checkOne);
+ yield countEntries("name-E", "value-E", checkOne);
- // check for downgraded schema.
- do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
+ // check for downgraded schema.
+ do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
- // ===== 2 =====
- testnum++;
- // Exercise adding and removing a name/value pair
- yield countEntries("name-D", "value-D", checkZero);
- yield updateEntry("add", "name-D", "value-D", next_test);
- yield countEntries("name-D", "value-D", checkOne);
- yield updateEntry("remove", "name-D", "value-D", next_test);
- yield countEntries("name-D", "value-D", checkZero);
+ // ===== 2 =====
+ testnum++;
+ // Exercise adding and removing a name/value pair
+ yield countEntries("name-D", "value-D", checkZero);
+ yield updateEntry("add", "name-D", "value-D", next_test);
+ yield countEntries("name-D", "value-D", checkOne);
+ yield updateEntry("remove", "name-D", "value-D", next_test);
+ yield countEntries("name-D", "value-D", checkZero);
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;
}
do_test_finished();
}
--- a/toolkit/components/satchel/test/unit/test_db_update_v999b.js
+++ b/toolkit/components/satchel/test/unit/test_db_update_v999b.js
@@ -19,73 +19,73 @@ function run_test() {
}
function next_test() {
iter.next();
}
function* tests() {
try {
- var testnum = 0;
+ var testnum = 0;
- // ===== test init =====
- var testfile = do_get_file("formhistory_v999b.sqlite");
- var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
+ // ===== 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()) {
- destFile.remove(false);
- }
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- var bakFile = profileDir.clone();
- bakFile.append("formhistory.sqlite.corrupt");
- if (bakFile.exists()) {
- bakFile.remove(false);
- }
+ var bakFile = profileDir.clone();
+ bakFile.append("formhistory.sqlite.corrupt");
+ if (bakFile.exists()) {
+ bakFile.remove(false);
+ }
- testfile.copyTo(profileDir, "formhistory.sqlite");
- do_check_eq(999, getDBVersion(testfile));
+ 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(); }
+ let checkZero = function(num) { do_check_eq(num, 0); next_test(); }
+ let checkOne = function(num) { do_check_eq(num, 1); next_test(); }
- // ===== 1 =====
- testnum++;
+ // ===== 1 =====
+ testnum++;
- // Open the DB, ensure that a backup of the corrupt DB is made.
- // DB init is done lazily so the DB shouldn't be created yet.
- do_check_false(bakFile.exists());
- // Doing any request to the DB should create it.
- yield countEntries("", "", next_test);
+ // Open the DB, ensure that a backup of the corrupt DB is made.
+ // DB init is done lazily so the DB shouldn't be created yet.
+ do_check_false(bakFile.exists());
+ // Doing any request to the DB should create it.
+ yield countEntries("", "", next_test);
- do_check_true(bakFile.exists());
- bakFile.remove(false);
+ do_check_true(bakFile.exists());
+ bakFile.remove(false);
- // ===== 2 =====
- testnum++;
- // File should be empty
- yield countEntries(null, null, function(num) { do_check_false(num); next_test(); });
- yield countEntries("name-A", "value-A", checkZero);
- // check for current schema.
- do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
+ // ===== 2 =====
+ testnum++;
+ // File should be empty
+ yield countEntries(null, null, function(num) { do_check_false(num); next_test(); });
+ yield countEntries("name-A", "value-A", checkZero);
+ // check for current schema.
+ do_check_eq(CURRENT_SCHEMA, FormHistory.schemaVersion);
- // ===== 3 =====
- testnum++;
- // Try adding an entry
- yield updateEntry("add", "name-A", "value-A", next_test);
- yield countEntries(null, null, checkOne);
- yield countEntries("name-A", "value-A", checkOne);
+ // ===== 3 =====
+ testnum++;
+ // Try adding an entry
+ yield updateEntry("add", "name-A", "value-A", next_test);
+ yield countEntries(null, null, checkOne);
+ yield countEntries("name-A", "value-A", checkOne);
- // ===== 4 =====
- testnum++;
- // Try removing an entry
- yield updateEntry("remove", "name-A", "value-A", next_test);
- yield countEntries(null, null, checkZero);
- yield countEntries("name-A", "value-A", checkZero);
+ // ===== 4 =====
+ testnum++;
+ // Try removing an entry
+ yield updateEntry("remove", "name-A", "value-A", next_test);
+ yield countEntries(null, null, checkZero);
+ yield countEntries("name-A", "value-A", checkZero);
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;
}
do_test_finished();
}
--- a/toolkit/components/satchel/test/unit/test_history_api.js
+++ b/toolkit/components/satchel/test/unit/test_history_api.js
@@ -100,357 +100,357 @@ function promiseCountEntries(name, value
add_task(async function() {
let oldSupportsDeletedTable = FormHistory._supportsDeletedTable;
FormHistory._supportsDeletedTable = true;
try {
// ===== test init =====
- var testfile = do_get_file("formhistory_apitest.sqlite");
- var profileDir = dirSvc.get("ProfD", Ci.nsIFile);
+ 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()) {
- destFile.remove(false);
- }
+ // Cleanup from any previous tests or failures.
+ var destFile = profileDir.clone();
+ destFile.append("formhistory.sqlite");
+ if (destFile.exists()) {
+ destFile.remove(false);
+ }
- testfile.copyTo(profileDir, "formhistory.sqlite");
+ testfile.copyTo(profileDir, "formhistory.sqlite");
- function checkExists(num) { do_check_true(num > 0); }
- function checkNotExists(num) { do_check_true(num == 0); }
+ function checkExists(num) { do_check_true(num > 0); }
+ function checkNotExists(num) { do_check_true(num == 0); }
- // ===== 1 =====
- // Check initial state is as expected
- testnum++;
- await promiseCountEntries("name-A", null, checkExists);
- await promiseCountEntries("name-B", null, checkExists);
- await promiseCountEntries("name-C", null, checkExists);
- await promiseCountEntries("name-D", null, checkExists);
- await promiseCountEntries("name-A", "value-A", checkExists);
- await promiseCountEntries("name-B", "value-B1", checkExists);
- await promiseCountEntries("name-B", "value-B2", checkExists);
- await promiseCountEntries("name-C", "value-C", checkExists);
- await promiseCountEntries("name-D", "value-D", checkExists);
- // time-A/B/C/D checked below.
+ // ===== 1 =====
+ // Check initial state is as expected
+ testnum++;
+ await promiseCountEntries("name-A", null, checkExists);
+ await promiseCountEntries("name-B", null, checkExists);
+ await promiseCountEntries("name-C", null, checkExists);
+ await promiseCountEntries("name-D", null, checkExists);
+ await promiseCountEntries("name-A", "value-A", checkExists);
+ await promiseCountEntries("name-B", "value-B1", checkExists);
+ await promiseCountEntries("name-B", "value-B2", checkExists);
+ await promiseCountEntries("name-C", "value-C", checkExists);
+ await promiseCountEntries("name-D", "value-D", checkExists);
+ // time-A/B/C/D checked below.
- // Delete anything from the deleted table
- let dbFile = Services.dirsvc.get("ProfD", Ci.nsIFile).clone();
- dbFile.append("formhistory.sqlite");
- dbConnection = Services.storage.openUnsharedDatabase(dbFile);
+ // Delete anything from the deleted table
+ let dbFile = Services.dirsvc.get("ProfD", Ci.nsIFile).clone();
+ dbFile.append("formhistory.sqlite");
+ dbConnection = Services.storage.openUnsharedDatabase(dbFile);
- let deferred = Promise.defer();
+ let deferred = Promise.defer();
- let stmt = dbConnection.createAsyncStatement("DELETE FROM moz_deleted_formhistory");
- stmt.executeAsync({
- handleResult(resultSet) { },
- handleError(error) {
- do_throw("Error occurred counting deleted all entries: " + error);
- },
- handleCompletion() {
- stmt.finalize();
- deferred.resolve();
- }
- });
- await deferred.promise;
+ let stmt = dbConnection.createAsyncStatement("DELETE FROM moz_deleted_formhistory");
+ stmt.executeAsync({
+ handleResult(resultSet) { },
+ handleError(error) {
+ do_throw("Error occurred counting deleted all entries: " + error);
+ },
+ handleCompletion() {
+ stmt.finalize();
+ deferred.resolve();
+ }
+ });
+ await deferred.promise;
- // ===== 2 =====
- // Test looking for nonexistent / bogus data.
- testnum++;
- await promiseCountEntries("blah", null, checkNotExists);
- await promiseCountEntries("", null, checkNotExists);
- await promiseCountEntries("name-A", "blah", checkNotExists);
- await promiseCountEntries("name-A", "", checkNotExists);
- await promiseCountEntries("name-A", null, checkExists);
- await promiseCountEntries("blah", "value-A", checkNotExists);
- await promiseCountEntries("", "value-A", checkNotExists);
- await promiseCountEntries(null, "value-A", checkExists);
+ // ===== 2 =====
+ // Test looking for nonexistent / bogus data.
+ testnum++;
+ await promiseCountEntries("blah", null, checkNotExists);
+ await promiseCountEntries("", null, checkNotExists);
+ await promiseCountEntries("name-A", "blah", checkNotExists);
+ await promiseCountEntries("name-A", "", checkNotExists);
+ await promiseCountEntries("name-A", null, checkExists);
+ await promiseCountEntries("blah", "value-A", checkNotExists);
+ await promiseCountEntries("", "value-A", checkNotExists);
+ await promiseCountEntries(null, "value-A", checkExists);
- // 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()
+ // 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()
+ }
}
- }
- });
- await deferred.promise;
+ });
+ await deferred.promise;
- // ===== 3 =====
- // Test removeEntriesForName with a single matching value
- testnum++;
- await promiseUpdateEntry("remove", "name-A", null);
+ // ===== 3 =====
+ // Test removeEntriesForName with a single matching value
+ testnum++;
+ await promiseUpdateEntry("remove", "name-A", null);
- await promiseCountEntries("name-A", "value-A", checkNotExists);
- await promiseCountEntries("name-B", "value-B1", checkExists);
- await promiseCountEntries("name-B", "value-B2", checkExists);
- await promiseCountEntries("name-C", "value-C", checkExists);
- await promiseCountEntries("name-D", "value-D", checkExists);
- await countDeletedEntries(1);
+ await promiseCountEntries("name-A", "value-A", checkNotExists);
+ await promiseCountEntries("name-B", "value-B1", checkExists);
+ await promiseCountEntries("name-B", "value-B2", checkExists);
+ await promiseCountEntries("name-C", "value-C", checkExists);
+ await promiseCountEntries("name-D", "value-D", checkExists);
+ await countDeletedEntries(1);
- // ===== 4 =====
- // Test removeEntriesForName with multiple matching values
- testnum++;
- await promiseUpdateEntry("remove", "name-B", null);
+ // ===== 4 =====
+ // Test removeEntriesForName with multiple matching values
+ testnum++;
+ await promiseUpdateEntry("remove", "name-B", null);
- await promiseCountEntries("name-A", "value-A", checkNotExists);
- await promiseCountEntries("name-B", "value-B1", checkNotExists);
- await promiseCountEntries("name-B", "value-B2", checkNotExists);
- await promiseCountEntries("name-C", "value-C", checkExists);
- await promiseCountEntries("name-D", "value-D", checkExists);
- await countDeletedEntries(3);
+ await promiseCountEntries("name-A", "value-A", checkNotExists);
+ await promiseCountEntries("name-B", "value-B1", checkNotExists);
+ await promiseCountEntries("name-B", "value-B2", checkNotExists);
+ await promiseCountEntries("name-C", "value-C", checkExists);
+ await promiseCountEntries("name-D", "value-D", checkExists);
+ await countDeletedEntries(3);
- // ===== 5 =====
- // Test removing by time range (single entry, not surrounding entries)
- testnum++;
- await promiseCountEntries("time-A", null, checkExists); // firstUsed=1000, lastUsed=1000
- await promiseCountEntries("time-B", null, checkExists); // firstUsed=1000, lastUsed=1099
- await promiseCountEntries("time-C", null, checkExists); // firstUsed=1099, lastUsed=1099
- await promiseCountEntries("time-D", null, checkExists); // firstUsed=2001, lastUsed=2001
- await promiseUpdate({ op: "remove", firstUsedStart: 1050, firstUsedEnd: 2000 });
+ // ===== 5 =====
+ // Test removing by time range (single entry, not surrounding entries)
+ testnum++;
+ await promiseCountEntries("time-A", null, checkExists); // firstUsed=1000, lastUsed=1000
+ await promiseCountEntries("time-B", null, checkExists); // firstUsed=1000, lastUsed=1099
+ await promiseCountEntries("time-C", null, checkExists); // firstUsed=1099, lastUsed=1099
+ await promiseCountEntries("time-D", null, checkExists); // firstUsed=2001, lastUsed=2001
+ await promiseUpdate({ op: "remove", firstUsedStart: 1050, firstUsedEnd: 2000 });
- await promiseCountEntries("time-A", null, checkExists);
- await promiseCountEntries("time-B", null, checkExists);
- await promiseCountEntries("time-C", null, checkNotExists);
- await promiseCountEntries("time-D", null, checkExists);
- await countDeletedEntries(4);
+ await promiseCountEntries("time-A", null, checkExists);
+ await promiseCountEntries("time-B", null, checkExists);
+ await promiseCountEntries("time-C", null, checkNotExists);
+ await promiseCountEntries("time-D", null, checkExists);
+ await countDeletedEntries(4);
- // ===== 6 =====
- // Test removing by time range (multiple entries)
- testnum++;
- await promiseUpdate({ op: "remove", firstUsedStart: 1000, firstUsedEnd: 2000 });
+ // ===== 6 =====
+ // Test removing by time range (multiple entries)
+ testnum++;
+ await promiseUpdate({ op: "remove", firstUsedStart: 1000, firstUsedEnd: 2000 });
- await promiseCountEntries("time-A", null, checkNotExists);
- await promiseCountEntries("time-B", null, checkNotExists);
- await promiseCountEntries("time-C", null, checkNotExists);
- await promiseCountEntries("time-D", null, checkExists);
- await countDeletedEntries(6);
+ await promiseCountEntries("time-A", null, checkNotExists);
+ await promiseCountEntries("time-B", null, checkNotExists);
+ await promiseCountEntries("time-C", null, checkNotExists);
+ await promiseCountEntries("time-D", null, checkExists);
+ await countDeletedEntries(6);
- // ===== 7 =====
- // test removeAllEntries
- testnum++;
- await promiseUpdateEntry("remove", null, null);
+ // ===== 7 =====
+ // test removeAllEntries
+ testnum++;
+ await promiseUpdateEntry("remove", null, null);
- await promiseCountEntries("name-C", null, checkNotExists);
- await promiseCountEntries("name-D", null, checkNotExists);
- await promiseCountEntries("name-C", "value-C", checkNotExists);
- await promiseCountEntries("name-D", "value-D", checkNotExists);
+ await promiseCountEntries("name-C", null, checkNotExists);
+ await promiseCountEntries("name-D", null, checkNotExists);
+ await promiseCountEntries("name-C", "value-C", checkNotExists);
+ await promiseCountEntries("name-D", "value-D", checkNotExists);
- await promiseCountEntries(null, null, checkNotExists);
- await countDeletedEntries(6);
+ await promiseCountEntries(null, null, checkNotExists);
+ await countDeletedEntries(6);
- // ===== 8 =====
- // Add a single entry back
- testnum++;
- await promiseUpdateEntry("add", "newname-A", "newvalue-A");
- await promiseCountEntries("newname-A", "newvalue-A", checkExists);
+ // ===== 8 =====
+ // Add a single entry back
+ testnum++;
+ await promiseUpdateEntry("add", "newname-A", "newvalue-A");
+ await promiseCountEntries("newname-A", "newvalue-A", checkExists);
- // ===== 9 =====
- // Remove the single entry
- testnum++;
- await promiseUpdateEntry("remove", "newname-A", "newvalue-A");
- await promiseCountEntries("newname-A", "newvalue-A", checkNotExists);
+ // ===== 9 =====
+ // Remove the single entry
+ testnum++;
+ await promiseUpdateEntry("remove", "newname-A", "newvalue-A");
+ await promiseCountEntries("newname-A", "newvalue-A", checkNotExists);
- // ===== 10 =====
- // Add a single entry
- testnum++;
- await promiseUpdateEntry("add", "field1", "value1");
- await promiseCountEntries("field1", "value1", checkExists);
+ // ===== 10 =====
+ // Add a single entry
+ testnum++;
+ await promiseUpdateEntry("add", "field1", "value1");
+ await promiseCountEntries("field1", "value1", checkExists);
- let processFirstResult = function processResults(results) {
- // Only handle the first result
- if (results.length > 0) {
- let result = results[0];
- return [result.timesUsed, result.firstUsed, result.lastUsed, result.guid];
+ let processFirstResult = function processResults(results) {
+ // Only handle the first result
+ if (results.length > 0) {
+ let result = results[0];
+ return [result.timesUsed, result.firstUsed, result.lastUsed, result.guid];
+ }
+ return undefined;
}
- return undefined;
- }
- let results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
- { fieldname: "field1", value: "value1" });
- let [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
- do_check_eq(1, timesUsed);
- do_check_true(firstUsed > 0);
- do_check_true(lastUsed > 0);
- await promiseCountEntries(null, null, num => do_check_eq(num, 1));
+ let results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
+ { fieldname: "field1", value: "value1" });
+ let [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
+ do_check_eq(1, timesUsed);
+ do_check_true(firstUsed > 0);
+ do_check_true(lastUsed > 0);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 1));
- // ===== 11 =====
- // Add another single entry
- testnum++;
- await promiseUpdateEntry("add", "field1", "value1b");
- await promiseCountEntries("field1", "value1", checkExists);
- await promiseCountEntries("field1", "value1b", checkExists);
- await promiseCountEntries(null, null, num => do_check_eq(num, 2));
+ // ===== 11 =====
+ // Add another single entry
+ testnum++;
+ await promiseUpdateEntry("add", "field1", "value1b");
+ await promiseCountEntries("field1", "value1", checkExists);
+ await promiseCountEntries("field1", "value1b", checkExists);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 2));
- // ===== 12 =====
- // Update a single entry
- testnum++;
+ // ===== 12 =====
+ // Update a single entry
+ testnum++;
- results = await promiseSearchEntries(["guid"], { fieldname: "field1", value: "value1" });
- let guid = processFirstResult(results)[3];
+ results = await promiseSearchEntries(["guid"], { fieldname: "field1", value: "value1" });
+ let guid = processFirstResult(results)[3];
- await promiseUpdate({ op: "update", guid, value: "modifiedValue" });
- await promiseCountEntries("field1", "modifiedValue", checkExists);
- await promiseCountEntries("field1", "value1", checkNotExists);
- await promiseCountEntries("field1", "value1b", checkExists);
- await promiseCountEntries(null, null, num => do_check_eq(num, 2));
+ await promiseUpdate({ op: "update", guid, value: "modifiedValue" });
+ await promiseCountEntries("field1", "modifiedValue", checkExists);
+ await promiseCountEntries("field1", "value1", checkNotExists);
+ await promiseCountEntries("field1", "value1b", checkExists);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 2));
- // ===== 13 =====
- // Add a single entry with times
- testnum++;
- await promiseUpdate({ op: "add", fieldname: "field2", value: "value2",
- timesUsed: 20, firstUsed: 100, lastUsed: 500 });
+ // ===== 13 =====
+ // Add a single entry with times
+ testnum++;
+ await promiseUpdate({ op: "add", fieldname: "field2", value: "value2",
+ timesUsed: 20, firstUsed: 100, lastUsed: 500 });
- results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
- { fieldname: "field2", value: "value2" });
- [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
+ results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
+ { fieldname: "field2", value: "value2" });
+ [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
- do_check_eq(20, timesUsed);
- do_check_eq(100, firstUsed);
- do_check_eq(500, lastUsed);
- await promiseCountEntries(null, null, num => do_check_eq(num, 3));
+ do_check_eq(20, timesUsed);
+ do_check_eq(100, firstUsed);
+ do_check_eq(500, lastUsed);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 3));
- // ===== 14 =====
- // Bump an entry, which updates its lastUsed field
- testnum++;
- await promiseUpdate({ op: "bump", fieldname: "field2", value: "value2",
- timesUsed: 20, firstUsed: 100, lastUsed: 500 });
- results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
- { fieldname: "field2", value: "value2" });
- [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
- do_check_eq(21, timesUsed);
- do_check_eq(100, firstUsed);
- do_check_true(lastUsed > 500);
- await promiseCountEntries(null, null, num => do_check_eq(num, 3));
+ // ===== 14 =====
+ // Bump an entry, which updates its lastUsed field
+ testnum++;
+ await promiseUpdate({ op: "bump", fieldname: "field2", value: "value2",
+ timesUsed: 20, firstUsed: 100, lastUsed: 500 });
+ results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
+ { fieldname: "field2", value: "value2" });
+ [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
+ do_check_eq(21, timesUsed);
+ do_check_eq(100, firstUsed);
+ do_check_true(lastUsed > 500);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 3));
- // ===== 15 =====
- // Bump an entry that does not exist
- testnum++;
- await promiseUpdate({ op: "bump", fieldname: "field3", value: "value3",
- timesUsed: 10, firstUsed: 50, lastUsed: 400 });
- results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
- { fieldname: "field3", value: "value3" });
- [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
- do_check_eq(10, timesUsed);
- do_check_eq(50, firstUsed);
- do_check_eq(400, lastUsed);
- await promiseCountEntries(null, null, num => do_check_eq(num, 4));
+ // ===== 15 =====
+ // Bump an entry that does not exist
+ testnum++;
+ await promiseUpdate({ op: "bump", fieldname: "field3", value: "value3",
+ timesUsed: 10, firstUsed: 50, lastUsed: 400 });
+ results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
+ { fieldname: "field3", value: "value3" });
+ [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
+ do_check_eq(10, timesUsed);
+ do_check_eq(50, firstUsed);
+ do_check_eq(400, lastUsed);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 4));
- // ===== 16 =====
- // Bump an entry with a guid
- testnum++;
- results = await promiseSearchEntries(["guid"], { fieldname: "field3", value: "value3" });
- guid = processFirstResult(results)[3];
- await promiseUpdate({ op: "bump", guid, timesUsed: 20, firstUsed: 55, lastUsed: 400 });
- results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
- { fieldname: "field3", value: "value3" });
- [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
- do_check_eq(11, timesUsed);
- do_check_eq(50, firstUsed);
- do_check_true(lastUsed > 400);
- await promiseCountEntries(null, null, num => do_check_eq(num, 4));
+ // ===== 16 =====
+ // Bump an entry with a guid
+ testnum++;
+ results = await promiseSearchEntries(["guid"], { fieldname: "field3", value: "value3" });
+ guid = processFirstResult(results)[3];
+ await promiseUpdate({ op: "bump", guid, timesUsed: 20, firstUsed: 55, lastUsed: 400 });
+ results = await promiseSearchEntries(["timesUsed", "firstUsed", "lastUsed"],
+ { fieldname: "field3", value: "value3" });
+ [timesUsed, firstUsed, lastUsed] = processFirstResult(results);
+ do_check_eq(11, timesUsed);
+ do_check_eq(50, firstUsed);
+ do_check_true(lastUsed > 400);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 4));
- // ===== 17 =====
- // Remove an entry
- testnum++;
- await countDeletedEntries(7);
+ // ===== 17 =====
+ // Remove an entry
+ testnum++;
+ await countDeletedEntries(7);
- results = await promiseSearchEntries(["guid"], { fieldname: "field1", value: "value1b" });
- guid = processFirstResult(results)[3];
+ results = await promiseSearchEntries(["guid"], { fieldname: "field1", value: "value1b" });
+ guid = processFirstResult(results)[3];
- await promiseUpdate({ op: "remove", guid});
- await promiseCountEntries("field1", "modifiedValue", checkExists);
- await promiseCountEntries("field1", "value1b", checkNotExists);
- await promiseCountEntries(null, null, num => do_check_eq(num, 3));
+ await promiseUpdate({ op: "remove", guid});
+ await promiseCountEntries("field1", "modifiedValue", checkExists);
+ await promiseCountEntries("field1", "value1b", checkNotExists);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 3));
- await countDeletedEntries(8);
- await checkTimeDeleted(guid, timeDeleted => do_check_true(timeDeleted > 10000));
+ await countDeletedEntries(8);
+ await checkTimeDeleted(guid, timeDeleted => do_check_true(timeDeleted > 10000));
- // ===== 18 =====
- // Add yet another single entry
- testnum++;
- await promiseUpdate({ op: "add", fieldname: "field4", value: "value4",
- timesUsed: 5, firstUsed: 230, lastUsed: 600 });
- await promiseCountEntries(null, null, num => do_check_eq(num, 4));
+ // ===== 18 =====
+ // Add yet another single entry
+ testnum++;
+ await promiseUpdate({ op: "add", fieldname: "field4", value: "value4",
+ timesUsed: 5, firstUsed: 230, lastUsed: 600 });
+ await promiseCountEntries(null, null, num => do_check_eq(num, 4));
- // ===== 19 =====
- // Remove an entry by time
- testnum++;
- await promiseUpdate({ op: "remove", firstUsedStart: 60, firstUsedEnd: 250 });
- await promiseCountEntries("field1", "modifiedValue", checkExists);
- await promiseCountEntries("field2", "value2", checkNotExists);
- await promiseCountEntries("field3", "value3", checkExists);
- await promiseCountEntries("field4", "value4", checkNotExists);
- await promiseCountEntries(null, null, num => do_check_eq(num, 2));
- await countDeletedEntries(10);
+ // ===== 19 =====
+ // Remove an entry by time
+ testnum++;
+ await promiseUpdate({ op: "remove", firstUsedStart: 60, firstUsedEnd: 250 });
+ await promiseCountEntries("field1", "modifiedValue", checkExists);
+ await promiseCountEntries("field2", "value2", checkNotExists);
+ await promiseCountEntries("field3", "value3", checkExists);
+ await promiseCountEntries("field4", "value4", checkNotExists);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 2));
+ await countDeletedEntries(10);
- // ===== 20 =====
- // Bump multiple existing entries at once
- testnum++;
+ // ===== 20 =====
+ // Bump multiple existing entries at once
+ testnum++;
- await promiseUpdate([{ op: "add", fieldname: "field5", value: "value5",
- timesUsed: 5, firstUsed: 230, lastUsed: 600 },
- { op: "add", fieldname: "field6", value: "value6",
- timesUsed: 12, firstUsed: 430, lastUsed: 700 }]);
- await promiseCountEntries(null, null, num => do_check_eq(num, 4));
+ await promiseUpdate([{ op: "add", fieldname: "field5", value: "value5",
+ timesUsed: 5, firstUsed: 230, lastUsed: 600 },
+ { op: "add", fieldname: "field6", value: "value6",
+ timesUsed: 12, firstUsed: 430, lastUsed: 700 }]);
+ await promiseCountEntries(null, null, num => do_check_eq(num, 4));
- await promiseUpdate([
- { op: "bump", fieldname: "field5", value: "value5" },
- { op: "bump", fieldname: "field6", value: "value6" }]);
- results = await promiseSearchEntries(["fieldname", "timesUsed", "firstUsed", "lastUsed"], { });
+ await promiseUpdate([
+ { op: "bump", fieldname: "field5", value: "value5" },
+ { op: "bump", fieldname: "field6", value: "value6" }]);
+ results = await promiseSearchEntries(["fieldname", "timesUsed", "firstUsed", "lastUsed"], { });
- do_check_eq(6, results[2].timesUsed);
- do_check_eq(13, results[3].timesUsed);
- do_check_eq(230, results[2].firstUsed);
- do_check_eq(430, results[3].firstUsed);
- do_check_true(results[2].lastUsed > 600);
- do_check_true(results[3].lastUsed > 700);
+ do_check_eq(6, results[2].timesUsed);
+ do_check_eq(13, results[3].timesUsed);
+ do_check_eq(230, results[2].firstUsed);
+ do_check_eq(430, results[3].firstUsed);
+ do_check_true(results[2].lastUsed > 600);
+ do_check_true(results[3].lastUsed > 700);
- await promiseCountEntries(null, null, num => do_check_eq(num, 4));
+ await promiseCountEntries(null, null, num => do_check_eq(num, 4));
- // ===== 21 =====
- // Check update fails if form history is disabled and the operation is not a
- // pure removal.
- testnum++;
- Services.prefs.setBoolPref("browser.formfill.enable", false);
+ // ===== 21 =====
+ // Check update fails if form history is disabled and the operation is not a
+ // pure removal.
+ testnum++;
+ Services.prefs.setBoolPref("browser.formfill.enable", false);
- // Cannot use arrow functions, see bug 1237961.
- Assert.rejects(promiseUpdate(
- { op: "bump", fieldname: "field5", value: "value5" }),
- function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
- "bumping when form history is disabled should fail");
- Assert.rejects(promiseUpdate(
- { op: "add", fieldname: "field5", value: "value5" }),
- function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
- "Adding when form history is disabled should fail");
- Assert.rejects(promiseUpdate([
- { op: "update", fieldname: "field5", value: "value5" },
- { op: "remove", fieldname: "field5", value: "value5" }
- ]),
- function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
- "mixed operations when form history is disabled should fail");
- Assert.rejects(promiseUpdate([
- null, undefined, "", 1, {},
- { op: "remove", fieldname: "field5", value: "value5" }
- ]),
- function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
- "Invalid entries when form history is disabled should fail");
+ // Cannot use arrow functions, see bug 1237961.
+ Assert.rejects(promiseUpdate(
+ { op: "bump", fieldname: "field5", value: "value5" }),
+ function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
+ "bumping when form history is disabled should fail");
+ Assert.rejects(promiseUpdate(
+ { op: "add", fieldname: "field5", value: "value5" }),
+ function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
+ "Adding when form history is disabled should fail");
+ Assert.rejects(promiseUpdate([
+ { op: "update", fieldname: "field5", value: "value5" },
+ { op: "remove", fieldname: "field5", value: "value5" }
+ ]),
+ function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
+ "mixed operations when form history is disabled should fail");
+ Assert.rejects(promiseUpdate([
+ null, undefined, "", 1, {},
+ { op: "remove", fieldname: "field5", value: "value5" }
+ ]),
+ function(err) { return err.result == Ci.mozIStorageError.MISUSE; },
+ "Invalid entries when form history is disabled should fail");
- // Remove should work though.
- await promiseUpdate([{ op: "remove", fieldname: "field5", value: null },
- { op: "remove", fieldname: null, value: null }]);
- Services.prefs.clearUserPref("browser.formfill.enable");
+ // Remove should work though.
+ await promiseUpdate([{ op: "remove", fieldname: "field5", value: null },
+ { op: "remove", fieldname: null, value: null }]);
+ Services.prefs.clearUserPref("browser.formfill.enable");
} catch (e) {
throw "FAILED in test #" + testnum + " -- " + e;
} finally {
FormHistory._supportsDeletedTable = oldSupportsDeletedTable;
dbConnection.asyncClose(do_test_finished);
}
});
--- a/toolkit/components/satchel/test/unit/test_notify.js
+++ b/toolkit/components/satchel/test/unit/test_notify.js
@@ -11,26 +11,26 @@ var expectedData;
var TestObserver = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
observe(subject, topic, data) {
do_check_eq(topic, "satchel-storage-changed");
do_check_eq(data, expectedNotification);
switch (data) {
- case "formhistory-add":
- case "formhistory-update":
- do_check_true(subject instanceof Ci.nsISupportsString);
- do_check_true(isGUID.test(subject.toString()));
- break;
- case "formhistory-remove":
- do_check_eq(null, subject);
- break;
- default:
- do_throw("Unhandled notification: " + data + " / " + topic);
+ case "formhistory-add":
+ case "formhistory-update":
+ do_check_true(subject instanceof Ci.nsISupportsString);
+ do_check_true(isGUID.test(subject.toString()));
+ break;
+ case "formhistory-remove":
+ do_check_eq(null, subject);
+ break;
+ default:
+ do_throw("Unhandled notification: " + data + " / " + topic);
}
expectedNotification = null;
expectedData = null;
}
};
var testIterator = null;
@@ -42,120 +42,132 @@ function run_test() {
}
function next_test() {
testIterator.next();
}
function* run_test_steps() {
-try {
+ try {
-var testnum = 0;
-var testdesc = "Setup of test form history entries";
+ var testnum = 0;
+ var testdesc = "Setup of test form history entries";
-var entry1 = ["entry1", "value1"];
+ var entry1 = ["entry1", "value1"];
-/* ========== 1 ========== */
-testnum = 1;
-testdesc = "Initial connection to storage module"
+ /* ========== 1 ========== */
+ testnum = 1;
+ testdesc = "Initial connection to storage module"
-yield updateEntry("remove", null, null, next_test);
-yield countEntries(null, null, function(num) { do_check_false(num, "Checking initial DB is empty"); next_test(); });
+ yield updateEntry("remove", null, null, next_test);
+ yield countEntries(null, null, function(num) {
+ do_check_false(num, "Checking initial DB is empty");
+ next_test();
+ });
-// Add the observer
-var os = Cc["@mozilla.org/observer-service;1"].
+ // Add the observer
+ var os = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
-os.addObserver(TestObserver, "satchel-storage-changed");
+ os.addObserver(TestObserver, "satchel-storage-changed");
-/* ========== 2 ========== */
-testnum++;
-testdesc = "addEntry";
+ /* ========== 2 ========== */
+ testnum++;
+ testdesc = "addEntry";
-expectedNotification = "formhistory-add";
-expectedData = entry1;
+ expectedNotification = "formhistory-add";
+ expectedData = entry1;
-yield updateEntry("add", entry1[0], entry1[1], next_test);
-do_check_eq(expectedNotification, null); // check that observer got a notification
+ yield updateEntry("add", entry1[0], entry1[1], next_test);
+ do_check_eq(expectedNotification, null); // check that observer got a notification
-yield countEntries(entry1[0], entry1[1], function(num) { do_check_true(num > 0); next_test(); });
+ yield countEntries(entry1[0], entry1[1], function(num) {
+ do_check_true(num > 0);
+ next_test();
+ });
-/* ========== 3 ========== */
-testnum++;
-testdesc = "modifyEntry";
+ /* ========== 3 ========== */
+ testnum++;
+ testdesc = "modifyEntry";
-expectedNotification = "formhistory-update";
-expectedData = entry1;
-// will update previous entry
-yield updateEntry("update", entry1[0], entry1[1], next_test);
-yield countEntries(entry1[0], entry1[1], function(num) { do_check_true(num > 0); next_test(); });
-
-do_check_eq(expectedNotification, null);
+ expectedNotification = "formhistory-update";
+ expectedData = entry1;
+ // will update previous entry
+ yield updateEntry("update", entry1[0], entry1[1], next_test);
+ yield countEntries(entry1[0], entry1[1], function(num) {
+ do_check_true(num > 0);
+ next_test();
+ });
-/* ========== 4 ========== */
-testnum++;
-testdesc = "removeEntry";
+ do_check_eq(expectedNotification, null);
-expectedNotification = "formhistory-remove";
-expectedData = entry1;
-yield updateEntry("remove", entry1[0], entry1[1], next_test);
+ /* ========== 4 ========== */
+ testnum++;
+ testdesc = "removeEntry";
-do_check_eq(expectedNotification, null);
-yield countEntries(entry1[0], entry1[1], function(num) { do_check_false(num, "doesn't exist after remove"); next_test(); });
+ expectedNotification = "formhistory-remove";
+ expectedData = entry1;
+ yield updateEntry("remove", entry1[0], entry1[1], next_test);
-/* ========== 5 ========== */
-testnum++;
-testdesc = "removeAllEntries";
+ do_check_eq(expectedNotification, null);
+ yield countEntries(entry1[0], entry1[1], function(num) {
+ do_check_false(num, "doesn't exist after remove");
+ next_test();
+ });
-expectedNotification = "formhistory-remove";
-expectedData = null; // no data expected
-yield updateEntry("remove", null, null, next_test);
+ /* ========== 5 ========== */
+ testnum++;
+ testdesc = "removeAllEntries";
-do_check_eq(expectedNotification, null);
-
-/* ========== 6 ========== */
-testnum++;
-testdesc = "removeAllEntries (again)";
+ expectedNotification = "formhistory-remove";
+ expectedData = null; // no data expected
+ yield updateEntry("remove", null, null, next_test);
-expectedNotification = "formhistory-remove";
-expectedData = null;
-yield updateEntry("remove", null, null, next_test);
+ do_check_eq(expectedNotification, null);
-do_check_eq(expectedNotification, null);
+ /* ========== 6 ========== */
+ testnum++;
+ testdesc = "removeAllEntries (again)";
-/* ========== 7 ========== */
-testnum++;
-testdesc = "removeEntriesForName";
+ expectedNotification = "formhistory-remove";
+ expectedData = null;
+ yield updateEntry("remove", null, null, next_test);
-expectedNotification = "formhistory-remove";
-expectedData = "field2";
-yield updateEntry("remove", null, "field2", next_test);
+ do_check_eq(expectedNotification, null);
+
+ /* ========== 7 ========== */
+ testnum++;
+ testdesc = "removeEntriesForName";
-do_check_eq(expectedNotification, null);
+ expectedNotification = "formhistory-remove";
+ expectedData = "field2";
+ yield updateEntry("remove", null, "field2", next_test);
+
+ do_check_eq(expectedNotification, null);
-/* ========== 8 ========== */
-testnum++;
-testdesc = "removeEntriesByTimeframe";
+ /* ========== 8 ========== */
+ testnum++;
+ testdesc = "removeEntriesByTimeframe";
-expectedNotification = "formhistory-remove";
-expectedData = [10, 99999999999];
+ expectedNotification = "formhistory-remove";
+ expectedData = [10, 99999999999];
-yield FormHistory.update({ op: "remove", firstUsedStart: expectedData[0], firstUsedEnd: expectedData[1] },
- { handleCompletion(reason) {
- if (!reason) {
- next_test()
- }
- },
- handleErrors(error) {
- do_throw("Error occurred updating form history: " + error);
- }
- });
+ yield FormHistory.update({ op: "remove", firstUsedStart: expectedData[0], firstUsedEnd: expectedData[1] },
+ { handleCompletion(reason) {
+ if (!reason) {
+ next_test()
+ }
+ },
+ handleErrors(error) {
+ do_throw("Error occurred updating form history: " + error);
+ }
+ });
-do_check_eq(expectedNotification, null);
+ do_check_eq(expectedNotification, null);
-os.removeObserver(TestObserver, "satchel-storage-changed");
+ os.removeObserver(TestObserver, "satchel-storage-changed");
-do_test_finished();
+ do_test_finished();
-} catch (e) {
+ } catch (e) {
throw "FAILED in test #" + testnum + " -- " + testdesc + ": " + e;
+ }
}
-}