2012-07-20 19:41:30 +04:00
|
|
|
/* Any copyright is dedicated to the public domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
// Test that sendMouseEvent dispatch events.
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-03-28 23:51:10 +04:00
|
|
|
browserElementTestHelpers.setEnabledPref(true);
|
|
|
|
browserElementTestHelpers.addPermission();
|
2012-07-20 19:41:30 +04:00
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
var iframe = document.createElement("iframe");
|
2014-10-31 05:39:15 +03:00
|
|
|
iframe.setAttribute('mozbrowser', 'true');
|
2012-07-20 19:41:30 +04:00
|
|
|
document.body.appendChild(iframe);
|
2015-02-17 05:41:49 +03:00
|
|
|
var x = 10;
|
|
|
|
var y = 10;
|
|
|
|
// First we force a reflow so that getChildProcessOffset actually returns
|
|
|
|
// meaningful data.
|
|
|
|
iframe.getBoundingClientRect();
|
|
|
|
// We need to make sure the event coordinates are actually inside the iframe,
|
|
|
|
// relative to the chome window.
|
|
|
|
var tabParent = SpecialPowers.wrap(iframe)
|
|
|
|
.QueryInterface(SpecialPowers.Ci.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.tabParent;
|
|
|
|
if (tabParent) {
|
|
|
|
let offsetX = {};
|
|
|
|
let offsetY = {};
|
|
|
|
tabParent.getChildProcessOffset(offsetX, offsetY);
|
|
|
|
x -= offsetX.value;
|
|
|
|
y -= offsetY.value;
|
|
|
|
}
|
2012-07-20 19:41:30 +04:00
|
|
|
|
|
|
|
iframe.addEventListener("mozbrowserloadend", function onloadend(e) {
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendMouseEvent("mousedown", x, y, 0, 1, 0);
|
2012-07-20 19:41:30 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
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.");
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendMouseEvent("mousemove", x, y, 0, 0, 0);
|
2012-07-20 19:41:30 +04:00
|
|
|
break;
|
|
|
|
case "#mousemove":
|
|
|
|
ok(true, "Receive a mousemove event.");
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendMouseEvent("mouseup", x, y, 0, 1, 0);
|
2012-07-20 19:41:30 +04:00
|
|
|
break;
|
|
|
|
case "#mouseup":
|
|
|
|
ok(true, "Receive a mouseup event.");
|
|
|
|
break;
|
|
|
|
case "#click":
|
|
|
|
ok(true, "Receive a click event.");
|
2012-10-25 18:57:51 +04:00
|
|
|
if (SpecialPowers.getIntPref("dom.w3c_touch_events.enabled") != 0) {
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendTouchEvent("touchstart", [1], [x], [y], [2], [2],
|
2012-07-20 19:41:30 +04:00
|
|
|
[20], [0.5], 1, 0);
|
|
|
|
} else {
|
2013-05-28 00:33:57 +04:00
|
|
|
iframe.removeEventListener('mozbrowserlocationchange', onlocchange);
|
2012-07-20 19:41:30 +04:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "#touchstart":
|
|
|
|
ok(true, "Receive a touchstart event.");
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendTouchEvent("touchmove", [1], [x], [y], [2], [2],
|
2012-07-20 19:41:30 +04:00
|
|
|
[20], [0.5], 1, 0);
|
|
|
|
case "#touchmove":
|
|
|
|
ok(true, "Receive a touchmove event.");
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendTouchEvent("touchend", [1], [x], [y], [2], [2],
|
2012-07-20 19:41:30 +04:00
|
|
|
[20], [0.5], 1, 0);
|
|
|
|
break;
|
|
|
|
case "#touchend":
|
|
|
|
ok(true, "Receive a touchend event.");
|
2015-02-17 05:41:49 +03:00
|
|
|
iframe.sendTouchEvent("touchcancel", [1], [x], [y], [2], [2],
|
2012-07-20 19:41:30 +04:00
|
|
|
[20], [0.5], 1, 0);
|
2013-05-28 00:33:57 +04:00
|
|
|
iframe.removeEventListener('mozbrowserlocationchange', onlocchange);
|
2012-07-20 19:41:30 +04:00
|
|
|
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>";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-03-28 23:51:10 +04:00
|
|
|
addEventListener('testready', runTest);
|