layout/generic/test/plugin_focus_helper.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Test that clicking on plugins transfers focus correctly</title>
michael@0 4 <style>
michael@0 5 embed { width:200px; height:200px; }
michael@0 6 </style>
michael@0 7 </head>
michael@0 8 <body>
michael@0 9
michael@0 10 <p><input type="text" id="input"></input>
michael@0 11 <p><embed id="p1" type="application/x-test" wmode="window" paintscript="didPaint('p1')">
michael@0 12 <embed id="p2" type="application/x-test" paintscript="didPaint('p2')"></p>
michael@0 13
michael@0 14 <script type="text/javascript">
michael@0 15 var SimpleTest = window.opener.SimpleTest;
michael@0 16 var is = window.opener.is;
michael@0 17 var ok = window.opener.ok;
michael@0 18 var todo = window.opener.todo;
michael@0 19 var info = window.opener.info;
michael@0 20
michael@0 21 SimpleTest.waitForExplicitFinish();
michael@0 22
michael@0 23 // We don't want to trigger native mouse events until the document is fully
michael@0 24 // loaded and each plugin has painted once.
michael@0 25 var expectPaints = 2;
michael@0 26 var loaded = false;
michael@0 27 function didPaint(id) {
michael@0 28 ok(--expectPaints >= 0, "Got plugin painted event from "+id);
michael@0 29 document.getElementById(id).setAttribute("paintscript", null);
michael@0 30 if (expectPaints == 0) {
michael@0 31 if (document.readyState == "complete") {
michael@0 32 theTest();
michael@0 33 } else {
michael@0 34 info("Waiting for document load to continue");
michael@0 35 window.addEventListener("load", function() { theTest(); });
michael@0 36 }
michael@0 37 }
michael@0 38 }
michael@0 39
michael@0 40 //
michael@0 41 // Begin the test
michael@0 42 //
michael@0 43 function theTest() {
michael@0 44
michael@0 45 const Cc = SpecialPowers.Cc;
michael@0 46 const Ci = SpecialPowers.Ci;
michael@0 47 var gWindowUtils = SpecialPowers.wrap(window)
michael@0 48 .QueryInterface(Ci.nsIInterfaceRequestor)
michael@0 49 .getInterface(Ci.nsIDOMWindowUtils);
michael@0 50
michael@0 51 var nativeMouseDown;
michael@0 52 var nativeMouseUp;
michael@0 53
michael@0 54 function nativeClickElement(id) {
michael@0 55 return function() {
michael@0 56
michael@0 57 var element = document.getElementById(id);
michael@0 58 var bounds = element.getBoundingClientRect();
michael@0 59 var x = (bounds.left + window.mozInnerScreenX + 10);
michael@0 60 var y = (bounds.top + window.mozInnerScreenY + 10);
michael@0 61
michael@0 62 SimpleTest.executeSoon(function () {
michael@0 63 gWindowUtils.sendNativeMouseEvent(x, y, nativeMouseDown, 0, element);
michael@0 64 gWindowUtils.sendNativeMouseEvent(x, y, nativeMouseUp, 0, element);
michael@0 65 });
michael@0 66 };
michael@0 67 }
michael@0 68
michael@0 69 function done() {
michael@0 70 // Something about this test is losing focus to the OS intermittently, remove
michael@0 71 // the windowed plugins and wait for this window to be focused before
michael@0 72 // continuing. (Bug 874843)
michael@0 73 for (var p of [ "p1", "p2" ]) {
michael@0 74 p = document.getElementById(p);
michael@0 75 p.parentNode.removeChild(p);
michael@0 76 p = null;
michael@0 77 }
michael@0 78 SimpleTest.waitForFocus(window.opener.childDone, window);
michael@0 79 }
michael@0 80
michael@0 81 var step = 0;
michael@0 82 var steps = [
michael@0 83 { event:"focus", id:"input", action:nativeClickElement("p1") },
michael@0 84 { event:"blur", id:"input" },
michael@0 85 { event:"focus", id:"p1", action:nativeClickElement("p2") },
michael@0 86 { event:"blur", id:"p1" },
michael@0 87 { event:"focus", id:"p2", action:nativeClickElement("input") },
michael@0 88 { event:"blur", id:"p2" },
michael@0 89 { event:"focus", id:"input", action:done }
michael@0 90 ];
michael@0 91
michael@0 92 function handleEvent(event) {
michael@0 93 if (step >= steps.length)
michael@0 94 return;
michael@0 95
michael@0 96 var s = steps[step++];
michael@0 97 is(event.type, s.event, "Check event type");
michael@0 98 is(event.target.id, s.id, "Check event target");
michael@0 99
michael@0 100 if (s.action) {
michael@0 101 SimpleTest.executeSoon(s.action);
michael@0 102 }
michael@0 103 }
michael@0 104
michael@0 105 var elems = ["input", "p1", "p2"];
michael@0 106 for (var i = 0; i < elems.length; ++i) {
michael@0 107 var e = document.getElementById(elems[i]);
michael@0 108 e.addEventListener("focus", handleEvent, false);
michael@0 109 e.addEventListener("blur", handleEvent, false);
michael@0 110 }
michael@0 111
michael@0 112 function doTest() {
michael@0 113 input.focus();
michael@0 114 }
michael@0 115
michael@0 116 if (navigator.platform.indexOf("Mac") >= 0) {
michael@0 117 nativeMouseDown = 1; // NSLeftMouseDown
michael@0 118 nativeMouseUp = 2; // NSLeftMouseUp
michael@0 119 SimpleTest.waitForFocus(doTest, window);
michael@0 120 } else if (navigator.platform.indexOf("Win") >= 0) {
michael@0 121 nativeMouseDown = 2; // MOUSEEVENTF_LEFTDOWN
michael@0 122 nativeMouseUp = 4; // MOUSEEVENTF_LEFTUP
michael@0 123 SimpleTest.waitForFocus(doTest, window);
michael@0 124 } else {
michael@0 125 // XXX(johns): our gtk2 sendNativeMouseEvent doesn't support clicks
michael@0 126 todo(false, "Platform not supported");
michael@0 127 done();
michael@0 128 }
michael@0 129
michael@0 130 } // function theTest
michael@0 131 </script>
michael@0 132
michael@0 133 </body>
michael@0 134 </html>

mercurial