toolkit/content/tests/chrome/test_popupincontent.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_popupincontent.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     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 in Content Positioning Tests"
     1.9 +        onload="setTimeout(nextTest, 0);"
    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 +<!--
    1.16 +  This test checks that popups in content areas don't extend past the content area.
    1.17 +  -->
    1.18 +
    1.19 +<hbox>
    1.20 +  <spacer width="100"/>
    1.21 +  <menu id="menu" label="Menu">
    1.22 +    <menupopup style="margin:10px;" id="popup" onpopupshown="popupShown()" onpopuphidden="nextTest()">
    1.23 +      <menuitem label="One"/>
    1.24 +      <menuitem label="Two"/>
    1.25 +      <menuitem label="Three"/>
    1.26 +      <menuitem label="A final longer label that is actually quite long. Very long indeed."/>
    1.27 +    </menupopup>
    1.28 +  </menu>
    1.29 +</hbox>
    1.30 +
    1.31 +<script class="testbody" type="application/javascript">
    1.32 +<![CDATA[
    1.33 +
    1.34 +SimpleTest.waitForExplicitFinish();
    1.35 +
    1.36 +var step = "";
    1.37 +var originalHeight = -1;
    1.38 +
    1.39 +function nextTest()
    1.40 +{
    1.41 +  // there are five tests here:
    1.42 +  //   openPopupAtScreen - checks that opening a popup using openPopupAtScreen
    1.43 +  //                       constrains the popup to the content area
    1.44 +  //   left and top - check with the left and top attributes set
    1.45 +  //   open near bottom - open the menu near the bottom of the window
    1.46 +  //   large menu - try with a menu that is very large and should be scaled
    1.47 +  //   shorter menu again - try with a menu that is shorter again. It should have
    1.48 +  //                        the same height as the 'left and top' test
    1.49 +  var popup = $("popup");
    1.50 +  var menu = $("menu");
    1.51 +  switch (step) {
    1.52 +    case "":
    1.53 +      step = "openPopupAtScreen";
    1.54 +      popup.openPopupAtScreen(1000, 1200);
    1.55 +      break;
    1.56 +    case "openPopupAtScreen":
    1.57 +      step = "left and top";
    1.58 +      popup.setAttribute("left", "800");
    1.59 +      popup.setAttribute("top", "2900");
    1.60 +      synthesizeMouse(menu, 2, 2, { });
    1.61 +      break;
    1.62 +    case "left and top":
    1.63 +      step = "open near bottom";
    1.64 +      // request that the menu be opened with a target point near the bottom of the window,
    1.65 +      // so that the menu's top margin will push it completely outside the window.
    1.66 +      var bo = document.documentElement.boxObject;
    1.67 +      popup.setAttribute("top", bo.screenY + window.innerHeight - 5);
    1.68 +      synthesizeMouse(menu, 2, 2, { });
    1.69 +      break;
    1.70 +    case "open near bottom":
    1.71 +      step = "large menu";
    1.72 +      popup.removeAttribute("left");
    1.73 +      popup.removeAttribute("top");
    1.74 +      for (var i = 0; i < 80; i++)
    1.75 +        menu.appendItem("Test", "");
    1.76 +      synthesizeMouse(menu, 2, 2, { });
    1.77 +      break;
    1.78 +    case "large menu":
    1.79 +      step = "shorter menu again";
    1.80 +      for (var i = 0; i < 80; i++)
    1.81 +        menu.removeItemAt(menu.itemCount - 1);
    1.82 +      synthesizeMouse(menu, 2, 2, { });
    1.83 +      break;
    1.84 +    case "shorter menu again":
    1.85 +      SimpleTest.finish();
    1.86 +      break;
    1.87 +  }
    1.88 +}
    1.89 +
    1.90 +function popupShown()
    1.91 +{
    1.92 +  var windowrect = document.documentElement.getBoundingClientRect();
    1.93 +  var popuprect = $("popup").getBoundingClientRect();
    1.94 +
    1.95 +  // subtract one off the edge due to a rounding issue
    1.96 +  ok(popuprect.left >= windowrect.left, step + " left");
    1.97 +  ok(popuprect.right - 1 <= windowrect.right, step + " right");
    1.98 +
    1.99 +  if (step == "left and top") {
   1.100 +    originalHeight = popuprect.bottom - popuprect.top;
   1.101 +  }
   1.102 +  else if (step == "open near bottom") {
   1.103 +    // check that the menu flipped up so it's above our requested point
   1.104 +    ok(popuprect.bottom - 1 <= windowrect.bottom - 5, step + " bottom");
   1.105 +  }
   1.106 +  else if (step == "large menu") {
   1.107 +    // add 10 to account for the margin
   1.108 +    is(popuprect.top, $("menu").getBoundingClientRect().bottom + 10, step + " top");
   1.109 +    ok(popuprect.bottom == windowrect.bottom ||
   1.110 +       popuprect.bottom - 1 == windowrect.bottom, step + " bottom");
   1.111 +  }
   1.112 +  else {
   1.113 +    ok(popuprect.top >= windowrect.top, step + " top");
   1.114 +    ok(popuprect.bottom - 1 <= windowrect.bottom, step + " bottom");
   1.115 +    if (step == "shorter menu again")
   1.116 +      is(popuprect.bottom - popuprect.top, originalHeight, step + " height shortened");
   1.117 +  }
   1.118 +
   1.119 +  $("menu").open = false;
   1.120 +}
   1.121 + 
   1.122 +]]>
   1.123 +</script>
   1.124 +
   1.125 +<body xmlns="http://www.w3.org/1999/xhtml">
   1.126 +<p id="display">
   1.127 +</p>
   1.128 +<div id="content" style="display: none">
   1.129 +</div>
   1.130 +<pre id="test">
   1.131 +</pre>
   1.132 +</body>
   1.133 +
   1.134 +</window>

mercurial