content/base/test/test_bug666604.html

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

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

mercurial