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 /layout/generic/test/plugin_focus_helper.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 'layout/generic/test/plugin_focus_helper.html')
-rw-r--r-- | layout/generic/test/plugin_focus_helper.html | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/layout/generic/test/plugin_focus_helper.html b/layout/generic/test/plugin_focus_helper.html new file mode 100644 index 000000000..49f712b5a --- /dev/null +++ b/layout/generic/test/plugin_focus_helper.html @@ -0,0 +1,134 @@ +<html> +<head> + <title>Test that clicking on plugins transfers focus correctly</title> + <style> + embed { width:200px; height:200px; } + </style> +</head> +<body> + +<p><input type="text" id="input"></input> +<p><embed id="p1" type="application/x-test" wmode="window" paintscript="didPaint('p1')"> + <embed id="p2" type="application/x-test" paintscript="didPaint('p2')"></p> + +<script type="text/javascript"> +var SimpleTest = window.opener.SimpleTest; +var is = window.opener.is; +var ok = window.opener.ok; +var todo = window.opener.todo; +var info = window.opener.info; + +SimpleTest.waitForExplicitFinish(); + +// We don't want to trigger native mouse events until the document is fully +// loaded and each plugin has painted once. +var expectPaints = 2; +var loaded = false; +function didPaint(id) { + ok(--expectPaints >= 0, "Got plugin painted event from "+id); + document.getElementById(id).setAttribute("paintscript", null); + if (expectPaints == 0) { + if (document.readyState == "complete") { + theTest(); + } else { + info("Waiting for document load to continue"); + window.addEventListener("load", function() { theTest(); }); + } + } +} + +// +// Begin the test +// +function theTest() { + +const Cc = SpecialPowers.Cc; +const Ci = SpecialPowers.Ci; +var gWindowUtils = SpecialPowers.wrap(window) + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + +var nativeMouseDown; +var nativeMouseUp; + +function nativeClickElement(id) { + return function() { + + var element = document.getElementById(id); + var bounds = element.getBoundingClientRect(); + var x = (bounds.left + window.mozInnerScreenX + 10); + var y = (bounds.top + window.mozInnerScreenY + 10); + + SimpleTest.executeSoon(function () { + gWindowUtils.sendNativeMouseEvent(x, y, nativeMouseDown, 0, element); + gWindowUtils.sendNativeMouseEvent(x, y, nativeMouseUp, 0, element); + }); + }; +} + +function done() { + // Something about this test is losing focus to the OS intermittently, remove + // the windowed plugins and wait for this window to be focused before + // continuing. (Bug 874843) + for (var p of [ "p1", "p2" ]) { + p = document.getElementById(p); + p.parentNode.removeChild(p); + p = null; + } + SimpleTest.waitForFocus(window.opener.childDone, window); +} + +var step = 0; +var steps = [ + { event:"focus", id:"input", action:nativeClickElement("p1") }, + { event:"blur", id:"input" }, + { event:"focus", id:"p1", action:nativeClickElement("p2") }, + { event:"blur", id:"p1" }, + { event:"focus", id:"p2", action:nativeClickElement("input") }, + { event:"blur", id:"p2" }, + { event:"focus", id:"input", action:done } +]; + +function handleEvent(event) { + if (step >= steps.length) + return; + + var s = steps[step++]; + is(event.type, s.event, "Check event type"); + is(event.target.id, s.id, "Check event target"); + + if (s.action) { + SimpleTest.executeSoon(s.action); + } +} + +var elems = ["input", "p1", "p2"]; +for (var i = 0; i < elems.length; ++i) { + var e = document.getElementById(elems[i]); + e.addEventListener("focus", handleEvent, false); + e.addEventListener("blur", handleEvent, false); +} + +function doTest() { + input.focus(); +} + +if (navigator.platform.indexOf("Mac") >= 0) { + nativeMouseDown = 1; // NSLeftMouseDown + nativeMouseUp = 2; // NSLeftMouseUp + SimpleTest.waitForFocus(doTest, window); +} else if (navigator.platform.indexOf("Win") >= 0) { + nativeMouseDown = 2; // MOUSEEVENTF_LEFTDOWN + nativeMouseUp = 4; // MOUSEEVENTF_LEFTUP + SimpleTest.waitForFocus(doTest, window); +} else { + // XXX(johns): our gtk2 sendNativeMouseEvent doesn't support clicks + todo(false, "Platform not supported"); + done(); +} + +} // function theTest +</script> + +</body> +</html> |