2009-10-16 01:57:32 -07:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=448602
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<title>Test for Bug 448602</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=448602">Mozilla Bug 448602</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script type="application/javascript">
|
|
|
|
|
|
|
|
/** Test for Bug 448602 **/
|
|
|
|
|
|
|
|
|
|
|
|
function runTests() {
|
2011-10-10 03:38:14 -07:00
|
|
|
/*
|
|
|
|
Disabled due to lack of present support for JSD in JM
|
2009-10-17 07:40:44 -07:00
|
|
|
var jsdIDebuggerService = Components.interfaces.jsdIDebuggerService;
|
|
|
|
var jsd = Components.classes['@mozilla.org/js/jsd/debugger-service;1']
|
|
|
|
.getService(jsdIDebuggerService);
|
2011-10-10 03:38:14 -07:00
|
|
|
*/
|
2012-09-11 01:05:10 -07:00
|
|
|
var els = SpecialPowers.wrap(Components).classes["@mozilla.org/eventlistenerservice;1"]
|
2009-10-16 01:57:32 -07:00
|
|
|
.getService(Components.interfaces.nsIEventListenerService);
|
|
|
|
|
|
|
|
// Event listener info tests
|
|
|
|
var root = document.getElementById("testroot");
|
|
|
|
var infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 0, "Element shouldn't have listeners (1)");
|
|
|
|
|
|
|
|
var listenerSource = 'alert(event);';
|
|
|
|
root.setAttribute("onclick", listenerSource);
|
|
|
|
infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 1, "Element should have listeners (1)");
|
2012-07-23 17:03:41 -07:00
|
|
|
is(infos[0].toSource(), 'function onclick(event) {\n' + listenerSource + '\n}',
|
2009-10-16 01:57:32 -07:00
|
|
|
"Unexpected serialization (1)");
|
|
|
|
is(infos[0].type, "click", "Wrong type (1)");
|
|
|
|
is(infos[0].capturing, false, "Wrong phase (1)");
|
|
|
|
is(infos[0].allowsUntrusted, true, "Should allow untrusted events (1)");
|
|
|
|
|
2011-10-10 03:38:14 -07:00
|
|
|
/*
|
2009-10-17 07:40:44 -07:00
|
|
|
var jsdOn = jsd.isOn;
|
|
|
|
if (!jsdOn) {
|
|
|
|
is(infos[0].getDebugObject(), null,
|
|
|
|
"If JSD isn't running, getDebugObject() should return null.")
|
|
|
|
jsd.on();
|
|
|
|
ok(jsd.isOn, "JSD should be running.");
|
|
|
|
}
|
|
|
|
var jsdvalue = infos[0].getDebugObject().QueryInterface(Components.interfaces.jsdIValue);
|
|
|
|
is(jsdvalue.jsType, 3, "Event listener should be a function! (1)");
|
2011-10-10 03:38:14 -07:00
|
|
|
*/
|
2009-10-17 07:40:44 -07:00
|
|
|
|
2009-10-16 01:57:32 -07:00
|
|
|
root.removeAttribute("onclick");
|
|
|
|
infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 0, "Element shouldn't have listeners (2)");
|
|
|
|
|
|
|
|
var l = function (e) { alert(e); };
|
|
|
|
root.addEventListener("foo", l, true, true);
|
|
|
|
root.addEventListener("foo", l, false, false);
|
|
|
|
infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 2, "Element should have listeners (2)");
|
2012-07-20 11:17:38 -07:00
|
|
|
is(infos[0].toSource(), "(function (e) { alert(e); })",
|
2009-10-16 01:57:32 -07:00
|
|
|
"Unexpected serialization (2)");
|
|
|
|
is(infos[0].type, "foo", "Wrong type (2)");
|
|
|
|
is(infos[0].capturing, true, "Wrong phase (2)");
|
|
|
|
is(infos[0].allowsUntrusted, true, "Should allow untrusted events (2)");
|
2011-10-10 03:38:14 -07:00
|
|
|
/*
|
2009-10-17 07:40:44 -07:00
|
|
|
jsdvalue = infos[0].getDebugObject().QueryInterface(Components.interfaces.jsdIValue);
|
|
|
|
is(jsdvalue.jsType, 3, "Event listener should be a function!(2)");
|
|
|
|
is(jsdvalue.getWrappedValue(), l, "Wrong JS value! (1)");
|
2011-10-10 03:38:14 -07:00
|
|
|
*/
|
2009-10-17 07:40:44 -07:00
|
|
|
|
2012-07-20 11:17:38 -07:00
|
|
|
is(infos[1].toSource(), "(function (e) { alert(e); })",
|
2009-10-16 01:57:32 -07:00
|
|
|
"Unexpected serialization (3)");
|
|
|
|
is(infos[1].type, "foo", "Wrong type (3)");
|
|
|
|
is(infos[1].capturing, false, "Wrong phase (3)");
|
|
|
|
is(infos[1].allowsUntrusted, false, "Shouldn't allow untrusted events (1)");
|
|
|
|
|
2011-10-10 03:38:14 -07:00
|
|
|
/*
|
2009-10-17 07:40:44 -07:00
|
|
|
jsdvalue2 = infos[1].getDebugObject().QueryInterface(Components.interfaces.jsdIValue);
|
|
|
|
is(jsdvalue2.jsType, 3, "Event listener should be a function! (3)");
|
|
|
|
is(jsdvalue2.getWrappedValue(), l, "Wrong JS value! (2)");
|
2011-10-10 03:38:14 -07:00
|
|
|
*/
|
2009-10-16 01:57:32 -07:00
|
|
|
root.removeEventListener("foo", l, true);
|
|
|
|
root.removeEventListener("foo", l, false);
|
|
|
|
infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 0, "Element shouldn't have listeners (3)");
|
|
|
|
|
|
|
|
root.onclick = l;
|
|
|
|
infos = els.getListenerInfoFor(root, {});
|
|
|
|
is(infos.length, 1, "Element should have listeners (3)");
|
2012-07-20 11:17:38 -07:00
|
|
|
is(infos[0].toSource(), '(function (e) { alert(e); })',
|
2009-10-16 01:57:32 -07:00
|
|
|
"Unexpected serialization (4)");
|
|
|
|
is(infos[0].type, "click", "Wrong type (4)");
|
|
|
|
is(infos[0].capturing, false, "Wrong phase (4)");
|
|
|
|
is(infos[0].allowsUntrusted, true, "Should allow untrusted events (3)");
|
|
|
|
|
|
|
|
// Event target chain tests
|
|
|
|
var l2 = document.getElementById("testlevel2");
|
|
|
|
var l3 = document.getElementById("testlevel3");
|
|
|
|
var textnode = l3.firstChild;
|
2012-09-11 01:05:10 -07:00
|
|
|
var chain = SpecialPowers.unwrap(els.getEventTargetChainFor(textnode, {}));
|
2009-10-16 01:57:32 -07:00
|
|
|
ok(chain.length > 3, "Too short event target chain.");
|
|
|
|
is(chain[0], textnode, "Wrong chain item (1)");
|
|
|
|
is(chain[1], l3, "Wrong chain item (2)");
|
|
|
|
is(chain[2], l2, "Wrong chain item (3)");
|
|
|
|
is(chain[3], root, "Wrong chain item (4)");
|
|
|
|
|
|
|
|
var hasDocumentInChain = false;
|
|
|
|
var hasWindowInChain = false;
|
|
|
|
for (var i = 0; i < chain.length; ++i) {
|
|
|
|
if (chain[i] == document) {
|
|
|
|
hasDocumentInChain = true;
|
|
|
|
} else if (chain[i] == window) {
|
|
|
|
hasWindowInChain = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(hasDocumentInChain, "Should have document in event target chain!");
|
|
|
|
ok(hasWindowInChain, "Should have window in event target chain!");
|
2011-10-10 03:38:14 -07:00
|
|
|
/*
|
2009-10-17 07:40:44 -07:00
|
|
|
if (!jsdOn) {
|
|
|
|
jsd.off();
|
|
|
|
ok(!jsd.isOn, "JSD shouldn't be running anymore.");
|
|
|
|
}
|
2011-10-10 03:38:14 -07:00
|
|
|
*/
|
2009-10-17 07:40:44 -07:00
|
|
|
|
2011-10-10 03:38:14 -07:00
|
|
|
try {
|
|
|
|
els.getListenerInfoFor(null, {});
|
|
|
|
ok(false, "Should have thrown an exception.");
|
|
|
|
} catch (ex) {
|
|
|
|
ok(true, "We should be still running.");
|
|
|
|
}
|
2009-10-17 07:40:44 -07:00
|
|
|
|
2009-10-16 01:57:32 -07:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
addLoadEvent(runTests);
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
<div id="testroot">
|
|
|
|
<div id="testlevel2">
|
|
|
|
<div id="testlevel3">
|
|
|
|
Test
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|