DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window title="Large Menu Tests"
  onfocus="setTimeout(runTests, 0);"
  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <title>Large Menu Tests</title>

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>

<!--
  This test checks that a large menu is displayed with arrow buttons
  and is on the screen.
  -->

<script>
<![CDATA[

var gOverflowed = false, gUnderflowed = false;
var gScreenY = -1;
var gTestIndex = 0;
var gTests = ["open normal", "open flipped position", "open with scrolling",
              "open after scrolling", "open small again"];

function runTests()
{
  var mouseFn = function(event) { gScreenY = event.screenY; }

  // a hacky way to get the screen position of the document
  window.addEventListener("mousedown", mouseFn, false);
  synthesizeMouse(document.documentElement, 0, 0, { });
  window.removeEventListener("mousedown", mouseFn, false);

  nextTest();
}

function nextTest()
{
  gOverflowed = false, gUnderflowed = false;

  var y = screen.height;
  if (gTestIndex == 1) // open flipped position test:
    y -= 100;
  else
    y /= 2;

  var popup = document.getElementById("popup");
  if (gTestIndex == 2) {
    // add some more menuitems so that scrolling will be necessary
    for (var t = 1; t <= 30; t++) {
      var menu = document.createElement("menuitem");
      menu.setAttribute("label", "More" + t);
      popup.appendChild(menu);
    }
  }
  else if (gTestIndex == 4) {
    for (var t = 1; t <= 30; t++)
      popup.removeChild(popup.lastChild);
  }

  popup.openPopupAtScreen(100, y, false);
}

function popupShown()
{
  var popup = document.getElementById("popup");
  var rect = popup.getBoundingClientRect();
  var sbo = document.getAnonymousNodes(popup)[0].scrollBoxObject;
  var expectedScrollPos = 0;

  if (gTestIndex == 0) {
    // the popup should be in the center of the screen 
    is(Math.round(rect.top) + gScreenY, screen.height / 2,
                              gTests[gTestIndex] + " top");
    ok(Math.round(rect.bottom) + gScreenY < screen.height,
                                gTests[gTestIndex] + " bottom");
    ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")
  }
  else if (gTestIndex == 1) {
    // the popup was supposed to open 100 pixels from the bottom, but that
    // would put it off screen so it should be flipped to have its bottom
    // edge 100 pixels from the bottom
    ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top");
    is(Math.round(rect.bottom) + gScreenY, screen.height - 100,
                                gTests[gTestIndex] + " bottom");
    ok(!gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")
  }
  else if (gTestIndex == 2) {
    // the popup is too large so ensure that it is on screen
    ok(Math.round(rect.top) + gScreenY >= screen.top, gTests[gTestIndex] + " top");
    ok(Math.round(rect.bottom) + gScreenY < screen.height, gTests[gTestIndex] + " bottom");
    ok(gOverflowed && !gUnderflowed, gTests[gTestIndex] + " overflow")

    sbo.scrollTo(0, 40);
    expectedScrollPos = 40;
  }
  else if (gTestIndex == 3) {
    expectedScrollPos = 40;
  }
  else if (gTestIndex == 4) {
    is(Math.round(rect.top) + gScreenY, screen.height / 2,
                              gTests[gTestIndex] + " top");
    ok(Math.round(rect.bottom) + gScreenY < screen.height,
                                gTests[gTestIndex] + " bottom");
    ok(!gOverflowed && gUnderflowed, gTests[gTestIndex] + " overflow")
  }

  var sx = { }, sy = { };
  sbo.getPosition(sx, sy);
  is(sy.value, expectedScrollPos, "menu scroll position");

  popup.hidePopup();
}

function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); }
function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); }

function popupHidden()
{
  gTestIndex++;
  if (gTestIndex == gTests.length) {
    window.opener.wrappedJSObject.SimpleTest.finish();
    window.close();
  }
  else {
    nextTest();
  }
}
]]>
</script>

<label value="OK" popup="popup"/>
<menupopup id="popup" onpopupshown="popupShown();" onpopuphidden="popupHidden();"
                      onoverflow="gOverflowed = true" onunderflow="gUnderflowed = true;">
  <menuitem label="1"/>
  <menuitem label="2"/>
  <menuitem label="3"/>
  <menuitem label="4"/>
  <menuitem label="5"/>
  <menuitem label="6"/>
  <menuitem label="7"/>
  <menuitem label="8"/>
  <menuitem label="9"/>
  <menuitem label="10"/>
  <menuitem label="11"/>
  <menuitem label="12"/>
  <menuitem label="13"/>
  <menuitem label="14"/>
  <menuitem label="15"/>
</menupopup>

</window>