1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
4 <script src=
"../../resources/js-test.js"></script>
7 <p id=
"description"></p>
8 <div id=
"console"></div>
10 function $(id
) { return document
.getElementById(id
); }
11 function focusOn(id
) {
15 description('Tests for reportValidity() with invalid event canceling');
17 var parent
= document
.createElement('div');
18 document
.body
.appendChild(parent
);
19 parent
.innerHTML
= '<form><input id=input-unset name=i required><input id=input2></form>';
20 var form
= parent
.firstChild
;
21 var input
= form
.firstChild
;
23 debug('"invalid" event is not canceled.');
24 var invalidFired
= false;
25 var nothingListener
= {};
26 nothingListener
.handleEvent = function(event
) {
30 shouldBeTrue('input.addEventListener("invalid", nothingListener, false); !input.reportValidity() && invalidFired');
31 shouldBe('document.activeElement', '$("input-unset")');
33 shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
34 shouldBe('document.activeElement', '$("input-unset")');
35 input
.removeEventListener('invalid', nothingListener
, false);
38 debug('"invalid" event is canceled.');
40 var cancelListener
= {};
41 cancelListener
.handleEvent = function(event
) {
43 event
.preventDefault();
45 // Even if 'invalid' is canceled, the input.reportValidity() result is still false.
47 shouldBeTrue('input.addEventListener("invalid", cancelListener, false); !input.reportValidity() && invalidFired');
48 shouldNotBe('document.activeElement', '$("input-unset")');
49 // form.reportValidity() also should be false.
50 shouldBeTrue('invalidFired = false; !form.reportValidity() && invalidFired');
51 shouldNotBe('document.activeElement', '$("input-unset")');