зеркало из https://github.com/mozilla/gecko-dev.git
Bug 976940 - FormHistory.update() should throw if form history is disabled and the operation is not a removal. r=markh
MozReview-Commit-ID: 94FRqGofGsP --HG-- extra : rebase_source : 9911e4bbc3efd8c4b527757e8eeac42bcf010840
This commit is contained in:
Родитель
4a6a66c87e
Коммит
c8473630a5
|
@ -842,10 +842,6 @@ this.FormHistory = {
|
|||
},
|
||||
|
||||
update : function formHistoryUpdate(aChanges, aCallbacks) {
|
||||
if (!Prefs.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Used to keep track of how many searches have been started. When that number
|
||||
// are finished, updateFormHistoryWrite can be called.
|
||||
let numSearches = 0;
|
||||
|
@ -860,6 +856,13 @@ this.FormHistory = {
|
|||
if (!("length" in aChanges))
|
||||
aChanges = [aChanges];
|
||||
|
||||
let isRemoveOperation = aChanges.every(change => change && change.op && change.op == "remove");
|
||||
if (!Prefs.enabled && !isRemoveOperation) {
|
||||
throw Components.Exception(
|
||||
"Form history is disabled, only remove operations are allowed",
|
||||
Cr.NS_ERROR_ILLEGAL_VALUE);
|
||||
}
|
||||
|
||||
for (let change of aChanges) {
|
||||
switch (change.op) {
|
||||
case "remove":
|
||||
|
|
|
@ -405,6 +405,36 @@ add_task(function* ()
|
|||
|
||||
yield promiseCountEntries(null, null, num => do_check_eq(num, 4));
|
||||
|
||||
// ===== 21 =====
|
||||
// Check update throws if form history is disabled and the operation is not a
|
||||
// pure removal.
|
||||
testnum++;
|
||||
Services.prefs.setBoolPref("browser.formfill.enable", false);
|
||||
Assert.throws(() => promiseUpdate(
|
||||
{ op : "bump", fieldname: "field5", value: "value5" }),
|
||||
/NS_ERROR_ILLEGAL_VALUE/);
|
||||
Assert.throws(() => promiseUpdate(
|
||||
{ op : "add", fieldname: "field5", value: "value5" }),
|
||||
/NS_ERROR_ILLEGAL_VALUE/);
|
||||
Assert.throws(() => promiseUpdate([
|
||||
{ op : "update", fieldname: "field5", value: "value5" },
|
||||
{ op : "remove", fieldname: "field5", value: "value5" }
|
||||
]),
|
||||
/NS_ERROR_ILLEGAL_VALUE/);
|
||||
Assert.throws(() => promiseUpdate([
|
||||
null,
|
||||
undefined,
|
||||
"",
|
||||
1,
|
||||
{},
|
||||
{ op : "remove", fieldname: "field5", value: "value5" }
|
||||
]),
|
||||
/NS_ERROR_ILLEGAL_VALUE/);
|
||||
// Remove should work though.
|
||||
yield 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;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче