toolkit/content/tests/chrome/test_bug624329.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 type="text/css" href="chrome://global/skin"?>
michael@0 3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 4 <!--
michael@0 5 https://bugzilla.mozilla.org/show_bug.cgi?id=624329
michael@0 6 -->
michael@0 7 <window title="Mozilla Bug 624329 context menu position"
michael@0 8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
michael@0 11
michael@0 12 <!-- test results are displayed in the html:body -->
michael@0 13 <body xmlns="http://www.w3.org/1999/xhtml"
michael@0 14 onload="openTestWindow()">
michael@0 15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=624329"
michael@0 16 target="_blank">Mozilla Bug 624329</a>
michael@0 17 </body>
michael@0 18
michael@0 19 <!-- test code goes here -->
michael@0 20 <script type="application/javascript">
michael@0 21 <![CDATA[
michael@0 22 /** Test for Bug 624329 **/
michael@0 23
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 var win;
michael@0 27 var timeoutID;
michael@0 28 var menu;
michael@0 29
michael@0 30 function openTestWindow() {
michael@0 31 win = open("bug624329_window.xul", "_blank", "width=300,resizable=yes,chrome");
michael@0 32 // Close our window if the test times out so that it doesn't interfere
michael@0 33 // with later tests.
michael@0 34 timeoutID = setTimeout(function () {
michael@0 35 ok(false, "Test timed out.");
michael@0 36 // Provide some time for a screenshot
michael@0 37 setTimeout(finish, 1000);
michael@0 38 }, 20000);
michael@0 39 }
michael@0 40
michael@0 41 function listenOnce(event, callback) {
michael@0 42 win.addEventListener(event, function listener() {
michael@0 43 win.removeEventListener(event, listener, false);
michael@0 44 callback();
michael@0 45 }, false);
michael@0 46 }
michael@0 47
michael@0 48 function childFocused() {
michael@0 49 // maximizing the window is a simple way to ensure that the menu is near
michael@0 50 // the right edge of the screen.
michael@0 51
michael@0 52 listenOnce("resize", childResized);
michael@0 53 win.maximize();
michael@0 54 }
michael@0 55
michael@0 56 function childResized() {
michael@0 57 const isOSXLion = navigator.userAgent.indexOf("Mac OS X 10.7") != -1;
michael@0 58 const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1;
michael@0 59 const isOSXMavericks = navigator.userAgent.indexOf("Mac OS X 10.9") != -1;
michael@0 60 if (isOSXLion || isOSXMtnLion || isOSXMavericks) {
michael@0 61 todo_is(win.windowState, win.STATE_MAXIMIZED,
michael@0 62 "A resize before being maximized breaks this test on 10.7 and 10.8 and 10.9");
michael@0 63 finish();
michael@0 64 return;
michael@0 65 }
michael@0 66
michael@0 67 is(win.windowState, win.STATE_MAXIMIZED,
michael@0 68 "window should be maximized");
michael@0 69
michael@0 70 isnot(win.innerWidth, 300,
michael@0 71 "window inner width should have changed");
michael@0 72
michael@0 73 openContextMenu();
michael@0 74 }
michael@0 75
michael@0 76 function openContextMenu() {
michael@0 77 var mouseX = win.innerWidth - 10;
michael@0 78 var mouseY = 10;
michael@0 79
michael@0 80 menu = win.document.getElementById("menu");
michael@0 81 var screenX = menu.boxObject.screenX;
michael@0 82 var screenY = menu.boxObject.screenY;
michael@0 83 var utils =
michael@0 84 win.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
michael@0 85 getInterface(Components.interfaces.nsIDOMWindowUtils);
michael@0 86
michael@0 87 utils.sendMouseEvent("contextmenu", mouseX, mouseY, 2, 0, 0);
michael@0 88
michael@0 89 var interval = setInterval(checkMoved, 200);
michael@0 90 function checkMoved() {
michael@0 91 if (menu.boxObject.screenX != screenX ||
michael@0 92 menu.boxObject.screenY != screenY) {
michael@0 93 clearInterval(interval);
michael@0 94 // Wait further to check that the window does not move again.
michael@0 95 setTimeout(checkPosition, 1000);
michael@0 96 }
michael@0 97 }
michael@0 98
michael@0 99 function checkPosition() {
michael@0 100 var menubox = menu.boxObject;
michael@0 101 var winbox = win.document.documentElement.boxObject
michael@0 102
michael@0 103 var x = menubox.screenX - winbox.screenX;
michael@0 104 var y = menubox.screenY - winbox.screenY;
michael@0 105 ok(y >= mouseY,
michael@0 106 "menu top " + y + " should be below click point " + mouseY);
michael@0 107 ok(y <= mouseY + 20,
michael@0 108 "menu top " + y + " should not be too far below click point " + mouseY);
michael@0 109
michael@0 110 ok(x < mouseX,
michael@0 111 "menu left " + x + " should be left of click point " + mouseX);
michael@0 112 var right = x + menubox.width;
michael@0 113 ok(right > mouseX,
michael@0 114 "menu right " + right + " should be right of click point " + mouseX);
michael@0 115
michael@0 116 clearTimeout(timeoutID);
michael@0 117 finish();
michael@0 118 }
michael@0 119
michael@0 120 }
michael@0 121
michael@0 122 function finish() {
michael@0 123 if (menu && navigator.platform.indexOf("Win") >= 0) {
michael@0 124 todo(false, "Should not have to hide popup before closing its window");
michael@0 125 // This avoids mochitest "Unable to restore focus" errors (bug 670053).
michael@0 126 menu.hidePopup();
michael@0 127 }
michael@0 128 win.close();
michael@0 129 SimpleTest.finish();
michael@0 130 }
michael@0 131
michael@0 132 ]]>
michael@0 133 </script>
michael@0 134 </window>

mercurial