content/base/test/test_bug666604.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/test_bug666604.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,154 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=666604
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 666604</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=666604">Mozilla Bug 666604</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<a href="javascript:activationListener()" id="testlink">test</a>
    1.21 +<pre id="test">
    1.22 +<script type="application/javascript">
    1.23 +
    1.24 +/** Test for Bug 666604 **/
    1.25 +
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +
    1.28 +function hitEventLoop(times, next)
    1.29 +{
    1.30 +  if (times == 0) {
    1.31 +     next();
    1.32 +     return;
    1.33 +   }
    1.34 + 
    1.35 +  SimpleTest.executeSoon(function() {
    1.36 +    hitEventLoop(times - 1, next);
    1.37 +  });
    1.38 +}
    1.39 +
    1.40 +var activationListener;
    1.41 +
    1.42 +function dispatchClick(target, ctrl) {
    1.43 +  var e = document.createEvent("MouseEvent");
    1.44 +  e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, 
    1.45 +                   ctrl, false, false, false, 0, null);
    1.46 +  target.dispatchEvent(e);
    1.47 +}
    1.48 +
    1.49 +function dispatchReturn(target, ctrl) {
    1.50 +  var e = document.createEvent("KeyboardEvent");
    1.51 +  e.initKeyEvent("keypress", true, true, window, ctrl, false,
    1.52 +                 false, false, 13, 0);
    1.53 +  target.dispatchEvent(e);                
    1.54 +}
    1.55 +
    1.56 +function dispatchDOMActivate(target) {
    1.57 +  var e = document.createEvent("UIEvent");
    1.58 +  e.initUIEvent("DOMActivate", true, true, window, 0);
    1.59 +  target.dispatchEvent(e);
    1.60 +}
    1.61 +
    1.62 +var testlink = document.getElementById("testlink");
    1.63 +function test1() {
    1.64 +  activationListener =
    1.65 +    function() {
    1.66 +      ok(true, "Untrusted click should activate a link");
    1.67 +      test2();
    1.68 +    }
    1.69 +  dispatchClick(testlink, false);
    1.70 +}
    1.71 +
    1.72 +function test2() {
    1.73 +  activationListener =
    1.74 +    function() {
    1.75 +      ok(true, "Untrusted return keypress should activate a link");
    1.76 +      test3();
    1.77 +    }
    1.78 +  dispatchReturn(testlink, false);
    1.79 +}
    1.80 +
    1.81 +function test3() {
    1.82 +  activationListener =
    1.83 +  function() {
    1.84 +    ok(false, "Untrusted click+ctrl should not activate a link");
    1.85 +    test4();
    1.86 +  }
    1.87 +  dispatchClick(testlink, true);
    1.88 +  hitEventLoop(10, test4);
    1.89 +}
    1.90 +
    1.91 +function test4() {
    1.92 +  activationListener =
    1.93 +    function() {
    1.94 +      ok(false, "Untrusted return keypress+ctrl should not activate a link");
    1.95 +      test5();
    1.96 +    }
    1.97 +  dispatchReturn(testlink, true);
    1.98 +  hitEventLoop(10, test5);
    1.99 +}
   1.100 +
   1.101 +function test5() {
   1.102 +  activationListener =
   1.103 +    function() {
   1.104 +      ok(true, "click() should activate a link");
   1.105 +      test6();
   1.106 +    }
   1.107 +  testlink.click();
   1.108 +}
   1.109 +
   1.110 +function test6() {
   1.111 +  activationListener =
   1.112 +    function() {
   1.113 +      ok(true, "Untrusted DOMActivate should activate a link");
   1.114 +      test7();
   1.115 +    }
   1.116 +  dispatchDOMActivate(testlink);
   1.117 +}
   1.118 +
   1.119 +var oldPref;
   1.120 +function test7() {
   1.121 +  oldPref = SpecialPowers.getBoolPref("dom.disable_open_during_load");
   1.122 +  SpecialPowers.setBoolPref("dom.disable_open_during_load", false);
   1.123 +  testlink.href = "javascript:opener.activationListener(); window.close();";
   1.124 +  testlink.target = "_blank";
   1.125 +  activationListener =
   1.126 +    function() {
   1.127 +      ok(true, "Click() should activate a link");
   1.128 +      setTimeout(test8, 0);
   1.129 +    }
   1.130 +  testlink.click();
   1.131 +}
   1.132 +
   1.133 +function test8() {
   1.134 +  SpecialPowers.setBoolPref("dom.disable_open_during_load", true);
   1.135 +  testlink.href = "javascript:opener.activationListener(); window.close();";
   1.136 +  testlink.target = "_blank";
   1.137 +  activationListener =
   1.138 +    function() {
   1.139 +      ok(false, "Click() should not activate a link");
   1.140 +      setTimeout(test9, 0);
   1.141 +    }
   1.142 +  testlink.click();  
   1.143 +  hitEventLoop(10, test9);
   1.144 +} 
   1.145 +
   1.146 +
   1.147 +function test9() {
   1.148 +  SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPref);
   1.149 +  SimpleTest.finish();
   1.150 +}
   1.151 +
   1.152 +addLoadEvent(test1);
   1.153 +
   1.154 +</script>
   1.155 +</pre>
   1.156 +</body>
   1.157 +</html>

mercurial