зеркало из https://github.com/mozilla/pjs.git
Bug 599628 - Fix test timeout for Gecko consumers without invalidformsubmit observers. r=callek a=test
This commit is contained in:
Родитель
61bc265749
Коммит
a304794495
|
@ -40,74 +40,76 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=561636
|
|||
|
||||
/** Test for Bug 561636 **/
|
||||
|
||||
var formSubmitted = [ false, false ];
|
||||
var invalidHandled = false;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var os = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
var observers = os.enumerateObservers("invalidformsubmit");
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function runTest()
|
||||
{
|
||||
var formSubmitted = [ false, false ];
|
||||
var invalidHandled = false;
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var os = Components.classes['@mozilla.org/observer-service;1']
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
var observers = os.enumerateObservers("invalidformsubmit");
|
||||
|
||||
// The following test should not be done if there is no observer for
|
||||
// "invalidformsubmit" because the form submission will not be canceled in that
|
||||
// case.
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
if (observers.hasMoreElements()) {
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// Initialize
|
||||
document.forms[0].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[0] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[1].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[1] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[2].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[2] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[3].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[3] = true;
|
||||
|
||||
ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid");
|
||||
ok(!formSubmitted[1], "Form 2 should not have been submitted because invalid");
|
||||
ok(!formSubmitted[2], "Form 3 should not have been submitted because invalid");
|
||||
ok(formSubmitted[3], "Form 4 should have been submitted because valid");
|
||||
|
||||
// Next test.
|
||||
document.forms[4].submit();
|
||||
}, false);
|
||||
|
||||
document.forms[4].elements[0].addEventListener('invalid', function(aEvent) {
|
||||
aEvent.target.removeEventListener('invalid', arguments.callee, false);
|
||||
invalidHandled = true;
|
||||
}, false);
|
||||
|
||||
document.getElementById('i').addEventListener('load', function(aEvent) {
|
||||
aEvent.target.removeEventListener('load', arguments.callee, false);
|
||||
|
||||
SimpleTest.executeSoon(function () {
|
||||
ok(true, "Form 5 should have been submitted because submit() has been used even if invalid");
|
||||
ok(!invalidHandled, "Invalid event should not have been sent");
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.getElementById('a').click();
|
||||
document.getElementById('b').click();
|
||||
var c = document.getElementById('c');
|
||||
c.focus(); synthesizeKey("VK_RETURN", {type: "keypress"});
|
||||
document.getElementById('s2').click();
|
||||
if (!observers.hasMoreElements()) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.forms[0].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[0] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[1].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[1] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[2].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[2] = true;
|
||||
}, false);
|
||||
|
||||
document.forms[3].addEventListener('submit', function(aEvent) {
|
||||
aEvent.target.removeEventListener('submit', arguments.callee, false);
|
||||
formSubmitted[3] = true;
|
||||
|
||||
ok(!formSubmitted[0], "Form 1 should not have been submitted because invalid");
|
||||
ok(!formSubmitted[1], "Form 2 should not have been submitted because invalid");
|
||||
ok(!formSubmitted[2], "Form 3 should not have been submitted because invalid");
|
||||
ok(formSubmitted[3], "Form 4 should have been submitted because valid");
|
||||
|
||||
// Next test.
|
||||
document.forms[4].submit();
|
||||
}, false);
|
||||
|
||||
document.forms[4].elements[0].addEventListener('invalid', function(aEvent) {
|
||||
aEvent.target.removeEventListener('invalid', arguments.callee, false);
|
||||
invalidHandled = true;
|
||||
}, false);
|
||||
|
||||
document.getElementById('i').addEventListener('load', function(aEvent) {
|
||||
aEvent.target.removeEventListener('load', arguments.callee, false);
|
||||
|
||||
SimpleTest.executeSoon(function () {
|
||||
ok(true, "Form 5 should have been submitted because submit() has been used even if invalid");
|
||||
ok(!invalidHandled, "Invalid event should not have been sent");
|
||||
|
||||
SimpleTest.finish();
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.getElementById('a').click();
|
||||
document.getElementById('b').click();
|
||||
var c = document.getElementById('c');
|
||||
c.focus(); synthesizeKey("VK_RETURN", {type: "keypress"});
|
||||
document.getElementById('s2').click();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче