1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/content/tests/chrome/test_bug624329.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=624329 1.9 +--> 1.10 +<window title="Mozilla Bug 624329 context menu position" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.14 + 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml" 1.17 + onload="openTestWindow()"> 1.18 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=624329" 1.19 + target="_blank">Mozilla Bug 624329</a> 1.20 + </body> 1.21 + 1.22 + <!-- test code goes here --> 1.23 + <script type="application/javascript"> 1.24 + <![CDATA[ 1.25 + /** Test for Bug 624329 **/ 1.26 + 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 + 1.29 +var win; 1.30 +var timeoutID; 1.31 +var menu; 1.32 + 1.33 +function openTestWindow() { 1.34 + win = open("bug624329_window.xul", "_blank", "width=300,resizable=yes,chrome"); 1.35 + // Close our window if the test times out so that it doesn't interfere 1.36 + // with later tests. 1.37 + timeoutID = setTimeout(function () { 1.38 + ok(false, "Test timed out."); 1.39 + // Provide some time for a screenshot 1.40 + setTimeout(finish, 1000); 1.41 + }, 20000); 1.42 +} 1.43 + 1.44 +function listenOnce(event, callback) { 1.45 + win.addEventListener(event, function listener() { 1.46 + win.removeEventListener(event, listener, false); 1.47 + callback(); 1.48 + }, false); 1.49 +} 1.50 + 1.51 +function childFocused() { 1.52 + // maximizing the window is a simple way to ensure that the menu is near 1.53 + // the right edge of the screen. 1.54 + 1.55 + listenOnce("resize", childResized); 1.56 + win.maximize(); 1.57 +} 1.58 + 1.59 +function childResized() { 1.60 + const isOSXLion = navigator.userAgent.indexOf("Mac OS X 10.7") != -1; 1.61 + const isOSXMtnLion = navigator.userAgent.indexOf("Mac OS X 10.8") != -1; 1.62 + const isOSXMavericks = navigator.userAgent.indexOf("Mac OS X 10.9") != -1; 1.63 + if (isOSXLion || isOSXMtnLion || isOSXMavericks) { 1.64 + todo_is(win.windowState, win.STATE_MAXIMIZED, 1.65 + "A resize before being maximized breaks this test on 10.7 and 10.8 and 10.9"); 1.66 + finish(); 1.67 + return; 1.68 + } 1.69 + 1.70 + is(win.windowState, win.STATE_MAXIMIZED, 1.71 + "window should be maximized"); 1.72 + 1.73 + isnot(win.innerWidth, 300, 1.74 + "window inner width should have changed"); 1.75 + 1.76 + openContextMenu(); 1.77 +} 1.78 + 1.79 +function openContextMenu() { 1.80 + var mouseX = win.innerWidth - 10; 1.81 + var mouseY = 10; 1.82 + 1.83 + menu = win.document.getElementById("menu"); 1.84 + var screenX = menu.boxObject.screenX; 1.85 + var screenY = menu.boxObject.screenY; 1.86 + var utils = 1.87 + win.QueryInterface(Components.interfaces.nsIInterfaceRequestor). 1.88 + getInterface(Components.interfaces.nsIDOMWindowUtils); 1.89 + 1.90 + utils.sendMouseEvent("contextmenu", mouseX, mouseY, 2, 0, 0); 1.91 + 1.92 + var interval = setInterval(checkMoved, 200); 1.93 + function checkMoved() { 1.94 + if (menu.boxObject.screenX != screenX || 1.95 + menu.boxObject.screenY != screenY) { 1.96 + clearInterval(interval); 1.97 + // Wait further to check that the window does not move again. 1.98 + setTimeout(checkPosition, 1000); 1.99 + } 1.100 + } 1.101 + 1.102 + function checkPosition() { 1.103 + var menubox = menu.boxObject; 1.104 + var winbox = win.document.documentElement.boxObject 1.105 + 1.106 + var x = menubox.screenX - winbox.screenX; 1.107 + var y = menubox.screenY - winbox.screenY; 1.108 + ok(y >= mouseY, 1.109 + "menu top " + y + " should be below click point " + mouseY); 1.110 + ok(y <= mouseY + 20, 1.111 + "menu top " + y + " should not be too far below click point " + mouseY); 1.112 + 1.113 + ok(x < mouseX, 1.114 + "menu left " + x + " should be left of click point " + mouseX); 1.115 + var right = x + menubox.width; 1.116 + ok(right > mouseX, 1.117 + "menu right " + right + " should be right of click point " + mouseX); 1.118 + 1.119 + clearTimeout(timeoutID); 1.120 + finish(); 1.121 + } 1.122 + 1.123 +} 1.124 + 1.125 +function finish() { 1.126 + if (menu && navigator.platform.indexOf("Win") >= 0) { 1.127 + todo(false, "Should not have to hide popup before closing its window"); 1.128 + // This avoids mochitest "Unable to restore focus" errors (bug 670053). 1.129 + menu.hidePopup(); 1.130 + } 1.131 + win.close(); 1.132 + SimpleTest.finish(); 1.133 +} 1.134 + 1.135 + ]]> 1.136 + </script> 1.137 +</window>