test_dom_activate_event.html (3784B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test DOMActivate event</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <script src="/tests/SimpleTest/EventUtils.js"></script> 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 8 </head> 9 <body> 10 <p id="display"> 11 <a id="a" href="#dummy">link</a> 12 <button id="button">button</button> 13 <input id="checkbox" type="checkbox"> 14 <input id="radio" type="radio"> 15 <input id="submit" type="submit"> 16 <input id="ibutton" type="button"> 17 <input id="reset" type="reset"> 18 </p> 19 <div id="content" style="display: none"> 20 21 </div> 22 <pre id="test"> 23 <script type="application/javascript"> 24 25 /* eslint-disable max-nested-callbacks */ 26 27 SimpleTest.waitForExplicitFinish(); 28 SimpleTest.waitForFocus(runTests); 29 30 function runIsTrustedTestCausedByTrustedClick(aElement, aNextTest) 31 { 32 const kDescription = "runIsTrustedTestCausedByTrustedClick(aElement.id=" + aElement.id + "): "; 33 var DOMActivateFired = false; 34 aElement.addEventListener("DOMActivate", function (aEvent) { 35 DOMActivateFired = true; 36 ok(aEvent.isTrusted, kDescription + "DOMActivate event should be trusted event"); 37 aElement.removeEventListener("DOMActivate", arguments.callee); 38 aNextTest(); 39 }); 40 aElement.addEventListener("click", function (aEvent) { 41 ok(aEvent.isTrusted, kDescription + "click event should be trusted event"); 42 aElement.removeEventListener("click", arguments.callee); 43 }); 44 synthesizeMouseAtCenter(aElement, {}); 45 } 46 47 function runIsTrustedTestCausedByUntrustedClick(aElement, aNextTest) 48 { 49 const kDescription = "runIsTrustedTestCausedByUntrustedClick(aElement.id=" + aElement.id + "): "; 50 var DOMActivateFired = false; 51 aElement.addEventListener("DOMActivate", function (aEvent) { 52 DOMActivateFired = true; 53 ok(aEvent.isTrusted, 54 kDescription + "DOMActivate event should be trusted event even if it's caused by untrusted event"); 55 aElement.removeEventListener("DOMActivate", arguments.callee); 56 aNextTest(); 57 }); 58 aElement.addEventListener("click", function (aEvent) { 59 ok(!aEvent.isTrusted, kDescription + "click event should be untrusted event"); 60 aElement.removeEventListener("click", arguments.callee); 61 }); 62 var click = new MouseEvent("click", { button: 0 }); 63 aElement.dispatchEvent(click); 64 } 65 66 function runTests() 67 { 68 // XXX Don't add indentation here. If you add indentation, the diff will be 69 // complicated when somebody adds new tests. 70 runIsTrustedTestCausedByTrustedClick(document.getElementById("a"), function () { 71 runIsTrustedTestCausedByTrustedClick(document.getElementById("button"), function () { 72 runIsTrustedTestCausedByTrustedClick(document.getElementById("checkbox"), function () { 73 runIsTrustedTestCausedByTrustedClick(document.getElementById("radio"), function () { 74 runIsTrustedTestCausedByTrustedClick(document.getElementById("submit"), function () { 75 runIsTrustedTestCausedByTrustedClick(document.getElementById("ibutton"), function () { 76 runIsTrustedTestCausedByTrustedClick(document.getElementById("reset"), function () { 77 runIsTrustedTestCausedByUntrustedClick(document.getElementById("a"), function () { 78 runIsTrustedTestCausedByUntrustedClick(document.getElementById("button"), function () { 79 runIsTrustedTestCausedByUntrustedClick(document.getElementById("checkbox"), function () { 80 runIsTrustedTestCausedByUntrustedClick(document.getElementById("radio"), function () { 81 runIsTrustedTestCausedByUntrustedClick(document.getElementById("submit"), function () { 82 runIsTrustedTestCausedByUntrustedClick(document.getElementById("ibutton"), function () { 83 runIsTrustedTestCausedByUntrustedClick(document.getElementById("reset"), function () { 84 SimpleTest.finish(); 85 });});});});});});});});});});});});});}); 86 } 87 88 </script> 89 </pre> 90 </body> 91 </html>