toolkit/content/tests/chrome/test_popupincontent.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     5 <window title="Popup in Content Positioning Tests"
     6         onload="setTimeout(nextTest, 0);"
     7         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
    10   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
    12 <!--
    13   This test checks that popups in content areas don't extend past the content area.
    14   -->
    16 <hbox>
    17   <spacer width="100"/>
    18   <menu id="menu" label="Menu">
    19     <menupopup style="margin:10px;" id="popup" onpopupshown="popupShown()" onpopuphidden="nextTest()">
    20       <menuitem label="One"/>
    21       <menuitem label="Two"/>
    22       <menuitem label="Three"/>
    23       <menuitem label="A final longer label that is actually quite long. Very long indeed."/>
    24     </menupopup>
    25   </menu>
    26 </hbox>
    28 <script class="testbody" type="application/javascript">
    29 <![CDATA[
    31 SimpleTest.waitForExplicitFinish();
    33 var step = "";
    34 var originalHeight = -1;
    36 function nextTest()
    37 {
    38   // there are five tests here:
    39   //   openPopupAtScreen - checks that opening a popup using openPopupAtScreen
    40   //                       constrains the popup to the content area
    41   //   left and top - check with the left and top attributes set
    42   //   open near bottom - open the menu near the bottom of the window
    43   //   large menu - try with a menu that is very large and should be scaled
    44   //   shorter menu again - try with a menu that is shorter again. It should have
    45   //                        the same height as the 'left and top' test
    46   var popup = $("popup");
    47   var menu = $("menu");
    48   switch (step) {
    49     case "":
    50       step = "openPopupAtScreen";
    51       popup.openPopupAtScreen(1000, 1200);
    52       break;
    53     case "openPopupAtScreen":
    54       step = "left and top";
    55       popup.setAttribute("left", "800");
    56       popup.setAttribute("top", "2900");
    57       synthesizeMouse(menu, 2, 2, { });
    58       break;
    59     case "left and top":
    60       step = "open near bottom";
    61       // request that the menu be opened with a target point near the bottom of the window,
    62       // so that the menu's top margin will push it completely outside the window.
    63       var bo = document.documentElement.boxObject;
    64       popup.setAttribute("top", bo.screenY + window.innerHeight - 5);
    65       synthesizeMouse(menu, 2, 2, { });
    66       break;
    67     case "open near bottom":
    68       step = "large menu";
    69       popup.removeAttribute("left");
    70       popup.removeAttribute("top");
    71       for (var i = 0; i < 80; i++)
    72         menu.appendItem("Test", "");
    73       synthesizeMouse(menu, 2, 2, { });
    74       break;
    75     case "large menu":
    76       step = "shorter menu again";
    77       for (var i = 0; i < 80; i++)
    78         menu.removeItemAt(menu.itemCount - 1);
    79       synthesizeMouse(menu, 2, 2, { });
    80       break;
    81     case "shorter menu again":
    82       SimpleTest.finish();
    83       break;
    84   }
    85 }
    87 function popupShown()
    88 {
    89   var windowrect = document.documentElement.getBoundingClientRect();
    90   var popuprect = $("popup").getBoundingClientRect();
    92   // subtract one off the edge due to a rounding issue
    93   ok(popuprect.left >= windowrect.left, step + " left");
    94   ok(popuprect.right - 1 <= windowrect.right, step + " right");
    96   if (step == "left and top") {
    97     originalHeight = popuprect.bottom - popuprect.top;
    98   }
    99   else if (step == "open near bottom") {
   100     // check that the menu flipped up so it's above our requested point
   101     ok(popuprect.bottom - 1 <= windowrect.bottom - 5, step + " bottom");
   102   }
   103   else if (step == "large menu") {
   104     // add 10 to account for the margin
   105     is(popuprect.top, $("menu").getBoundingClientRect().bottom + 10, step + " top");
   106     ok(popuprect.bottom == windowrect.bottom ||
   107        popuprect.bottom - 1 == windowrect.bottom, step + " bottom");
   108   }
   109   else {
   110     ok(popuprect.top >= windowrect.top, step + " top");
   111     ok(popuprect.bottom - 1 <= windowrect.bottom, step + " bottom");
   112     if (step == "shorter menu again")
   113       is(popuprect.bottom - popuprect.top, originalHeight, step + " height shortened");
   114   }
   116   $("menu").open = false;
   117 }
   119 ]]>
   120 </script>
   122 <body xmlns="http://www.w3.org/1999/xhtml">
   123 <p id="display">
   124 </p>
   125 <div id="content" style="display: none">
   126 </div>
   127 <pre id="test">
   128 </pre>
   129 </body>
   131 </window>

mercurial