Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 4 | type="text/css"?> |
michael@0 | 5 | <window title="Native mouse event tests" |
michael@0 | 6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 7 | |
michael@0 | 8 | <script type="application/javascript" |
michael@0 | 9 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 10 | |
michael@0 | 11 | <body xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 12 | <p id="display"></p> |
michael@0 | 13 | <div id="content" style="display: none"> |
michael@0 | 14 | |
michael@0 | 15 | </div> |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | </pre> |
michael@0 | 18 | </body> |
michael@0 | 19 | |
michael@0 | 20 | <script class="testbody" type="application/javascript"> |
michael@0 | 21 | <![CDATA[ |
michael@0 | 22 | |
michael@0 | 23 | const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; |
michael@0 | 24 | const NSMouseMoved = 5; |
michael@0 | 25 | |
michael@0 | 26 | var gLeftWindow, gRightWindow, gIFrame; |
michael@0 | 27 | var gExpectedEvents = []; |
michael@0 | 28 | |
michael@0 | 29 | function moveMouseTo(x, y, andThen) { |
michael@0 | 30 | var utils = gLeftWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor). |
michael@0 | 31 | getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 32 | utils.sendNativeMouseEvent(x, y, NSMouseMoved, 0, gLeftWindow.documentElement); |
michael@0 | 33 | SimpleTest.executeSoon(andThen); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function openWindows() { |
michael@0 | 37 | gLeftWindow = open('empty_window.xul', '_blank', 'chrome,screenX=50,screenY=50,width=200,height=200'); |
michael@0 | 38 | SimpleTest.waitForFocus(function () { |
michael@0 | 39 | gRightWindow = open('empty_window.xul', '', 'chrome,screenX=300,screenY=50,width=200,height=200'); |
michael@0 | 40 | SimpleTest.waitForFocus(attachIFrameToRightWindow, gRightWindow); |
michael@0 | 41 | }, gLeftWindow); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | function attachIFrameToRightWindow() { |
michael@0 | 45 | gIFrame = gLeftWindow.document.createElementNS(XUL_NS, "iframe"); |
michael@0 | 46 | gIFrame.setAttribute("type", "content"); |
michael@0 | 47 | gIFrame.setAttribute("clickthrough", "never"); |
michael@0 | 48 | gIFrame.setAttribute("src", "data:text/html,<!DOCTYPE html>Content page"); |
michael@0 | 49 | gIFrame.style.width = "100px"; |
michael@0 | 50 | gIFrame.style.height = "100px"; |
michael@0 | 51 | gIFrame.style.margin = "50px"; |
michael@0 | 52 | gLeftWindow.document.documentElement.appendChild(gIFrame); |
michael@0 | 53 | gIFrame.contentWindow.addEventListener("load", function (e) { |
michael@0 | 54 | gIFrame.removeEventListener("load", arguments.callee, false); |
michael@0 | 55 | test1(); |
michael@0 | 56 | }, false); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function test1() { |
michael@0 | 60 | // gRightWindow is active, gLeftWindow is inactive. |
michael@0 | 61 | moveMouseTo(0, 0, function () { |
michael@0 | 62 | var expectMouseOver = false, expectMouseOut = false; |
michael@0 | 63 | function mouseOverListener(e) { |
michael@0 | 64 | ok(expectMouseOver, "Got expected mouseover at " + e.screenX + ", " + e.screenY); |
michael@0 | 65 | expectMouseOver = false; |
michael@0 | 66 | } |
michael@0 | 67 | function mouseOutListener(e) { |
michael@0 | 68 | ok(expectMouseOut, "Got expected mouseout at " + e.screenX + ", " + e.screenY); |
michael@0 | 69 | expectMouseOut = false; |
michael@0 | 70 | } |
michael@0 | 71 | gLeftWindow.addEventListener("mouseover", mouseOverListener, false); |
michael@0 | 72 | gLeftWindow.addEventListener("mouseout", mouseOutListener, false); |
michael@0 | 73 | |
michael@0 | 74 | // Move into the left window |
michael@0 | 75 | expectMouseOver = true; |
michael@0 | 76 | moveMouseTo(80, 80, function () { |
michael@0 | 77 | ok(!expectMouseOver, "Should have got mouseover event"); |
michael@0 | 78 | |
michael@0 | 79 | // Move over the iframe, which has clickthrough="never". |
michael@0 | 80 | expectMouseOut = true; |
michael@0 | 81 | moveMouseTo(150, 150, function () { |
michael@0 | 82 | ok (!expectMouseOut, "Should have got mouseout event"); |
michael@0 | 83 | gLeftWindow.removeEventListener("mouseover", mouseOverListener, false); |
michael@0 | 84 | gLeftWindow.removeEventListener("mouseout", mouseOutListener, false); |
michael@0 | 85 | test2(); |
michael@0 | 86 | }); |
michael@0 | 87 | }); |
michael@0 | 88 | }); |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | function test2() { |
michael@0 | 92 | // Make the iframe cover the whole window. |
michael@0 | 93 | gIFrame.style.margin = "0"; |
michael@0 | 94 | gIFrame.style.width = gIFrame.style.height = "200px"; |
michael@0 | 95 | |
michael@0 | 96 | // Add a box to the iframe at the left edge. |
michael@0 | 97 | var doc = gIFrame.contentDocument; |
michael@0 | 98 | var box = doc.createElement("div"); |
michael@0 | 99 | box.setAttribute("id", "box"); |
michael@0 | 100 | box.style.position = "absolute"; |
michael@0 | 101 | box.style.left = "0"; |
michael@0 | 102 | box.style.top = "50px"; |
michael@0 | 103 | box.style.width = "100px"; |
michael@0 | 104 | box.style.height = "100px"; |
michael@0 | 105 | box.style.backgroundColor = "green"; |
michael@0 | 106 | doc.body.appendChild(box); |
michael@0 | 107 | |
michael@0 | 108 | 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)"); |
michael@0 | 109 | |
michael@0 | 110 | // A function to waitForFocus and then wait for synthetic mouse |
michael@0 | 111 | // events to happen. Note that those happen off the refresh driver, |
michael@0 | 112 | // and happen after animation frame requests. |
michael@0 | 113 | function changeFocusAndAwaitSyntheticMouse(callback, winToFocus, |
michael@0 | 114 | elementToWatchForMouseEventOn) { |
michael@0 | 115 | function mouseWatcher() { |
michael@0 | 116 | elementToWatchForMouseEventOn.removeEventListener("mouseover", |
michael@0 | 117 | mouseWatcher, |
michael@0 | 118 | false); |
michael@0 | 119 | elementToWatchForMouseEventOn.removeEventListener("mouseout", |
michael@0 | 120 | mouseWatcher, |
michael@0 | 121 | false); |
michael@0 | 122 | SimpleTest.executeSoon(callback); |
michael@0 | 123 | } |
michael@0 | 124 | elementToWatchForMouseEventOn.addEventListener("mouseover", |
michael@0 | 125 | mouseWatcher, |
michael@0 | 126 | false); |
michael@0 | 127 | elementToWatchForMouseEventOn.addEventListener("mouseout", |
michael@0 | 128 | mouseWatcher, |
michael@0 | 129 | false); |
michael@0 | 130 | // Just pass a dummy function to waitForFocus; the mouseout/over listener |
michael@0 | 131 | // will actually handle things for us. |
michael@0 | 132 | SimpleTest.waitForFocus(function() {}, winToFocus); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | // Move the mouse over the box. |
michael@0 | 136 | moveMouseTo(100, 150, function () { |
michael@0 | 137 | ok(!box.mozMatchesSelector(":hover"), "Box shouldn't be hovered (since it's in a non-clickthrough iframe in a background window)"); |
michael@0 | 138 | // Activate the left window. |
michael@0 | 139 | changeFocusAndAwaitSyntheticMouse(function () { |
michael@0 | 140 | ok(gIFrame.mozMatchesSelector(":hover"), "iframe should be hovered"); |
michael@0 | 141 | ok(box.mozMatchesSelector(":hover"), "Box should be hovered"); |
michael@0 | 142 | // De-activate the window (by activating the right window). |
michael@0 | 143 | changeFocusAndAwaitSyntheticMouse(function () { |
michael@0 | 144 | ok(!gIFrame.mozMatchesSelector(":hover"), "iframe shouldn't be hovered"); |
michael@0 | 145 | ok(!box.mozMatchesSelector(":hover"), "Box shouldn't be hovered"); |
michael@0 | 146 | // Re-activate it. |
michael@0 | 147 | changeFocusAndAwaitSyntheticMouse(function () { |
michael@0 | 148 | ok(gIFrame.mozMatchesSelector(":hover"), "iframe should be hovered"); |
michael@0 | 149 | ok(box.mozMatchesSelector(":hover"), "Box should be hovered"); |
michael@0 | 150 | // Unhover box and iframe by moving the mouse outside the window. |
michael@0 | 151 | moveMouseTo(0, 150, function () { |
michael@0 | 152 | const isOSXSnowLeopard = navigator.userAgent.indexOf("Mac OS X 10.6") != -1; |
michael@0 | 153 | if (!isOSXSnowLeopard) { |
michael@0 | 154 | ok(!gIFrame.mozMatchesSelector(":hover"), "iframe shouldn't be hovered"); |
michael@0 | 155 | ok(!box.mozMatchesSelector(":hover"), "box shouldn't be hovered"); |
michael@0 | 156 | } |
michael@0 | 157 | finalize(); |
michael@0 | 158 | }); |
michael@0 | 159 | }, gLeftWindow, box); |
michael@0 | 160 | }, gRightWindow, box); |
michael@0 | 161 | }, gLeftWindow, box); |
michael@0 | 162 | }); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | function finalize() { |
michael@0 | 166 | gRightWindow.close(); |
michael@0 | 167 | gLeftWindow.close(); |
michael@0 | 168 | SimpleTest.finish(); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 172 | SimpleTest.waitForFocus(openWindows); |
michael@0 | 173 | |
michael@0 | 174 | ]]> |
michael@0 | 175 | </script> |
michael@0 | 176 | |
michael@0 | 177 | </window> |