diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/plugins/test/mochitest/cocoa_focus.html | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/plugins/test/mochitest/cocoa_focus.html')
-rw-r--r-- | dom/plugins/test/mochitest/cocoa_focus.html | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/dom/plugins/test/mochitest/cocoa_focus.html b/dom/plugins/test/mochitest/cocoa_focus.html new file mode 100644 index 000000000..ca35fd7a1 --- /dev/null +++ b/dom/plugins/test/mochitest/cocoa_focus.html @@ -0,0 +1,142 @@ +<html> +<head> + <title>NPCocoaEventFocusChanged Tests</title> +</head> +<body> + <embed id="plugin1" type="application/x-test" width="100" height="100"></embed> + <embed id="plugin2" type="application/x-test" width="100" height="100"></embed> + <script type="application/javascript"> + function is(aLeft, aRight, aMessage) { + window.opener.SimpleTest.is(aLeft, aRight, aMessage); + } + + function ok(aValue, aMessage) { + window.opener.SimpleTest.ok(aValue, aMessage); + } + + function synthesizeNativeMouseEvent(aX, aY, aNativeMsg, aModifiers, aElement, aCallback) { + var observer = { + observe: function(aSubject, aTopic, aData) { + if (aCallback && aTopic == "mouseevent") { + aCallback(aData); + } + } + }; + SpecialPowers.DOMWindowUtils.sendNativeMouseEvent(aX, aY, aNativeMsg, aModifiers, aElement, observer); + return true; + } + + function* runTests() { + var utils = SpecialPowers.DOMWindowUtils; + var scale = utils.screenPixelsPerCSSPixel; + + var plugin1 = document.getElementById("plugin1"); // What we're testing. + var plugin2 = document.getElementById("plugin2"); // Dummy. + + var plugin1Bounds = plugin1.getBoundingClientRect(); + var plugin2Bounds = plugin2.getBoundingClientRect(); + + var plugin1X = (window.mozInnerScreenX + plugin1Bounds.left + 10); + var plugin1Y = (window.mozInnerScreenY + plugin1Bounds.top + 10); + var plugin2X = (window.mozInnerScreenX + plugin2Bounds.left + 10); + var plugin2Y = (window.mozInnerScreenY + plugin2Bounds.top + 10); + + const NSLeftMouseDown = 1, + NSLeftMouseUp = 2; + + if (plugin1.getEventModel() != 1) { + window.opener.todo(false, "Skipping this test when not testing the Cocoa event model"); + return; + } + + // Initialize to 0 since there is no initial state event, + // plugins should assume they do not initially have focus. + var expectedEventCount = 0; + + // Make sure initial event count is correct. + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Make sure initial focus state is unknown (assumed false). + var initialStateUnknown = false; + try { + plugin1.getFocusState(); + } catch (e) { + initialStateUnknown = true; + } + is(initialStateUnknown, true, "Initial state should be unknown, assumed false."); + + // Give the plugin focus (the window is already focused). + yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1, continueTest); + yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1, continueTest); + expectedEventCount++; + + is(plugin1.getFocusState(), true, "(1) Plugin should have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Make sure window activation state changes don't spontaneously + // change plugin focus. + + // Blur the window. + SpecialPowers.focus(opener); + + is(plugin1.getFocusState(), true, "(2) Plugin should still have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Focus the window. + SpecialPowers.focus(window); + + is(plugin1.getFocusState(), true, "(3) Plugin should still have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Take focus from the plugin. + yield synthesizeNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseDown, 0, plugin2, continueTest); + yield synthesizeNativeMouseEvent(plugin2X * scale, plugin2Y * scale, NSLeftMouseUp, 0, plugin2, continueTest); + expectedEventCount++; + + is(plugin1.getFocusState(), false, "(4) Plugin should not have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Make sure window activation causes the plugin to be informed of focus + // changes that took place while the window was inactive. + + // Give the plugin focus (the window is already focused). + yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseDown, 0, plugin1, continueTest); + yield synthesizeNativeMouseEvent(plugin1X * scale, plugin1Y * scale, NSLeftMouseUp, 0, plugin1, continueTest); + expectedEventCount++; + + // Blur the window. + SpecialPowers.focus(opener); + + // Take focus from the plugin while the window is blurred. + plugin2.focus(); + + is(plugin1.getFocusState(), true, "(5) Plugin should still have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + + // Focus the window. + SpecialPowers.focus(window); + expectedEventCount++; + + is(plugin1.getFocusState(), false, "(6) Plugin should not have focus."); + is(plugin1.getFocusEventCount(), expectedEventCount, "Focus event count should be " + expectedEventCount); + } + + var gTestContinuation = null; + function continueTest() { + if (!gTestContinuation) { + gTestContinuation = runTests(); + } + var ret = gTestContinuation.next(); + if (ret.done) { + window.opener.testsFinished(); + } else { + is(ret.value, true, "Mouse event successfully synthesized"); + } + } + + // Onload hander doesn't work for these tests -- no events arrive at the plugin. + window.opener.SimpleTest.waitForFocus(continueTest, window); + + </script> +</body> +</html> |