1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/test_bug596600.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,177 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="Native mouse event tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.10 + 1.11 + <script type="application/javascript" 1.12 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.13 + 1.14 +<body xmlns="http://www.w3.org/1999/xhtml"> 1.15 +<p id="display"></p> 1.16 +<div id="content" style="display: none"> 1.17 + 1.18 +</div> 1.19 +<pre id="test"> 1.20 +</pre> 1.21 +</body> 1.22 + 1.23 +<script class="testbody" type="application/javascript"> 1.24 +<![CDATA[ 1.25 + 1.26 +const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; 1.27 +const NSMouseMoved = 5; 1.28 + 1.29 +var gLeftWindow, gRightWindow, gIFrame; 1.30 +var gExpectedEvents = []; 1.31 + 1.32 +function moveMouseTo(x, y, andThen) { 1.33 + var utils = gLeftWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor). 1.34 + getInterface(Components.interfaces.nsIDOMWindowUtils); 1.35 + utils.sendNativeMouseEvent(x, y, NSMouseMoved, 0, gLeftWindow.documentElement); 1.36 + SimpleTest.executeSoon(andThen); 1.37 +} 1.38 + 1.39 +function openWindows() { 1.40 + gLeftWindow = open('empty_window.xul', '_blank', 'chrome,screenX=50,screenY=50,width=200,height=200'); 1.41 + SimpleTest.waitForFocus(function () { 1.42 + gRightWindow = open('empty_window.xul', '', 'chrome,screenX=300,screenY=50,width=200,height=200'); 1.43 + SimpleTest.waitForFocus(attachIFrameToRightWindow, gRightWindow); 1.44 + }, gLeftWindow); 1.45 +} 1.46 + 1.47 +function attachIFrameToRightWindow() { 1.48 + gIFrame = gLeftWindow.document.createElementNS(XUL_NS, "iframe"); 1.49 + gIFrame.setAttribute("type", "content"); 1.50 + gIFrame.setAttribute("clickthrough", "never"); 1.51 + gIFrame.setAttribute("src", "data:text/html,<!DOCTYPE html>Content page"); 1.52 + gIFrame.style.width = "100px"; 1.53 + gIFrame.style.height = "100px"; 1.54 + gIFrame.style.margin = "50px"; 1.55 + gLeftWindow.document.documentElement.appendChild(gIFrame); 1.56 + gIFrame.contentWindow.addEventListener("load", function (e) { 1.57 + gIFrame.removeEventListener("load", arguments.callee, false); 1.58 + test1(); 1.59 + }, false); 1.60 +} 1.61 + 1.62 +function test1() { 1.63 + // gRightWindow is active, gLeftWindow is inactive. 1.64 + moveMouseTo(0, 0, function () { 1.65 + var expectMouseOver = false, expectMouseOut = false; 1.66 + function mouseOverListener(e) { 1.67 + ok(expectMouseOver, "Got expected mouseover at " + e.screenX + ", " + e.screenY); 1.68 + expectMouseOver = false; 1.69 + } 1.70 + function mouseOutListener(e) { 1.71 + ok(expectMouseOut, "Got expected mouseout at " + e.screenX + ", " + e.screenY); 1.72 + expectMouseOut = false; 1.73 + } 1.74 + gLeftWindow.addEventListener("mouseover", mouseOverListener, false); 1.75 + gLeftWindow.addEventListener("mouseout", mouseOutListener, false); 1.76 + 1.77 + // Move into the left window 1.78 + expectMouseOver = true; 1.79 + moveMouseTo(80, 80, function () { 1.80 + ok(!expectMouseOver, "Should have got mouseover event"); 1.81 + 1.82 + // Move over the iframe, which has clickthrough="never". 1.83 + expectMouseOut = true; 1.84 + moveMouseTo(150, 150, function () { 1.85 + ok (!expectMouseOut, "Should have got mouseout event"); 1.86 + gLeftWindow.removeEventListener("mouseover", mouseOverListener, false); 1.87 + gLeftWindow.removeEventListener("mouseout", mouseOutListener, false); 1.88 + test2(); 1.89 + }); 1.90 + }); 1.91 + }); 1.92 +} 1.93 + 1.94 +function test2() { 1.95 + // Make the iframe cover the whole window. 1.96 + gIFrame.style.margin = "0"; 1.97 + gIFrame.style.width = gIFrame.style.height = "200px"; 1.98 + 1.99 + // Add a box to the iframe at the left edge. 1.100 + var doc = gIFrame.contentDocument; 1.101 + var box = doc.createElement("div"); 1.102 + box.setAttribute("id", "box"); 1.103 + box.style.position = "absolute"; 1.104 + box.style.left = "0"; 1.105 + box.style.top = "50px"; 1.106 + box.style.width = "100px"; 1.107 + box.style.height = "100px"; 1.108 + box.style.backgroundColor = "green"; 1.109 + doc.body.appendChild(box); 1.110 + 1.111 + ok(!box.mozMatchesSelector(":hover"), "Box shouldn't be hovered (since the mouse isn't over it and since it's in a non-clickthrough iframe in a background window)"); 1.112 + 1.113 + // A function to waitForFocus and then wait for synthetic mouse 1.114 + // events to happen. Note that those happen off the refresh driver, 1.115 + // and happen after animation frame requests. 1.116 + function changeFocusAndAwaitSyntheticMouse(callback, winToFocus, 1.117 + elementToWatchForMouseEventOn) { 1.118 + function mouseWatcher() { 1.119 + elementToWatchForMouseEventOn.removeEventListener("mouseover", 1.120 + mouseWatcher, 1.121 + false); 1.122 + elementToWatchForMouseEventOn.removeEventListener("mouseout", 1.123 + mouseWatcher, 1.124 + false); 1.125 + SimpleTest.executeSoon(callback); 1.126 + } 1.127 + elementToWatchForMouseEventOn.addEventListener("mouseover", 1.128 + mouseWatcher, 1.129 + false); 1.130 + elementToWatchForMouseEventOn.addEventListener("mouseout", 1.131 + mouseWatcher, 1.132 + false); 1.133 + // Just pass a dummy function to waitForFocus; the mouseout/over listener 1.134 + // will actually handle things for us. 1.135 + SimpleTest.waitForFocus(function() {}, winToFocus); 1.136 + } 1.137 + 1.138 + // Move the mouse over the box. 1.139 + moveMouseTo(100, 150, function () { 1.140 + ok(!box.mozMatchesSelector(":hover"), "Box shouldn't be hovered (since it's in a non-clickthrough iframe in a background window)"); 1.141 + // Activate the left window. 1.142 + changeFocusAndAwaitSyntheticMouse(function () { 1.143 + ok(gIFrame.mozMatchesSelector(":hover"), "iframe should be hovered"); 1.144 + ok(box.mozMatchesSelector(":hover"), "Box should be hovered"); 1.145 + // De-activate the window (by activating the right window). 1.146 + changeFocusAndAwaitSyntheticMouse(function () { 1.147 + ok(!gIFrame.mozMatchesSelector(":hover"), "iframe shouldn't be hovered"); 1.148 + ok(!box.mozMatchesSelector(":hover"), "Box shouldn't be hovered"); 1.149 + // Re-activate it. 1.150 + changeFocusAndAwaitSyntheticMouse(function () { 1.151 + ok(gIFrame.mozMatchesSelector(":hover"), "iframe should be hovered"); 1.152 + ok(box.mozMatchesSelector(":hover"), "Box should be hovered"); 1.153 + // Unhover box and iframe by moving the mouse outside the window. 1.154 + moveMouseTo(0, 150, function () { 1.155 + const isOSXSnowLeopard = navigator.userAgent.indexOf("Mac OS X 10.6") != -1; 1.156 + if (!isOSXSnowLeopard) { 1.157 + ok(!gIFrame.mozMatchesSelector(":hover"), "iframe shouldn't be hovered"); 1.158 + ok(!box.mozMatchesSelector(":hover"), "box shouldn't be hovered"); 1.159 + } 1.160 + finalize(); 1.161 + }); 1.162 + }, gLeftWindow, box); 1.163 + }, gRightWindow, box); 1.164 + }, gLeftWindow, box); 1.165 + }); 1.166 +} 1.167 + 1.168 +function finalize() { 1.169 + gRightWindow.close(); 1.170 + gLeftWindow.close(); 1.171 + SimpleTest.finish(); 1.172 +} 1.173 + 1.174 +SimpleTest.waitForExplicitFinish(); 1.175 +SimpleTest.waitForFocus(openWindows); 1.176 + 1.177 +]]> 1.178 +</script> 1.179 + 1.180 +</window>