toolkit/content/tests/chrome/frame_popup_anchor.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/frame_popup_anchor.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +
     1.7 +<page xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     1.8 +
     1.9 +<script type="application/javascript"
    1.10 +        src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    1.11 +
    1.12 +<menupopup id="popup" onpopupshowing="if (isSecondTest) popupShowing(event)" onpopupshown="popupShown()"
    1.13 +                      onpopuphidden="nextTest()">
    1.14 +  <menuitem label="One"/>
    1.15 +  <menuitem label="Two"/>
    1.16 +</menupopup>
    1.17 +
    1.18 +<button id="button" label="OK" popup="popup"/>
    1.19 +
    1.20 +<script class="testbody" type="application/javascript">
    1.21 +<![CDATA[
    1.22 +
    1.23 +var isSecondTest = false;
    1.24 +
    1.25 +function openPopup()
    1.26 +{
    1.27 +  document.getElementById("popup").openPopup(parent.document.getElementById("outerbutton"), "after_start", 3, 1);
    1.28 +}
    1.29 +
    1.30 +function popupShowing(event)
    1.31 +{
    1.32 +  var buttonrect = document.getElementById("button").getBoundingClientRect();
    1.33 +  parent.opener.wrappedJSObject.SimpleTest.is(event.clientX, buttonrect.left + 6, "popup clientX with mouse");
    1.34 +  parent.opener.wrappedJSObject.SimpleTest.is(event.clientY, buttonrect.top + 6, "popup clientY with mouse");
    1.35 +}
    1.36 +
    1.37 +function popupShown()
    1.38 +{
    1.39 +  var left, top;
    1.40 +  var popuprect = document.getElementById("popup").getBoundingClientRect();
    1.41 +  if (isSecondTest) {
    1.42 +    var buttonrect = document.getElementById("button").getBoundingClientRect();
    1.43 +    left = buttonrect.left + 6;
    1.44 +    top = buttonrect.top + 6;
    1.45 +  }
    1.46 +  else {
    1.47 +    var iframerect = parent.document.getElementById("frame").getBoundingClientRect();
    1.48 +    var buttonrect = parent.document.getElementById("outerbutton").getBoundingClientRect();
    1.49 +
    1.50 +    // The popup should appear anchored on the bottom left edge of the button, however
    1.51 +    // the client rectangle is relative to the iframe's document. Thus the coordinates
    1.52 +    // are:
    1.53 +    //  left = iframe's left - anchor button's left - 3 pixel offset passed to openPopup +
    1.54 +    //         iframe border (17px) + iframe padding (0)
    1.55 +    //  top = iframe's top - anchor button's bottom - 1 pixel offset passed to openPopup +
    1.56 +    //        iframe border (0) + iframe padding (3px);
    1.57 +    left = -(Math.round(iframerect.left) - Math.round(buttonrect.left) + 14);
    1.58 +    top = -(Math.round(iframerect.top) - Math.round(buttonrect.bottom) + 2);
    1.59 +  }
    1.60 +
    1.61 +  var testid = isSecondTest ? "with mouse" : "anchored to parent frame";
    1.62 +  parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.left), left, "popup left " + testid);
    1.63 +  parent.opener.wrappedJSObject.SimpleTest.is(Math.round(popuprect.top), top, "popup top " + testid);
    1.64 +
    1.65 +  document.getElementById("popup").hidePopup();
    1.66 +}
    1.67 +
    1.68 +function nextTest()
    1.69 +{
    1.70 +  if (isSecondTest) {
    1.71 +    parent.opener.wrappedJSObject.SimpleTest.finish();
    1.72 +    parent.close();
    1.73 +  }
    1.74 +  else {
    1.75 +    // this second test ensures that the popupshowing coordinates when a popup in
    1.76 +    // a frame is opened are correct 
    1.77 +    isSecondTest = true;
    1.78 +    synthesizeMouse(document.getElementById("button"), 6, 6, { });
    1.79 +  }
    1.80 +}
    1.81 +
    1.82 +]]>
    1.83 +</script>
    1.84 +
    1.85 +</page>

mercurial