Bug 552828 - update Form History to work with Electrolysis [r=dolske]

This commit is contained in:
Benjamin Stover 2010-08-16 21:10:36 -07:00
parent 87f1cb0c48
commit b67eb1a272
8 changed files with 404 additions and 214 deletions

View File

@ -0,0 +1,3 @@
toolkit.jar:
% content satchel %content/satchel/
* content/satchel/formSubmitListener.js (src/formSubmitListener.js)

View File

@ -0,0 +1,199 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Mozilla Foundation.
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Justin Dolske <dolske@mozilla.com>
* Paul OShannessy <paul@oshannessy.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
const satchelFormListener = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormSubmitObserver,
Ci.nsObserver,
Ci.nsISupportsWeakReference]),
debug : true,
enabled : true,
saveHttpsForms : true,
init : function() {
Services.obs.addObserver(this, "earlyformsubmit", false);
let prefBranch = Services.prefs.getBranch("browser.formfill.");
prefBranch.QueryInterface(Ci.nsIPrefBranch2);
prefBranch.addObserver("", this, true);
this.updatePrefs();
},
updatePrefs : function () {
let prefBranch = Services.prefs.getBranch("browser.formfill.");
this.debug = prefBranch.getBoolPref("debug");
this.enabled = prefBranch.getBoolPref("enable");
this.saveHttpsForms = prefBranch.getBoolPref("saveHttpsForms");
},
// Implements the Luhn checksum algorithm as described at
// http://wikipedia.org/wiki/Luhn_algorithm
isValidCCNumber : function (ccNumber) {
// Remove dashes and whitespace
ccNumber = ccNumber.replace(/[\-\s]/g, '');
let len = ccNumber.length;
if (len != 9 && len != 15 && len != 16)
return false;
if (!/^\d+$/.test(ccNumber))
return false;
let total = 0;
for (let i = 0; i < len; i++) {
let ch = parseInt(ccNumber[len - i - 1]);
if (i % 2 == 1) {
// Double it, add digits together if > 10
ch *= 2;
if (ch > 9)
ch -= 9;
}
total += ch;
}
return total % 10 == 0;
},
log : function (message) {
if (!this.debug)
return;
dump("satchelFormListener: " + message + "\n");
Services.console.logStringMessage("satchelFormListener: " + message);
},
/* ---- nsIObserver interface ---- */
observe : function (subject, topic, data) {
if (topic == "nsPref:changed")
this.updatePrefs();
else
this.log("Oops! Unexpected notification: " + topic);
},
/* ---- nsIFormSubmitObserver interfaces ---- */
notify : function(form, domWin, actionURI, cancelSubmit) {
try {
// Even though the global context is for a specific browser, we
// can receive observer events from other tabs! Ensure this event
// is about our content.
if (domWin.top != content)
return;
if (!this.enabled)
return;
this.log("Form submit observer notified.");
if (!this.saveHttpsForms) {
if (actionURI.schemeIs("https"))
return;
if (form.ownerDocument.documentURIObject.schemeIs("https"))
return;
}
if (form.hasAttribute("autocomplete") &&
form.getAttribute("autocomplete").toLowerCase() == "off")
return;
let entries = [];
for (let i = 0; i < form.elements.length; i++) {
let input = form.elements[i];
if (!(input instanceof Ci.nsIDOMHTMLInputElement))
continue;
// Only use inputs that hold text values (not including type="password")
if (!input.mozIsTextField(true))
continue;
// Bug 394612: If Login Manager marked this input, don't save it.
// The login manager will deal with remembering it.
// Don't save values when autocomplete=off is present.
if (input.hasAttribute("autocomplete") &&
input.getAttribute("autocomplete").toLowerCase() == "off")
continue;
let value = input.value.trim();
// Don't save empty or unchanged values.
if (!value || value == input.defaultValue.trim())
continue;
// Don't save credit card numbers.
if (this.isValidCCNumber(value)) {
this.log("skipping saving a credit card number");
continue;
}
let name = input.name || input.id;
if (!name)
continue;
// Limit stored data to 200 characters.
if (name.length > 200 || value.length > 200) {
this.log("skipping input that has a name/value too large");
continue;
}
// Limit number of fields stored per form.
if (entries.length >= 100) {
this.log("not saving any more entries for this form.");
break;
}
entries.push({ name: name, value: value });
}
if (entries.length) {
this.log("sending entries to parent process for form " + form.id);
sendAsyncMessage("FormHistory:FormSubmitEntries", entries);
}
}
catch (e) {
this.log("notify failed: " + e);
}
}
};
satchelFormListener.init();

View File

@ -52,12 +52,14 @@ function FormHistory() {
FormHistory.prototype = {
classID : Components.ID("{0c1bb408-71a2-403f-854a-3a0659829ded}"),
QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormHistory2, Ci.nsIObserver, Ci.nsIFormSubmitObserver, Ci.nsISupportsWeakReference]),
QueryInterface : XPCOMUtils.generateQI([Ci.nsIFormHistory2,
Ci.nsIObserver,
Ci.nsIFrameMessageListener,
Ci.nsISupportsWeakReference]),
debug : true,
enabled : true,
saveHttpsForms : true,
prefBranch : null,
// The current database schema.
dbSchema : {
@ -124,15 +126,21 @@ FormHistory.prototype = {
init : function() {
let self = this;
this.prefBranch = Services.prefs.getBranch("browser.formfill.");
this.prefBranch.QueryInterface(Ci.nsIPrefBranch2);
this.prefBranch.addObserver("", this, true);
let prefBranch = Services.prefs.getBranch("browser.formfill.");
prefBranch = prefBranch.QueryInterface(Ci.nsIPrefBranch2);
prefBranch.addObserver("", this, true);
this.updatePrefs();
this.dbStmts = {};
this.messageManager = Cc["@mozilla.org/globalmessagemanager;1"].
getService(Ci.nsIChromeFrameMessageManager);
this.messageManager.loadFrameScript("chrome://satchel/content/formSubmitListener.js", true);
this.messageManager.addMessageListener("FormHistory:FormSubmitEntries", this);
// Add observers
Services.obs.addObserver(this, "earlyformsubmit", false);
Services.obs.addObserver(function() { self.expireOldEntries() }, "idle-daily", false);
Services.obs.addObserver(function() { self.expireOldEntries() }, "formhistory-expire-now", false);
@ -155,6 +163,26 @@ FormHistory.prototype = {
},
/* ---- message listener ---- */
receiveMessage: function receiveMessage(message) {
// Open a transaction so multiple adds happen in one commit
this.dbConnection.beginTransaction();
try {
let entries = message.json;
for (let i = 0; i < entries.length; i++) {
this.addEntry(entries[i].name, entries[i].value);
}
} finally {
// Don't need it to be atomic if there was an error. Commit what
// we managed to put in the table.
this.dbConnection.commitTransaction();
}
},
/* ---- nsIFormHistory2 interfaces ---- */
@ -173,10 +201,10 @@ FormHistory.prototype = {
let now = Date.now() * 1000; // microseconds
let [id, guid] = this.getExistingEntryID(name, value);
let stmt;
if (id != -1) {
// Update existing entry
let stmt;
let query = "UPDATE moz_formhistory SET timesUsed = timesUsed + 1, lastUsed = :lastUsed WHERE id = :id";
let params = {
lastUsed : now,
@ -360,87 +388,6 @@ FormHistory.prototype = {
},
/* ---- nsIFormSubmitObserver interfaces ---- */
notify : function(form, domWin, actionURI, cancelSubmit) {
if (!this.enabled)
return;
this.log("Form submit observer notified.");
if (!this.saveHttpsForms) {
if (actionURI.schemeIs("https"))
return;
if (form.ownerDocument.documentURIObject.schemeIs("https"))
return;
}
if (form.hasAttribute("autocomplete") &&
form.getAttribute("autocomplete").toLowerCase() == "off")
return;
// Open a transaction so that multiple additions are efficient.
this.dbConnection.beginTransaction();
try {
let savedCount = 0;
for (let i = 0; i < form.elements.length; i++) {
let input = form.elements[i];
if (!(input instanceof Ci.nsIDOMHTMLInputElement))
continue;
// Only use inputs that hold text values (not including type="password")
if (!input.mozIsTextField(true))
continue;
// Bug 394612: If Login Manager marked this input, don't save it.
// The login manager will deal with remembering it.
// Don't save values when autocomplete=off is present.
if (input.hasAttribute("autocomplete") &&
input.getAttribute("autocomplete").toLowerCase() == "off")
continue;
let value = input.value.trim();
// Don't save empty or unchanged values.
if (!value || value == input.defaultValue.trim())
continue;
// Don't save credit card numbers.
if (this.isValidCCNumber(value)) {
this.log("skipping saving a credit card number");
continue;
}
let name = input.name || input.id;
if (!name)
continue;
// Limit stored data to 200 characters.
if (name.length > 200 || value.length > 200) {
this.log("skipping input that has a name/value too large");
continue;
}
// Limit number of fields stored per form.
if (savedCount++ >= 100) {
this.log("not saving any more entries for this form.");
break;
}
this.addEntry(name, value);
}
} catch (e) {
// Empty
} finally {
// Save whatever we've added so far.
this.dbConnection.commitTransaction();
}
},
/* ---- helpers ---- */
@ -564,7 +511,8 @@ FormHistory.prototype = {
// Determine how many days of history we're supposed to keep.
let expireDays = 180;
try {
expireDays = this.prefBranch.getIntPref("expire_days");
let prefBranch = Services.prefs.getBranch("browser.formfill.");
expireDays = prefBranch.getIntPref("expire_days");
} catch (e) { /* ignore */ }
let expireTime = Date.now() - expireDays * DAY_IN_MS;
@ -603,41 +551,12 @@ FormHistory.prototype = {
updatePrefs : function () {
this.debug = this.prefBranch.getBoolPref("debug");
this.enabled = this.prefBranch.getBoolPref("enable");
this.saveHttpsForms = this.prefBranch.getBoolPref("saveHttpsForms");
let prefBranch = Services.prefs.getBranch("browser.formfill.");
this.debug = prefBranch.getBoolPref("debug");
this.enabled = prefBranch.getBoolPref("enable");
this.saveHttpsForms = prefBranch.getBoolPref("saveHttpsForms");
},
// Implements the Luhn checksum algorithm as described at
// http://wikipedia.org/wiki/Luhn_algorithm
isValidCCNumber : function (ccNumber) {
// Remove dashes and whitespace
ccNumber = ccNumber.replace(/[\-\s]/g, '');
let len = ccNumber.length;
if (len != 9 && len != 15 && len != 16)
return false;
if (!/^\d+$/.test(ccNumber))
return false;
let total = 0;
for (let i = 0; i < len; i++) {
let ch = parseInt(ccNumber[len - i - 1]);
if (i % 2 == 1) {
// Double it, add digits together if > 10
ch *= 2;
if (ch > 9)
ch -= 9;
}
total += ch;
}
return total % 10 == 0;
},
//**************************************************************************//
// Database Creation & Access

View File

@ -35,6 +35,11 @@
*
* ***** END LICENSE BLOCK ***** */
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
/*
* $_
*
@ -112,3 +117,60 @@ function cleanUpFormHist() {
formhist.removeAllEntries();
}
cleanUpFormHist();
var checkObserver = {
verifyStack: [],
callback: null,
waitForChecks: function(callback) {
if (this.verifyStack.length == 0)
callback();
else
this.callback = callback;
},
observe: function(subject, topic, data) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (data != "addEntry" && data != "modifyEntry")
return;
ok(this.verifyStack.length > 0, "checking if saved form data was expected");
// Make sure that every piece of data we expect to be saved is saved, and no
// more. Here it is assumed that for every entry satchel saves or modifies, a
// message is sent.
//
// We don't actually check the content of the message, but just that the right
// quantity of messages is received.
// - 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();
ok(fh.entryExists(expected.name, expected.value), expected.message);
if (this.verifyStack.length == 0) {
var callback = this.callback;
this.callback = null;
callback();
}
}
};
function checkForSave(name, value, message) {
checkObserver.verifyStack.push({ name : name, value: value, message: message });
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
return button;
}

View File

@ -1,9 +1,38 @@
<form id="subform">
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form id="subform1" onsubmit="return checkSubmit(21)">
<input id="subtest1" type="text" name="subtest1">
<button type="submit">Submit</button>
</form>
<form id="subform2" onsubmit="return checkSubmit(100)">
<input id="subtest2" type="text" name="subtest2">
<button type="submit">Submit</button>
</form>
<script>
function checkSubmit(num) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
return parent.checkSubmit(num);
}
function clickButton(num) {
if (num == 21)
document.querySelectorAll("button")[0].click();
else if (num == 100)
document.querySelectorAll("button")[1].click();
}
// set the input's value (can't use a default value, as satchel will ignore it)
document.getElementById("subtest1").value = "subtestValue";
document.getElementById("subtest2").value = "subtestValue";
</script>
</body>
</html>

View File

@ -9,6 +9,7 @@
</head>
<body>
<p id="display"></p>
<iframe id="iframe" src="https://example.com/tests/toolkit/components/satchel/test/subtst_form_submission_1.html"></iframe>
<div id="content" style="display: none">
<!-- ===== Things that should not be saved. ===== -->
@ -222,9 +223,6 @@
<button type="submit">Submit</button>
</form>
<iframe id="iframe1" src="https://example.com/tests/toolkit/components/satchel/test/subtst_form_submission_1.html"></iframe>
<iframe id="iframe2" src="https://example.com/tests/toolkit/components/satchel/test/subtst_form_submission_1.html"></iframe>
<!-- form data submitted through HTTPS, when browser.formfill.saveHttpsForms is true -->
<form id="form109" action="https://www.example.com/" onsubmit="return checkSubmit(109)">
<input type="text" name="test9">
@ -347,7 +345,7 @@ function checkSubmit(formNum) {
ok(true, "form " + formNum + " submitted");
numSubmittedForms++;
// Check for expected storage state.
switch (formNum) {
// Test 1-20 should not save anything.
@ -371,75 +369,63 @@ function checkSubmit(formNum) {
case 18:
case 19:
case 20:
case 21:
ok(!fh.hasEntries, "checking for empty storage");
break;
// The other tests do save data...
case 100:
checkForSave("subtest2", "subtestValue", "checking saved subtest value");
break;
case 101:
ok(fh.entryExists("test1", "savedValue"), "checking saved value");
checkForSave("test1", "savedValue", "checking saved value");
break;
case 102:
ok(fh.entryExists("test2", "savedValue"), "checking saved value");
checkForSave("test2", "savedValue", "checking saved value");
break;
case 103:
ok(fh.entryExists("test3", "savedValue"), "checking saved value");
checkForSave("test3", "savedValue", "checking saved value");
break;
case 104:
ok(fh.entryExists("test4", "trimTrailingAndLeadingSpace"), "checking saved value is trimmed on both sides");
checkForSave("test4", "trimTrailingAndLeadingSpace", "checking saved value is trimmed on both sides");
break;
case 105:
ok(fh.entryExists("test5", "trimTrailingAndLeadingWhitespace"), "checking saved value is trimmed on both sides");
checkForSave("test5", "trimTrailingAndLeadingWhitespace", "checking saved value is trimmed on both sides");
break;
case 106:
ok(fh.entryExists("test6", "00000000109181"), "checking saved value");
checkForSave("test6", "00000000109181", "checking saved value");
break;
case 107:
for (var i = 0; i != ccNumbers.invalid16.length; i++) {
ok(fh.entryExists("test7_" + (i + 1), ccNumbers.invalid16[i]), "checking saved value");
checkForSave("test7_" + (i + 1), ccNumbers.invalid16[i], "checking saved value");
}
break;
case 108:
for (var i = 0; i != ccNumbers.invalid15.length; i++) {
ok(fh.entryExists("test8_" + (i + 1), ccNumbers.invalid15[i]), "checking saved value");
checkForSave("test8_" + (i + 1), ccNumbers.invalid15[i], "checking saved value");
}
break;
case 109:
ok(fh.entryExists("test9", "savedValue"), "checking saved value");
checkForSave("test9", "savedValue", "checking saved value");
break;
case 110:
ok(fh.entryExists("test10", "savedValue"), "checking saved value");
checkForSave("test10", "savedValue", "checking saved value");
break;
default:
ok(false, "Unexpected form submission");
break;
}
// Forms 13 and 14 would trigger a save-password notification. Tempoarily
// Forms 13 and 14 would trigger a save-password notification. Temporarily
// disable pwmgr, then reenable it.
if (formNum == 12)
prefBranch.setBoolPref("signon.rememberSignons", false);
if (formNum == 14)
prefBranch.clearUserPref("signon.rememberSignons");
// Form 20 requires browser.formfill.saveHttpsForms to be false
// Run a couple subtests here, which submit forms from an HTTPS origin,
// these are loaded in iframes since the test suite isn't HTTPS. The subtest
// before the pref change should save a value, the (same) subtest run after
// the pref change should not.
if (formNum == 19) {
ok(true, "submitting subtest1");
var iframe = document.getElementById("iframe1");
iframe.contentDocument.forms[0].submit();
ok(fh.entryExists("subtest1", "subtestValue"), "checking saved subtest value");
fh.removeEntriesForName("subtest1");
// Forms 20 and 21 requires browser.formfill.saveHttpsForms to be false
if (formNum == 19)
prefBranch.setBoolPref("browser.formfill.saveHttpsForms", false);
ok(true, "submitting subtest1");
iframe = document.getElementById("iframe2");
iframe.contentDocument.forms[0].submit();
ok(!fh.entryExists("subtest1", "subtestValue"), "checking unsaved subtest value");
}
if (formNum == 20)
// Reset preference now that 20 and 21 are over
if (formNum == 21)
prefBranch.clearUserPref("browser.formfill.saveHttpsForms");
// Form 109 requires browser.formfill.save_https_forms to be true;
@ -453,32 +439,42 @@ function checkSubmit(formNum) {
// End the test at the last form.
if (formNum == 110) {
is(numSubmittedForms, 30, "Ensuring all forms were submitted.");
is(numSubmittedForms, 32, "Ensuring all forms were submitted.");
Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
SimpleTest.finish();
return false; // return false to cancel current form submission
}
// submit the next form.
var button = getFormSubmitButton(formNum == 20 ? 101 : (formNum + 1));
button.click();
// This timeout is here so that button.click() is never called before this
// function returns. If button.click() is called before returning, a long
// chain of submits will happen recursively since the submit is dispatched
// immediately.
//
// This in itself is fine, but if there are errors in the code, mochitests
// will in some cases give you "server too busy", which is hard to debug!
//
setTimeout(function() {
checkObserver.waitForChecks(function() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var nextFormNum = formNum == 21 ? 100 : (formNum + 1);
// Submit the next form. Special cases are Forms 21 and 100, which happen
// from an HTTPS domain in an iframe.
if (nextFormNum == 21 || nextFormNum == 100) {
ok(true, "submitting iframe test " + nextFormNum);
document.getElementById("iframe").contentWindow.clickButton(nextFormNum);
}
else {
var button = getFormSubmitButton(nextFormNum);
button.click();
}
});
}, 0);
return false; // cancel current form submission
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
return button;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var fh = Components.classes["@mozilla.org/satchel/form-history;1"].
@ -488,6 +484,8 @@ ok(fh != null, "Got formHistory service");
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefBranch);
Services.obs.addObserver(checkObserver, "satchel-storage-changed", false);
window.onload = startTest;
SimpleTest.waitForExplicitFinish();

View File

@ -63,41 +63,27 @@ function checkSubmit(formNum) {
// check that the first (numInputFields - 1) CHANGED fields are saved
for (i = 1; i < numInputFields; i++) { // check all but last
ok(fh.entryExists("test" + i, i), "checking saved value " + i);
checkForSave("test" + i, i, "checking saved value " + i);
}
// make sure that the remaining changed fields are not saved
ok(!fh.entryExists("test" + numInputFields, numInputFields), "checking unsaved value " + numInputFields);
// End the test at the last form.
if (formNum == 1) {
is(numSubmittedForms, 1, "Ensuring all forms were submitted.");
Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
SimpleTest.finish();
return false; // return false to cancel current form submission
}
// submit the next form.
var button = getFormSubmitButton(formNum + 1);
button.click();
checkObserver.waitForChecks(function() {
// submit the next form.
var button = getFormSubmitButton(formNum + 1);
button.click();
});
return false; // cancel current form submission
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
return button;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var fh = Components.classes["@mozilla.org/satchel/form-history;1"].
@ -106,6 +92,8 @@ ok(fh != null, "Got formHistory service");
window.onload = startTest;
Services.obs.addObserver(checkObserver, "satchel-storage-changed", false);
SimpleTest.waitForExplicitFinish();
</script>

View File

@ -155,37 +155,27 @@ function checkSubmit(formNum) {
}
// make sure that the field # numInputFields was saved
ok(fh.entryExists("test" + numInputFields, numInputFields + " changed"), "checking saved value " + numInputFields);
checkForSave("test" + numInputFields, numInputFields + " changed", "checking saved value " + numInputFields);
// End the test at the last form.
if (formNum == 1) {
is(numSubmittedForms, 1, "Ensuring all forms were submitted.");
Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
SimpleTest.finish();
return false; // return false to cancel current form submission
}
// submit the next form.
var button = getFormSubmitButton(formNum + 1);
button.click();
checkObserver.waitForChecks(function() {
// submit the next form.
var button = getFormSubmitButton(formNum + 1);
button.click();
});
return false; // cancel current form submission
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
ok(form != null, "getting form " + formNum);
// we can't just call form.submit(), because that doesn't seem to
// invoke the form onsubmit handler.
var button = form.firstChild;
while (button && button.type != "submit") { button = button.nextSibling; }
ok(button != null, "getting form submit button");
return button;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var fh = Components.classes["@mozilla.org/satchel/form-history;1"].
@ -194,6 +184,8 @@ ok(fh != null, "Got formHistory service");
window.onload = startTest;
Services.obs.addObserver(checkObserver, "satchel-storage-changed", false);
SimpleTest.waitForExplicitFinish();
</script>