toolkit/content/tests/chrome/test_popup_coords.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_popup_coords.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +
     1.8 +<window title="Popup Coordinate Tests"
     1.9 +  onload="setTimeout(openThePopup, 0, 'outer');"
    1.10 +  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.11 +
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    1.13 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    1.14 +
    1.15 +<deck style="margin-top: 5px; padding-top: 5px;">
    1.16 +  <label id="outer" popup="outerpopup" value="Popup"/>
    1.17 +</deck>
    1.18 +
    1.19 +<panel id="outerpopup"
    1.20 +           onpopupshowing="popupShowingEventOccurred(event);"
    1.21 +           onpopupshown="eventOccurred(event); openThePopup('inner')"
    1.22 +           onpopuphiding="eventOccurred(event);"
    1.23 +           onpopuphidden="eventOccurred(event); SimpleTest.finish();">
    1.24 +  <button id="item1" label="First"/>
    1.25 +  <label id="inner" value="Second" popup="innerpopup"/>
    1.26 +  <button id="item2" label="Third"/>
    1.27 +</panel>
    1.28 +
    1.29 +<menupopup id="innerpopup"
    1.30 +           onpopupshowing="popupShowingEventOccurred(event);"
    1.31 +           onpopupshown="eventOccurred(event); event.target.hidePopup();"
    1.32 +           onpopuphiding="eventOccurred(event);"
    1.33 +           onpopuphidden="eventOccurred(event); document.getElementById('outerpopup').hidePopup();">
    1.34 +  <menuitem id="inner1" label="Inner First"/>
    1.35 +  <menuitem id="inner2" label="Inner Second"/>
    1.36 +</menupopup>
    1.37 +
    1.38 +<script>
    1.39 +SimpleTest.waitForExplicitFinish();
    1.40 +
    1.41 +function openThePopup(id)
    1.42 +{
    1.43 +  if (id == "inner")
    1.44 +    document.getElementById("item1").focus();
    1.45 +
    1.46 +  var trigger = document.getElementById(id);
    1.47 +  synthesizeMouse(trigger, 4, 5, { });
    1.48 +}
    1.49 +
    1.50 +function eventOccurred(event)
    1.51 +{
    1.52 +  var testname = event.type + " on " + event.target.id + " ";
    1.53 +  ok(event instanceof MouseEvent, testname + "is a mouse event");
    1.54 +  is(event.clientX, 0, testname + "clientX");
    1.55 +  is(event.clientY, 0, testname + "clientY");
    1.56 +  is(event.rangeParent, null, testname + "rangeParent");
    1.57 +  is(event.rangeOffset, 0, testname + "rangeOffset");
    1.58 +}
    1.59 +
    1.60 +function popupShowingEventOccurred(event)
    1.61 +{
    1.62 +  // the popupshowing event should have the event coordinates and
    1.63 +  // range position filled in.
    1.64 +  var testname = "popupshowing on " + event.target.id + " ";
    1.65 +  ok(event instanceof MouseEvent, testname + "is a mouse event");
    1.66 +
    1.67 +  var trigger = document.getElementById(event.target.id == "outerpopup" ? "outer" : "inner");
    1.68 +  var rect = trigger.getBoundingClientRect();
    1.69 +  is(event.clientX, Math.round(rect.left + 4), testname + "clientX");
    1.70 +  is(event.clientY, Math.round(rect.top + 5), testname + "clientY");
    1.71 +  // rangeOffset should be just after the trigger element. As rangeOffset
    1.72 +  // considers the zeroth position to be before the first element, the value
    1.73 +  // should be one higher than its index within its parent.
    1.74 +  is(event.rangeParent, trigger.parentNode, testname + "rangeParent");
    1.75 +  is(event.rangeOffset, Array.indexOf(trigger.parentNode.childNodes, trigger) + 1, testname + "rangeOffset");
    1.76 +
    1.77 +  var popuprect = event.target.getBoundingClientRect();
    1.78 +  is(Math.round(popuprect.left), Math.round(rect.left + 4), "popup left");
    1.79 +  is(Math.round(popuprect.top), Math.round(rect.top + 5), "popup top");
    1.80 +  ok(popuprect.width > 0, "popup width");
    1.81 +  ok(popuprect.height > 0, "popup height");
    1.82 +}
    1.83 +</script>
    1.84 +
    1.85 +<body xmlns="http://www.w3.org/1999/xhtml">
    1.86 +<p id="display">
    1.87 +</p>
    1.88 +<div id="content" style="display: none">
    1.89 +</div>
    1.90 +<pre id="test">
    1.91 +</pre>
    1.92 +</body>
    1.93 +
    1.94 +</window>

mercurial