summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug666604.html
blob: 4f73c4075cd90ab2744764482e5a589b0f1dab5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=666604
-->
<head>
  <title>Test for Bug 666604</title>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=666604">Mozilla Bug 666604</a>
<p id="display"></p>
<div id="content" style="display: none">
  
</div>
<a href="javascript:activationListener()" id="testlink">test</a>
<pre id="test">
<script type="application/javascript">

/** Test for Bug 666604 **/

SimpleTest.waitForExplicitFinish();

function hitEventLoop(times, next)
{
  if (times == 0) {
     next();
     return;
   }
 
  SimpleTest.executeSoon(function() {
    hitEventLoop(times - 1, next);
  });
}

var activationListener;

function dispatchClick(target, ctrl) {
  var e = document.createEvent("MouseEvent");
  e.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, 
                   ctrl, false, false, false, 0, null);
  target.dispatchEvent(e);
}

function dispatchReturn(target, ctrl) {
  var e = document.createEvent("KeyboardEvent");
  e.initKeyEvent("keypress", true, true, window, ctrl, false,
                 false, false, 13, 0);
  target.dispatchEvent(e);                
}

function dispatchDOMActivate(target) {
  var e = document.createEvent("UIEvent");
  e.initUIEvent("DOMActivate", true, true, window, 0);
  target.dispatchEvent(e);
}

var testlink = document.getElementById("testlink");
function test1() {
  activationListener =
    function() {
      ok(true, "Untrusted click should activate a link");
      test2();
    }
  dispatchClick(testlink, false);
}

function test2() {
  activationListener =
    function() {
      ok(true, "Untrusted return keypress should activate a link");
      test3();
    }
  dispatchReturn(testlink, false);
}

function test3() {
  activationListener =
  function() {
    ok(false, "Untrusted click+ctrl should not activate a link");
    test4();
  }
  dispatchClick(testlink, true);
  hitEventLoop(10, test4);
}

function test4() {
  activationListener =
    function() {
      ok(false, "Untrusted return keypress+ctrl should not activate a link");
      test5();
    }
  dispatchReturn(testlink, true);
  hitEventLoop(10, test5);
}

function test5() {
  activationListener =
    function() {
      ok(true, "click() should activate a link");
      test6();
    }
  testlink.click();
}

function test6() {
  activationListener =
    function() {
      ok(true, "Untrusted DOMActivate should activate a link");
      SpecialPowers.pushPrefEnv({"set":[["dom.disable_open_during_load", false]]}, test7);
    }
  dispatchDOMActivate(testlink);
}

function test7() {
  testlink.href = "javascript:opener.activationListener(); window.close();";
  testlink.target = "_blank";
  activationListener =
    function() {
      ok(true, "Click() should activate a link");
      SpecialPowers.pushPrefEnv({"set":[["dom.disable_open_during_load", true]]}, test8);
    }
  testlink.click();
}

function test8() {
  testlink.href = "javascript:opener.activationListener(); window.close();";
  testlink.target = "_blank";
  activationListener =
    function() {
      ok(false, "Click() should not activate a link");
    }
  testlink.click();
  SimpleTest.executeSoon(SimpleTest.finish);
}
addLoadEvent(test1);

</script>
</pre>
</body>
</html>