widget/tests/test_panel_mouse_coords.xul
author Jan de Mooij <jdemooij@mozilla.com>
Sat, 12 Jan 2019 10:50:04 +0000
changeset 453631 cfa1c48c717048f00eb4811b5719cd716eb1e5b3
parent 428244 d2df9ae93b11d29cb471fbecdf9616c277a27dd2
child 469642 0d9b9b96f5475adbed73922da696aeff7cbbaed3
permissions -rw-r--r--
Bug 1518753 part 5 - Stop using JSProtoKey for initial shapes. r=tcampbell I added this optimization in bug 1299107 to share more shapes across compartments. Unfortunately this doesn't play well with same-compartment realms (ICs can misbehave) because it relies on compartments being isolated from each other. I think we should remove this optimization: * Fixing the IC issue is impossible without deoptimizing everything. * I added it mainly for chrome globals. The shared-JSM-global work has eliminated the need for this there. * Same-compartment realms win memory back by eliminating CCWs etc. * It's quite a lot of complicated code. Differential Revision: https://phabricator.services.mozilla.com/D16170

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=835044
-->
<window title="Mozilla Bug 835044"
        onload="startTest()"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

<panel id="thepanel" level="parent"
       onpopupshown="sendMouseEvent();"
       onmousemove="checkCoords(event);"
       width="80" height="80">
</panel>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=835044"
     id="anchor"
     target="_blank">Mozilla Bug 835044</a>
  </body>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[
SimpleTest.waitForExplicitFinish();

let utils = window.windowUtils;
let panel = document.getElementById('thepanel');
let nativeMouseMove;
let rect;

function startTest() {
    let widgetToolkit = Cc["@mozilla.org/xre/app-info;1"].
        getService(Ci.nsIXULRuntime).widgetToolkit;

    if (widgetToolkit == "cocoa") {
        nativeMouseMove = 5; // NSMouseMoved
    } else if (widgetToolkit == "windows") {
        nativeMouseMove = 1; // MOUSEEVENTF_MOVE
    } else if (/^gtk/.test(widgetToolkit)) {
        nativeMouseMove = 3; // GDK_MOTION_NOTIFY
    } else {
        todo_is("widgetToolkit", widgetToolkit, "Platform not supported");
        done();
    }

    // This first event is to ensure that the next event will have different
    // coordinates to the previous mouse position, and so actually generates
    // mouse events.  The mouse is not moved off the window, as that might
    // move focus to another application.
    utils.sendNativeMouseEvent(window.mozInnerScreenX, window.mozInnerScreenY,
                               nativeMouseMove, 0, window.documentElement);

    panel.openPopup(document.getElementById("anchor"), "after_start");
}

function sendMouseEvent() {
    rect = panel.getBoundingClientRect();
    let x = window.mozInnerScreenX + rect.left + 1;
    let y = window.mozInnerScreenY + rect.top + 2;
    utils.sendNativeMouseEvent(x, y, nativeMouseMove, 0,
                               window.documentElement);
}

function checkCoords(event) {
    is(event.clientX, rect.left + 1, "Motion x coordinate");
    is(event.clientY, rect.top + 2, "Motion y coordinate");
    done();
}

function done() {
  SimpleTest.finish();
}
  ]]>
  </script>
</window>