toolkit/content/tests/chrome/test_popupincontent.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial