Bug 487631, fix a number of xul tests which were disabled in the past due to not working on some platforms, these are tests for bugs 474149, 416390, 212750, 409242, r=gavin
authorNeil Deakin <neil@mozilla.com>
Wed, 22 Apr 2009 08:55:49 -0400
changeset 27617 d0699dd384f0ed6c4577b3f7730dccc8c5c44130
parent 27616 d299a5eb0f76b527e617efaf6e10aa3d2dc98927
child 27618 d02c0b3b889475b09862ab168b0d2458afe5f7c0
push id6654
push userneil@mozilla.com
push dateWed, 22 Apr 2009 12:57:00 +0000
treeherdermozilla-central@0b355aff0abd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs487631, 474149, 416390, 212750, 409242
milestone1.9.2a1pre
Bug 487631, fix a number of xul tests which were disabled in the past due to not working on some platforms, these are tests for bugs 474149, 416390, 212750, 409242, r=gavin
toolkit/content/tests/chrome/Makefile.in
toolkit/content/tests/chrome/window_largemenu.xul
toolkit/content/tests/widgets/Makefile.in
toolkit/content/tests/widgets/test_contextmenu_list.xul
toolkit/content/tests/widgets/test_popupincontent.xul
--- a/toolkit/content/tests/chrome/Makefile.in
+++ b/toolkit/content/tests/chrome/Makefile.in
@@ -81,16 +81,18 @@ include $(topsrcdir)/config/rules.mk
 		window_preferences2.xul \
 		window_preferences3.xul \
 		test_autocomplete2.xul \
 		test_autocomplete3.xul \
 		test_keys.xul \
 		window_keys.xul \
 		$(NULL)
 
+# test_panel_focus.xul won't work if the Full Keyboard Access preference is set to
+# textboxes and lists only, so skip this test on Mac
 ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 _TEST_FILES += test_panel_focus.xul \
                window_panel_focus.xul
 else
 _TEST_FILES += test_autocomplete.xul
 endif
 
 libs:: $(_TEST_FILES)
--- a/toolkit/content/tests/chrome/window_largemenu.xul
+++ b/toolkit/content/tests/chrome/window_largemenu.xul
@@ -23,29 +23,35 @@ var gTestIndex = 0;
 var gTests = ["open normal", "open flipped position", "open with scrolling",
               "open after scrolling", "open small again",
               "menu movement", "panel movement",
               "context menu enough space below",
               "context menu more space above",
               "context menu too big either side",
               "context menu larger than screen"];
 
-function setDocumentScreenY()
+function getScreenXY(element)
 {
-  var mouseFn = function(event) { gScreenY = event.screenY; }
+  var screenX, screenY;
+  var mouseFn = function(event) {
+    screenX = event.screenX - 1;
+    screenY = event.screenY - 1;
+  }
 
-  // a hacky way to get the screen position of the document
+  // a hacky way to get the screen position of an element without using the box object
   window.addEventListener("mousedown", mouseFn, false);
-  synthesizeMouse(document.documentElement, 0, 0, { });
+  synthesizeMouse(element, 1, 1, { });
   window.removeEventListener("mousedown", mouseFn, false);
+
+  return [screenX, screenY];
 }
 
 function runTests()
 {
-  setDocumentScreenY();
+  [, gScreenY] = getScreenXY(document.documentElement);
   nextTest();
 }
 
 function nextTest()
 {
   gOverflowed = false, gUnderflowed = false;
 
   var y = screen.height;
@@ -160,27 +166,26 @@ function popupHidden()
 }
 
 function contextMenuPopupShown()
 {
   var popup = document.getElementById("popup");
   var rect = popup.getBoundingClientRect();
   var labelrect = document.getElementById("label").getBoundingClientRect();
 
-  // XXXndeakin disable test on Linux for now
-    is(rect.left, labelrect.left + 6, gTests[gTestIndex] + " left");
+  is(rect.left, labelrect.left + 6, gTests[gTestIndex] + " left");
   switch (gTests[gTestIndex]) {
     case "context menu enough space below":
       is(rect.top, labelrect.top + 6, gTests[gTestIndex] + " top");
       break;
     case "context menu more space above":
       is(rect.top, labelrect.top - rect.height + 2, gTests[gTestIndex] + " top");
       break;
     case "context menu too big either side":
-      setDocumentScreenY();
+      [, gScreenY] = getScreenXY(document.documentElement);
       // compare against the available size as well as the total size, as some
       // platforms allow the menu to overlap os chrome and others do not
       // the - 3 here is to account for 3 pixels that are subtracted from the
       // screen size when sizing a popup for the popup shadow
       var pos = (screen.availTop + screen.availHeight - 3 - rect.height) - gScreenY;
       var availPos = (screen.top + screen.height - 3 - rect.height) - gScreenY;
       ok(rect.top == pos || rect.top == availPos,
          gTests[gTestIndex] + " top");
@@ -224,52 +229,64 @@ function contextMenuPopupHidden()
   synthesizeMouse(document.getElementById("label"), 4, 4, { type: "contextmenu", button: 2 });
 }
 
 function testPopupMovement()
 {
   var button = document.getElementById("label");
   var popup = document.getElementById((gTests[gTestIndex] == "panel movement") ? "panel" : "popup");
 
+  var screenX, screenY, buttonScreenX, buttonScreenY;
   var rect = popup.getBoundingClientRect();
 
   var overlapOSChrome = (navigator.platform.indexOf("Mac") == -1);
   popup.moveTo(1, 1);
-//  is(popup.boxObject.screenX, overlapOSChrome ? 1 : screen.availLeft, gTests[gTestIndex] + " (1, 1) x");
-//  is(popup.boxObject.screenY, overlapOSChrome ? 1 : screen.availTop, gTests[gTestIndex] + " (1, 1) y");
+  [screenX, screenY] = getScreenXY(popup);
+
+  var expectedx = overlapOSChrome ? 1 : (screen.availLeft < 1 ? 1 : screen.availLeft);
+  var expectedy = overlapOSChrome ? 1 : (screen.availTop < 1 ? 1 : screen.availTop);
+  is(screenX, expectedx, gTests[gTestIndex] + " (1, 1) x");
+  is(screenY, expectedy, gTests[gTestIndex] + " (1, 1) y");
 
   popup.moveTo(100, 8000);
   var expectedy = (overlapOSChrome ? screen.height + screen.top : screen.availHeight + screen.availTop) -
                   Math.round(rect.height) - 3;
-  is(popup.boxObject.screenX, 100, gTests[gTestIndex] + " (100, 8000) x");
-  is(popup.boxObject.screenY, expectedy, gTests[gTestIndex] + " (100, 8000) y");
+  [screenX, screenY] = getScreenXY(popup);
+  is(screenX, 100, gTests[gTestIndex] + " (100, 8000) x");
+  is(screenY, expectedy, gTests[gTestIndex] + " (100, 8000) y");
 
   popup.moveTo(6000, 100);
-  var expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) -
-                  Math.round(rect.width) - 3;
-//  is(popup.boxObject.screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x");
-  is(popup.boxObject.screenY, 100, gTests[gTestIndex] + " (6000, 100) y");
+  expectedx = (overlapOSChrome ? screen.width + screen.left : screen.availWidth + screen.availLeft) -
+              Math.round(rect.width) - 3;
+
+  [screenX, screenY] = getScreenXY(popup);
+  is(screenX, expectedx, gTests[gTestIndex] + " (6000, 100) x");
+  is(screenY, 100, gTests[gTestIndex] + " (6000, 100) y");
 
   is(popup.left, "", gTests[gTestIndex] + " left is empty after moving");
   is(popup.top, "", gTests[gTestIndex] + " top is empty after moving");
   popup.setAttribute("left", "80");
   popup.setAttribute("top", "82");
-  is(popup.boxObject.screenX, 80, gTests[gTestIndex] + " set left and top x");
-  is(popup.boxObject.screenY, 82, gTests[gTestIndex] + " set left and top y");
+  [screenX, screenY] = getScreenXY(popup);
+  is(screenX, 80, gTests[gTestIndex] + " set left and top x");
+  is(screenY, 82, gTests[gTestIndex] + " set left and top y");
   popup.moveTo(95, 98);
-  is(popup.boxObject.screenX, 95, gTests[gTestIndex] + " move after set left and top x");
-  is(popup.boxObject.screenY, 98, gTests[gTestIndex] + " move after set left and top y");
+  [screenX, screenY] = getScreenXY(popup);
+  is(screenX, 95, gTests[gTestIndex] + " move after set left and top x");
+  is(screenY, 98, gTests[gTestIndex] + " move after set left and top y");
   is(popup.left, "95", gTests[gTestIndex] + " left is set after moving");
   is(popup.top, "98", gTests[gTestIndex] + " top is set after moving");
   popup.removeAttribute("left");
   popup.removeAttribute("top");
 
   popup.moveTo(-1, -1);
-  is(popup.boxObject.screenX, button.boxObject.screenX, gTests[gTestIndex] + " original x");
-  is(popup.boxObject.screenY, button.boxObject.screenY + button.getBoundingClientRect().height, gTests[gTestIndex] + " original y");
+  [screenX, screenY] = getScreenXY(popup);
+  [buttonScreenX, buttonScreenY] = getScreenXY(button);
+  is(screenX, buttonScreenX, gTests[gTestIndex] + " original x");
+  is(screenY, buttonScreenY + button.getBoundingClientRect().height, gTests[gTestIndex] + " original y");
 
   popup.hidePopup();
 }
 
 ]]>
 </script>
 
 <button id="label" label="OK" context="popup"/>
@@ -287,13 +304,13 @@ function testPopupMovement()
   <menuitem label="10"/>
   <menuitem label="11"/>
   <menuitem label="12"/>
   <menuitem label="13"/>
   <menuitem label="14"/>
   <menuitem label="15"/>
 </menupopup>
 
-<panel id="panel" onpopupshown="testPopupMovement();" onpopuphidden="popupHidden();">
+<panel id="panel" onpopupshown="testPopupMovement();" onpopuphidden="popupHidden();" style="margin: 0">
   <button label="OK"/>
 </panel>
 
 </window>
--- a/toolkit/content/tests/widgets/Makefile.in
+++ b/toolkit/content/tests/widgets/Makefile.in
@@ -102,23 +102,20 @@ include $(topsrcdir)/config/rules.mk
 		test_position.xul \
 		test_menu.xul \
 		test_menu_hide.xul \
 		test_focus.xul \
 		test_tabindex.xul \
  		test_mousescroll.xul \
 		test_scrollbar.xul \
 		test_sorttemplate.xul \
+		test_contextmenu_list.xul \
 		test_videocontrols.html \
 		video.ogg \
 		$(NULL)
 
 ifeq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 _TEST_FILES += test_menubar.xul \
                window_menubar.xul
 endif
 
-ifeq (,$(filter gtk2,$(MOZ_WIDGET_TOOLKIT)))
-_TEST_FILES += test_contextmenu_list.xul 
-endif
-
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
--- a/toolkit/content/tests/widgets/test_contextmenu_list.xul
+++ b/toolkit/content/tests/widgets/test_contextmenu_list.xul
@@ -9,18 +9,18 @@
   <script type="application/javascript" src="/MochiKit/packed.js"></script>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>      
   <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>      
 
 <spacer height="5"/>
 
 <hbox style="padding-left: 10px;">
   <spacer width="5"/>
-  <richlistbox id="list" context="themenu" oncontextmenu="checkContextMenu(event)">
-    <richlistitem id="item1" style="padding-top: 3px;"><button label="One"/></richlistitem>
+  <richlistbox id="list" context="themenu" style="padding: 0;" oncontextmenu="checkContextMenu(event)">
+    <richlistitem id="item1" style="padding-top: 3px; margin: 0;"><button label="One"/></richlistitem>
     <richlistitem id="item2" height="22"><checkbox label="Checkbox"/></richlistitem>
     <richlistitem id="item3"><button label="Three"/></richlistitem>
     <richlistitem id="item4"><checkbox label="Four"/></richlistitem>
   </richlistbox>
 
   <tree id="tree" rows="5" flex="1" context="themenu" style="-moz-appearance: none; border: 0">
     <treecols>
       <treecol label="Name" flex="1"/>
@@ -81,25 +81,25 @@ var gTestElement = "list";
 var gSelectionStep = 0;
 var gContextMenuFired = false;
 
 function startTest()
 {
   // first, check if the richlistbox selection changes on a contextmenu mouse event
   var element = $("list");
   synthesizeMouse(element.getItemAtIndex(3), 7, 1, { type : "mousedown", button: 2, ctrlKey: true });
-  synthesizeMouse(element, 7, 2, { type : "contextmenu", button: 2 });
+  synthesizeMouse(element, 7, 4, { type : "contextmenu", button: 2 });
 
   gSelectionStep++;
   synthesizeMouse(element.getItemAtIndex(1), 7, 1, { type : "mousedown", button: 2, ctrlKey: true, shiftKey: true });
-  synthesizeMouse(element, 7, 2, { type : "contextmenu", button: 2 });
+  synthesizeMouse(element, 7, 4, { type : "contextmenu", button: 2 });
 
   gSelectionStep++;
   synthesizeMouse(element.getItemAtIndex(1), 7, 1, { type : "mousedown", button: 2 });
-  synthesizeMouse(element, 7, 2, { type : "contextmenu", button: 2 });
+  synthesizeMouse(element, 7, 4, { type : "contextmenu", button: 2 });
 
   $("menu").open = true;
 }
 
 function menuTests()
 {
   // context menus shouldn't open when a menu is open on Mac
   var ismac = (navigator.platform.indexOf("Mac") >= 0);
@@ -135,34 +135,34 @@ function nextTest()
   element.focus();
   if (gTestId == 0) {
     if (gTestElement == "list")
       element.selectedIndex = 2;
     element.currentIndex = 2;
     synthesizeMouse(element, 0, 0, { type : "contextmenu", button: 0 });
   }
   else if (gTestId == 1) {
-    synthesizeMouse(element, 7, 2, { type : "contextmenu", button: 2 });
+    synthesizeMouse(element, 7, 4, { type : "contextmenu", button: 2 });
   }
   else {
     element.currentIndex = -1;
     element.selectedIndex = -1;
     synthesizeMouse(element, 0, 0, { type : "contextmenu", button: 0 });
   }
 }
 
 function checkContextMenu(event)
 {
   var rect = $(gTestElement).getBoundingClientRect();
 
   var frombase = (gTestId == -1 || gTestId == 1);
   if (!frombase)
     rect = event.originalTarget.getBoundingClientRect();
   left = frombase ? rect.left + 7 : rect.left;
-  top = frombase ? rect.top + 2 : rect.bottom;
+  top = frombase ? rect.top + 4 : rect.bottom;
 
   is(event.clientX, left, gTestElement + " clientX " + gSelectionStep + " " + gTestId + "," + frombase);
   is(event.clientY, top, gTestElement + " clientY " + gSelectionStep + " " + gTestId);
   ok(event.screenX > left, gTestElement + " screenX " + gSelectionStep + " " + gTestId);
   ok(event.screenY > top, gTestElement + " screenY " + gSelectionStep + " " + gTestId);
 
   // context menu from mouse click
   switch (gTestId) {
@@ -172,19 +172,17 @@ function checkContextMenu(event)
       break;
     case 0:
       if (gTestElement == "list")
         is(event.originalTarget, $("item3"), "list selection target");
       else
         is(event.originalTarget, $("treechildren"), "tree selection target");
       break;
     case 1:
-      // XXXndeakin disable test on Windows for now
-      if (navigator.platform.indexOf("Win") == -1)
-        is(event.originalTarget.id, $("item1").id, "list mouse selection target");
+      is(event.originalTarget.id, $("item1").id, "list mouse selection target");
       break;
     case 2:
       is(event.originalTarget, $("list"), "list no selection target");
       break;
   }
 }
 
 function checkContextMenuForMenu(event)
@@ -224,17 +222,17 @@ function checkPopup()
   else if (gTestId == 1) {
     // activating a context menu with the mouse from position (7, 1).
     // Add 2 pixels to these values as context menus are offset by 2 pixels
     // so that they don't appear exactly only the menu making them easier to
     // dismiss. See nsXULPopupListener.
     var elementrect = $(gTestElement).getBoundingClientRect();
     is(Math.round(menurect.left), Math.round(elementrect.left) + 9,
        gTestElement + " mouse left");
-    is(Math.round(menurect.top), Math.round(elementrect.top) + 4,
+    is(Math.round(menurect.top), Math.round(elementrect.top) + 6,
        gTestElement + " mouse top");
   }
   else {
     var elementrect = $(gTestElement).getBoundingClientRect();
     is(Math.round(menurect.left), Math.round(elementrect.left) + 2,
        gTestElement + " no selection keyboard left");
     is(Math.round(menurect.top), Math.round(elementrect.bottom) + 2,
        gTestElement + " no selection keyboard top");
--- a/toolkit/content/tests/widgets/test_popupincontent.xul
+++ b/toolkit/content/tests/widgets/test_popupincontent.xul
@@ -16,37 +16,36 @@
 
 <hbox>
   <spacer width="100"/>
   <menu id="menu">
     <menupopup style="margin:10px;" id="popup" onpopupshown="popupShown()" onpopuphidden="nextTest()">
       <menuitem label="One"/>
       <menuitem label="Two"/>
       <menuitem label="Three"/>
-      <menuitem label="Four"/>
-      <menuitem label="Five"/>
       <menuitem label="A final longer label that is actually quite long. Very long indeed."/>
     </menupopup>
   </menu>
 </hbox>
 
 <script class="testbody" type="application/javascript">
 <![CDATA[
 
 SimpleTest.waitForExplicitFinish();
 
 var step = "";
 var originalHeight = -1;
 
 function nextTest()
 {
-  // there are four tests here:
+  // there are five tests here:
   //   openPopupAtScreen - checks that opening a popup using openPopupAtScreen
   //                       constrains the popup to the content area
   //   left and top - check with the left and top attributes set
+  //   open near bottom - open the menu near the bottom of the window
   //   large menu - try with a menu that is very large and should be scaled
   //   shorter menu again - try with a menu that is shorter again. It should have
   //                        the same height as the 'left and top' test
   var popup = $("popup");
   var menu = $("menu");
   switch (step) {
     case "":
       step = "openPopupAtScreen";
@@ -65,23 +64,23 @@ function nextTest()
       var bo = document.documentElement.boxObject;
       popup.setAttribute("top", bo.screenY + window.innerHeight - 5);
       synthesizeMouse($("menu"), 2, 2, { });
       break;
     case "open near bottom":
       step = "large menu";
       popup.removeAttribute("left");
       popup.removeAttribute("top");
-      for (var i = 0; i < 40; i++)
+      for (var i = 0; i < 80; i++)
         menu.appendItem("Test", "");
       synthesizeMouse(menu, 2, 2, { });
       break;
     case "large menu":
       step = "shorter menu again";
-      for (var i = 0; i < 40; i++)
+      for (var i = 0; i < 80; i++)
         menu.removeItemAt(menu.itemCount - 1);
       synthesizeMouse(menu, 2, 2, { });
       break;
     case "shorter menu again":
       SimpleTest.finish();
       break;
   }
 }
@@ -90,33 +89,34 @@ function popupShown()
 {
   var windowrect = document.documentElement.getBoundingClientRect();
   var popuprect = $("popup").getBoundingClientRect();
 
   // subtract one off the edge due to a rounding issue
   ok(popuprect.left >= windowrect.left, step + " left");
   ok(popuprect.right - 1 <= windowrect.right, step + " right");
 
-  if (step == "left and top")
+  if (step == "left and top") {
     originalHeight = popuprect.bottom - popuprect.top;
-
-  if (step == "open near bottom") {
+  }
+  else if (step == "open near bottom") {
     // check that the menu flipped up so it's above our requested point
     ok(popuprect.bottom - 1 <= windowrect.bottom - 5, step + " bottom");
   }
-
-  if (step == "largemenu") {
-    ok(popuprect.top == windowrect.top, step + " top");
-    ok(popuprect.bottom - 1 == windowrect.bottom, step + " bottom");
+  else if (step == "large menu") {
+    // add 10 to account for the margin
+    is(popuprect.top, $("menu").getBoundingClientRect().bottom + 10, step + " top");
+    ok(popuprect.bottom == windowrect.bottom ||
+       popuprect.bottom - 1 == windowrect.bottom, step + " bottom");
   }
   else {
     ok(popuprect.top >= windowrect.top, step + " top");
     ok(popuprect.bottom - 1 <= windowrect.bottom, step + " bottom");
-    // XXXndeakin disable this test for now: bug 407937
-    //  is(popuprect.bottom - popuprect.top, originalHeight, step + " height shortened");
+    if (step == "shorter menu again")
+      is(popuprect.bottom - popuprect.top, originalHeight, step + " height shortened");
   }
 
   $("menu").open = false;
 }
  
 ]]>
 </script>