2011-06-30 04:52:11 -07:00
|
|
|
<!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();
|
|
|
|
|
2011-07-06 06:02:26 -07:00
|
|
|
function hitEventLoop(times, next)
|
|
|
|
{
|
|
|
|
if (times == 0) {
|
|
|
|
next();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.executeSoon(function() {
|
|
|
|
hitEventLoop(times - 1, next);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-30 04:52:11 -07:00
|
|
|
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);
|
2011-07-06 06:02:26 -07:00
|
|
|
hitEventLoop(10, test4);
|
2011-06-30 04:52:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function test4() {
|
|
|
|
activationListener =
|
|
|
|
function() {
|
|
|
|
ok(false, "Untrusted return keypress+ctrl should not activate a link");
|
|
|
|
test5();
|
|
|
|
}
|
|
|
|
dispatchReturn(testlink, true);
|
2011-07-06 06:02:26 -07:00
|
|
|
hitEventLoop(10, test5);
|
2011-06-30 04:52:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
test7();
|
|
|
|
}
|
|
|
|
dispatchDOMActivate(testlink);
|
|
|
|
}
|
|
|
|
|
2011-07-06 06:02:26 -07:00
|
|
|
var oldPref;
|
2011-06-30 04:52:11 -07:00
|
|
|
function test7() {
|
2011-07-06 06:02:26 -07:00
|
|
|
oldPref = SpecialPowers.getBoolPref("dom.disable_open_during_load");
|
|
|
|
SpecialPowers.setBoolPref("dom.disable_open_during_load", false);
|
2011-06-30 04:52:11 -07:00
|
|
|
testlink.href = "javascript:opener.activationListener(); window.close();";
|
|
|
|
testlink.target = "_blank";
|
|
|
|
activationListener =
|
|
|
|
function() {
|
|
|
|
ok(true, "Click() should activate a link");
|
2011-07-06 06:02:26 -07:00
|
|
|
setTimeout(test8, 0);
|
2011-06-30 04:52:11 -07:00
|
|
|
}
|
|
|
|
testlink.click();
|
|
|
|
}
|
|
|
|
|
2011-07-06 06:02:26 -07:00
|
|
|
function test8() {
|
|
|
|
SpecialPowers.setBoolPref("dom.disable_open_during_load", true);
|
|
|
|
testlink.href = "javascript:opener.activationListener(); window.close();";
|
|
|
|
testlink.target = "_blank";
|
|
|
|
activationListener =
|
|
|
|
function() {
|
|
|
|
ok(false, "Click() should not activate a link");
|
|
|
|
setTimeout(test9, 0);
|
|
|
|
}
|
|
|
|
testlink.click();
|
|
|
|
hitEventLoop(10, test9);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-30 04:52:11 -07:00
|
|
|
function test9() {
|
2011-07-06 06:02:26 -07:00
|
|
|
SpecialPowers.setBoolPref("dom.disable_open_during_load", oldPref);
|
2011-06-30 04:52:11 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
addLoadEvent(test1);
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|