test_bug666604.html (3451B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=666604 5 --> 6 <head> 7 <title>Test for Bug 666604</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=666604">Mozilla Bug 666604</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <a href="javascript:activationListener()" id="testlink">test</a> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 666604 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 25 function hitEventLoop(times, next) 26 { 27 if (times == 0) { 28 next(); 29 return; 30 } 31 32 SimpleTest.executeSoon(function() { 33 hitEventLoop(times - 1, next); 34 }); 35 } 36 37 var activationListener; 38 39 function dispatchClick(target, ctrl) { 40 var e = document.createEvent("MouseEvent"); 41 e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, 42 ctrl, false, false, false, 0, null); 43 target.dispatchEvent(e); 44 } 45 46 function dispatchReturn(target, ctrl) { 47 var e = new KeyboardEvent("keypress", { 48 bubbles: true, 49 cancelable: true, 50 view: window, 51 ctrlKey: ctrl, 52 keyCode: 13, 53 charCode: 0, 54 }); 55 target.dispatchEvent(e); 56 } 57 58 function dispatchDOMActivate(target) { 59 var e = document.createEvent("UIEvent"); 60 e.initUIEvent("DOMActivate", true, true, window, 0); 61 target.dispatchEvent(e); 62 } 63 64 var testlink = document.getElementById("testlink"); 65 function test1() { 66 activationListener = 67 function() { 68 ok(true, "Untrusted click should activate a link"); 69 test2(); 70 } 71 dispatchClick(testlink, false); 72 } 73 74 function test2() { 75 activationListener = 76 function() { 77 ok(true, "Untrusted return keypress should activate a link"); 78 test3(); 79 } 80 dispatchReturn(testlink, false); 81 } 82 83 function test3() { 84 activationListener = 85 function() { 86 ok(false, "Untrusted click+ctrl should not activate a link"); 87 test4(); 88 } 89 dispatchClick(testlink, true); 90 hitEventLoop(10, test4); 91 } 92 93 function test4() { 94 activationListener = 95 function() { 96 ok(false, "Untrusted return keypress+ctrl should not activate a link"); 97 test5(); 98 } 99 dispatchReturn(testlink, true); 100 hitEventLoop(10, test5); 101 } 102 103 function test5() { 104 activationListener = 105 function() { 106 ok(true, "click() should activate a link"); 107 test6(); 108 } 109 testlink.click(); 110 } 111 112 function test6() { 113 activationListener = 114 function() { 115 ok(true, "Untrusted DOMActivate should activate a link"); 116 SpecialPowers.pushPrefEnv({"set":[["dom.disable_open_during_load", false]]}, test7); 117 } 118 dispatchDOMActivate(testlink); 119 } 120 121 function test7() { 122 testlink.href = "javascript:opener.activationListener(); window.close();"; 123 testlink.target = "_blank"; 124 testlink.rel = "opener"; 125 activationListener = 126 function() { 127 ok(true, "Click() should activate a link"); 128 SpecialPowers.pushPrefEnv({"set":[["dom.disable_open_during_load", true]]}, test8); 129 } 130 testlink.click(); 131 } 132 133 function test8() { 134 testlink.href = "javascript:opener.activationListener(); window.close();"; 135 testlink.target = "_blank"; 136 testlink.rel = "opener"; 137 activationListener = 138 function() { 139 ok(false, "Click() should not activate a link"); 140 } 141 testlink.click(); 142 SimpleTest.executeSoon(SimpleTest.finish); 143 } 144 addLoadEvent(test1); 145 146 </script> 147 </pre> 148 </body> 149 </html>