2011-05-16 17:15:43 +04:00
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
type="text/css"?>
<window title="Native mouse event tests"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
2019-04-16 06:59:25 +03:00
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
2011-05-16 17:15:43 +04:00
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script class="testbody" type="application/javascript">
<![CDATA[
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
const NSMouseMoved = 5;
2019-01-14 23:42:50 +03:00
var gLeftWindow, gRightWindow, gBrowserElement;
2011-05-16 17:15:43 +04:00
var gExpectedEvents = [];
function moveMouseTo(x, y, andThen) {
2018-07-25 02:47:43 +03:00
var utils = gLeftWindow.windowUtils;
2011-05-16 17:15:43 +04:00
utils.sendNativeMouseEvent(x, y, NSMouseMoved, 0, gLeftWindow.documentElement);
SimpleTest.executeSoon(andThen);
}
function openWindows() {
2012-01-31 14:40:03 +04:00
gLeftWindow = open('empty_window.xul', '_blank', 'chrome,screenX=50,screenY=50,width=200,height=200');
2011-05-16 17:15:43 +04:00
SimpleTest.waitForFocus(function () {
2012-01-31 14:40:03 +04:00
gRightWindow = open('empty_window.xul', '', 'chrome,screenX=300,screenY=50,width=200,height=200');
2019-01-14 23:42:50 +03:00
SimpleTest.waitForFocus(attachBrowserToLeftWindow, gRightWindow);
2011-05-16 17:15:43 +04:00
}, gLeftWindow);
}
2019-01-14 23:42:50 +03:00
function attachBrowserToLeftWindow() {
gBrowserElement = gLeftWindow.document.createXULElement("browser");
gBrowserElement.setAttribute("type", "content");
gBrowserElement.setAttribute("src", "file_bug596600.html");
gBrowserElement.style.width = "100px";
gBrowserElement.style.height = "100px";
gBrowserElement.style.margin = "50px";
gLeftWindow.document.documentElement.appendChild(gBrowserElement);
gBrowserElement.addEventListener("load", function (e) {
2011-05-16 17:15:43 +04:00
test1();
2019-01-14 23:42:50 +03:00
}, { capture: true, once: true });
2011-05-16 17:15:43 +04:00
}
function test1() {
// gRightWindow is active, gLeftWindow is inactive.
moveMouseTo(0, 0, function () {
var expectMouseOver = false, expectMouseOut = false;
function mouseOverListener(e) {
ok(expectMouseOver, "Got expected mouseover at " + e.screenX + ", " + e.screenY);
expectMouseOver = false;
}
function mouseOutListener(e) {
ok(expectMouseOut, "Got expected mouseout at " + e.screenX + ", " + e.screenY);
expectMouseOut = false;
}
gLeftWindow.addEventListener("mouseover", mouseOverListener, false);
gLeftWindow.addEventListener("mouseout", mouseOutListener, false);
// Move into the left window
expectMouseOver = true;
moveMouseTo(80, 80, function () {
ok(!expectMouseOver, "Should have got mouseover event");
2019-01-14 23:42:50 +03:00
// Move over the browser
2011-05-16 17:15:43 +04:00
expectMouseOut = true;
moveMouseTo(150, 150, function () {
ok (!expectMouseOut, "Should have got mouseout event");
gLeftWindow.removeEventListener("mouseover", mouseOverListener, false);
gLeftWindow.removeEventListener("mouseout", mouseOutListener, false);
test2();
});
});
});
}
function test2() {
2019-01-14 23:42:50 +03:00
// Make the browser cover the whole window.
gBrowserElement.style.margin = "0";
gBrowserElement.style.width = gBrowserElement.style.height = "200px";
2011-05-16 17:15:43 +04:00
2019-01-14 23:42:50 +03:00
// Add a box to the browser at the left edge.
var doc = gBrowserElement.contentDocument;
2011-05-16 17:15:43 +04:00
var box = doc.createElement("div");
box.setAttribute("id", "box");
box.style.position = "absolute";
box.style.left = "0";
box.style.top = "50px";
box.style.width = "100px";
box.style.height = "100px";
box.style.backgroundColor = "green";
doc.body.appendChild(box);
2019-01-14 23:42:50 +03:00
ok(!box.matches(":hover"), "Box shouldn't be hovered (since the mouse isn't over it and since it's in a non-clickthrough browser in a background window)");
2011-05-16 17:15:43 +04:00
2012-01-10 09:23:29 +04:00
// A function to waitForFocus and then wait for synthetic mouse
// events to happen. Note that those happen off the refresh driver,
// and happen after animation frame requests.
function changeFocusAndAwaitSyntheticMouse(callback, winToFocus,
elementToWatchForMouseEventOn) {
function mouseWatcher() {
elementToWatchForMouseEventOn.removeEventListener("mouseover",
mouseWatcher,
false);
elementToWatchForMouseEventOn.removeEventListener("mouseout",
mouseWatcher,
false);
SimpleTest.executeSoon(callback);
}
elementToWatchForMouseEventOn.addEventListener("mouseover",
mouseWatcher,
false);
elementToWatchForMouseEventOn.addEventListener("mouseout",
mouseWatcher,
false);
// Just pass a dummy function to waitForFocus; the mouseout/over listener
// will actually handle things for us.
SimpleTest.waitForFocus(function() {}, winToFocus);
}
2011-05-16 17:15:43 +04:00
// Move the mouse over the box.
moveMouseTo(100, 150, function () {
2019-01-14 23:42:50 +03:00
ok(!box.matches(":hover"), "Box shouldn't be hovered (since it's in a non-clickthrough browser in a background window)");
2011-05-16 17:15:43 +04:00
// Activate the left window.
2012-01-10 09:23:29 +04:00
changeFocusAndAwaitSyntheticMouse(function () {
2019-01-14 23:42:50 +03:00
ok(gBrowserElement.matches(":hover"), "browser should be hovered");
2014-08-12 16:30:59 +04:00
ok(box.matches(":hover"), "Box should be hovered");
2011-05-16 17:15:43 +04:00
// De-activate the window (by activating the right window).
2012-01-10 09:23:29 +04:00
changeFocusAndAwaitSyntheticMouse(function () {
2019-01-14 23:42:50 +03:00
ok(!gBrowserElement.matches(":hover"), "browser shouldn't be hovered");
2014-08-12 16:30:59 +04:00
ok(!box.matches(":hover"), "Box shouldn't be hovered");
2011-05-16 17:15:43 +04:00
// Re-activate it.
2012-01-10 09:23:29 +04:00
changeFocusAndAwaitSyntheticMouse(function () {
2019-01-14 23:42:50 +03:00
ok(gBrowserElement.matches(":hover"), "browser should be hovered");
2014-08-12 16:30:59 +04:00
ok(box.matches(":hover"), "Box should be hovered");
2019-01-14 23:42:50 +03:00
// Unhover box and browser by moving the mouse outside the window.
2011-05-16 17:15:43 +04:00
moveMouseTo(0, 150, function () {
2019-01-14 23:42:50 +03:00
ok(!gBrowserElement.matches(":hover"), "browser shouldn't be hovered");
2018-09-14 07:33:19 +03:00
ok(!box.matches(":hover"), "box shouldn't be hovered");
2011-05-16 17:15:43 +04:00
finalize();
});
2012-01-10 09:23:29 +04:00
}, gLeftWindow, box);
}, gRightWindow, box);
}, gLeftWindow, box);
2011-05-16 17:15:43 +04:00
});
}
function finalize() {
gRightWindow.close();
gLeftWindow.close();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(openWindows);
]]>
</script>
</window>