gecko/dom/browser-element/mochitest/browserElement_SendEvent.js
Justin Lebar f9c87527fa Bug 852847 - Part 2: Do things later in our browser-element tests, thus avoiding doing things before the browser-element machinery has loaded. r=kk1ff
Also set network.disable.ipc.security to true and leave it that way. This prevents security errors in the tests which happen when we pop the pref.

--HG--
extra : rebase_source : 95f7ca7c3b71cdc0e3e6fd1cfb663a5653f3ab6f
2013-03-28 15:51:10 -04:00

82 lines
3.0 KiB
JavaScript

/* Any copyright is dedicated to the public domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Test that sendMouseEvent dispatch events.
"use strict";
SimpleTest.waitForExplicitFinish();
browserElementTestHelpers.setEnabledPref(true);
browserElementTestHelpers.addPermission();
function runTest() {
var iframe = document.createElement("iframe");
SpecialPowers.wrap(iframe).mozbrowser = true;
document.body.appendChild(iframe);
iframe.addEventListener("mozbrowserloadend", function onloadend(e) {
iframe.sendMouseEvent("mousedown", 10, 10, 0, 1, 0);
});
iframe.addEventListener("mozbrowserlocationchange", function onlocchange(e) {
var a = document.createElement("a");
a.href = e.detail;
switch (a.hash) {
case "#mousedown":
ok(true, "Receive a mousedown event.");
iframe.sendMouseEvent("mousemove", 10, 10, 0, 0, 0);
break;
case "#mousemove":
ok(true, "Receive a mousemove event.");
iframe.sendMouseEvent("mouseup", 10, 10, 0, 1, 0);
break;
case "#mouseup":
ok(true, "Receive a mouseup event.");
break;
case "#click":
ok(true, "Receive a click event.");
if (SpecialPowers.getIntPref("dom.w3c_touch_events.enabled") != 0) {
iframe.sendTouchEvent("touchstart", [1], [10], [10], [2], [2],
[20], [0.5], 1, 0);
} else {
SimpleTest.finish();
}
break;
case "#touchstart":
ok(true, "Receive a touchstart event.");
iframe.sendTouchEvent("touchmove", [1], [10], [10], [2], [2],
[20], [0.5], 1, 0);
case "#touchmove":
ok(true, "Receive a touchmove event.");
iframe.sendTouchEvent("touchend", [1], [10], [10], [2], [2],
[20], [0.5], 1, 0);
break;
case "#touchend":
ok(true, "Receive a touchend event.");
iframe.sendTouchEvent("touchcancel", [1], [10], [10], [2], [2],
[20], [0.5], 1, 0);
SimpleTest.finish();
break;
}
});
iframe.src = "data:text/html,<html><body>" +
"<button>send[Mouse|Touch]Event</button>" +
"</body><script>" +
"function changeHash(e) {" +
" document.location.hash = e.type;" +
"};" +
"window.addEventListener('mousedown', changeHash);" +
"window.addEventListener('mousemove', changeHash);" +
"window.addEventListener('mouseup', changeHash);" +
"window.addEventListener('click', changeHash, true);" +
"window.addEventListener('touchstart', changeHash);" +
"window.addEventListener('touchmove', changeHash);" +
"window.addEventListener('touchend', changeHash);" +
"window.addEventListener('touchcancel', changeHash);" +
"</script></html>";
}
addEventListener('testready', runTest);