From fd2ff0c80bd42e71d89d527b8dbb44c74bd4273a Mon Sep 17 00:00:00 2001 From: "highmind63@gmail.com" <highmind63@gmail.com> Date: Tue, 22 Sep 2009 15:18:38 -0400 Subject: [PATCH] Bug 416276, reenable tooltip test, move into a single file and fix up to use waitForFocus, r=enn --- toolkit/content/tests/widgets/Makefile.in | 5 +- toolkit/content/tests/widgets/popup_shared.js | 28 ++- .../content/tests/widgets/test_tooltip.xul | 209 +++++++++++++++++- .../tests/widgets/test_tooltip_noautohide.xul | 5 + .../content/tests/widgets/window_tooltip.xul | 207 ----------------- 5 files changed, 234 insertions(+), 220 deletions(-) delete mode 100644 toolkit/content/tests/widgets/window_tooltip.xul diff --git a/toolkit/content/tests/widgets/Makefile.in b/toolkit/content/tests/widgets/Makefile.in index f8e783d4f4a5f..f58a449940c6a 100644 --- a/toolkit/content/tests/widgets/Makefile.in +++ b/toolkit/content/tests/widgets/Makefile.in @@ -44,9 +44,6 @@ relativesrcdir = toolkit/content/tests/widgets include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk -# disabled, see bug 506038 -# test_tooltip.xul \ - _TEST_FILES = test_bug360220.xul \ test_bug359754.xul \ test_bug365773.xul \ @@ -73,7 +70,7 @@ _TEST_FILES = test_bug360220.xul \ popup_trigger.js \ window_popup_button.xul \ window_popup_attribute.xul \ - window_tooltip.xul \ + test_tooltip.xul \ test_progressmeter.xul \ test_props.xul \ test_statusbar.xul \ diff --git a/toolkit/content/tests/widgets/popup_shared.js b/toolkit/content/tests/widgets/popup_shared.js index 7b3cdd358e22b..e970decbfb813 100644 --- a/toolkit/content/tests/widgets/popup_shared.js +++ b/toolkit/content/tests/widgets/popup_shared.js @@ -34,6 +34,7 @@ var gTestStepIndex = 0; var gTestEventIndex = 0; var gAutoHide = false; var gExpectedEventDetails = null; +var gWindowUtils; function startPopupTests(tests) { @@ -49,22 +50,41 @@ function startPopupTests(tests) document.addEventListener("DOMMenuBarInactive", eventOccured, false); gPopupTests = tests; + gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); goNext(); } function finish() { - window.close(); - window.opener.SimpleTest.finish(); + if (window.opener) { + window.close(); + window.opener.SimpleTest.finish(); + return; + } + SimpleTest.finish(); + return; } function ok(condition, message) { - window.opener.SimpleTest.ok(condition, message); + if (window.opener) + window.opener.SimpleTest.ok(condition, message); + else + SimpleTest.ok(condition, message); } function is(left, right, message) { - window.opener.SimpleTest.is(left, right, message); + if (window.opener) + window.opener.SimpleTest.is(left, right, message); + else + SimpleTest.is(left, right, message); +} + +function disableNonTestMouse(aDisable) { + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); + + gWindowUtils.disableNonTestMouseEvents(aDisable); } function eventOccured(event) diff --git a/toolkit/content/tests/widgets/test_tooltip.xul b/toolkit/content/tests/widgets/test_tooltip.xul index 8777dc86abae4..7ee803ef8b23a 100644 --- a/toolkit/content/tests/widgets/test_tooltip.xul +++ b/toolkit/content/tests/widgets/test_tooltip.xul @@ -3,21 +3,220 @@ <?xml-stylesheet href="/tests/SimpleTest/test.css" type="text/css"?> <window title="Tooltip Tests" - onload="setTimeout(runTest, 0);" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <title>Tooltip Tests</title> <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> + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> + <script type="application/javascript" src="popup_shared.js"></script> + +<tooltip id="thetooltip"> + <label id="label" value="This is a tooltip"/> +</tooltip> + +<box tooltiptext="Box Tooltip"> + <button id="withtext" label="Tooltip Text" tooltiptext="Button Tooltip" + style="-moz-appearance: none; padding: 0;"/> + <button id="without" label="No Tooltip" style="-moz-appearance: none; padding: 0;"/> + <!-- remove the native theme and borders to avoid some platform + specific sizing differences --> + <button id="withtooltip" label="Tooltip Element" tooltip="thetooltip" + class="plain" style="-moz-appearance: none; padding: 0;"/> +</box> + +<script class="testbody" type="application/javascript"> +<![CDATA[ -<script> SimpleTest.waitForExplicitFinish(); +var gOriginalWidth = -1; +var gOriginalHeight = -1; +var gButton = null; + function runTest() { - window.open("window_tooltip.xul", "_blank", "width=600,height=600"); + startPopupTests(popupTests); +} + +function checkCoords(event) +{ + // all but one test open the tooltip at the button location offset by 6 + // in each direction. Test 5 opens it at 4 in each direction. + var mod = (gTestIndex == 5) ? 4 : 6; + + var rect = gButton.getBoundingClientRect(); + var popupstyle = window.getComputedStyle(gButton, ""); + is(event.clientX, Math.round(rect.left + mod), + "step " + (gTestIndex + 1) + " clientX"); + is(event.clientY, Math.round(rect.top + mod), + "step " + (gTestIndex + 1) + " clientY"); + ok(event.screenX > 0, "step " + (gTestIndex + 1) + " screenX"); + ok(event.screenY > 0, "step " + (gTestIndex + 1) + " screenY"); } + +var popupTests = [ +{ + testname: "hover tooltiptext attribute", + events: [ "popupshowing #tooltip", "popupshown #tooltip" ], + test: function() { + gButton = document.getElementById("withtext"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + disableNonTestMouse(false); + } +}, +{ + testname: "close tooltip", + events: [ "popuphiding #tooltip", "popuphidden #tooltip", + "DOMMenuInactive #tooltip" ], + test: function() { + disableNonTestMouse(true); + synthesizeMouse(document.documentElement, 2, 2, { type: "mousemove" }); + disableNonTestMouse(false); + }, +}, +{ + testname: "hover inherited tooltip", + events: [ "popupshowing #tooltip", "popupshown #tooltip" ], + test: function() { + gButton = document.getElementById("without"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + disableNonTestMouse(false); + } +}, +{ + testname: "hover tooltip attribute", + events: [ "popuphiding #tooltip", "popuphidden #tooltip", + "DOMMenuInactive #tooltip", + "popupshowing thetooltip", "popupshown thetooltip" ], + test: function() { + gButton = document.getElementById("withtooltip"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + disableNonTestMouse(false); + }, + result: function(testname) { + var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); + var rect = document.getElementById("thetooltip").getBoundingClientRect(); + var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); + + is(Math.round(rect.left), + Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6), + testname + " top position of tooltip"); + is(Math.round(rect.top), + Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6), + testname + " top position of tooltip"); + + var labelrect = document.getElementById("label").getBoundingClientRect(); + ok(labelrect.right < rect.right, testname + " tooltip width"); + ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); + + gOriginalWidth = rect.right - rect.left; + gOriginalHeight = rect.bottom - rect.top; + } +}, +{ + testname: "click to close tooltip", + events: [ "popuphiding thetooltip", "popuphidden thetooltip", + "command withtooltip", "DOMMenuInactive thetooltip" ], + test: function() { + gButton = document.getElementById("withtooltip"); + synthesizeMouse(gButton, 2, 2, { }); + }, +}, +{ + testname: "hover tooltip after size increased", + events: [ "popupshowing thetooltip", "popupshown thetooltip" ], + test: function() { + var label = document.getElementById("label"); + label.removeAttribute("value"); + label.textContent = "This is a longer tooltip than before\nIt has multiple lines\nIt is testing tooltip sizing\n"; + gButton = document.getElementById("withtooltip"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + disableNonTestMouse(false); + }, + result: function(testname) { + var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); + var rect = document.getElementById("thetooltip").getBoundingClientRect(); + var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); + var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), ""); + + is(Math.round(rect.left), + Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 4), + testname + " top position of tooltip"); + is(Math.round(rect.top), + Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 4), + testname + " top position of tooltip"); + + var labelrect = document.getElementById("label").getBoundingClientRect(); + ok(labelrect.right < rect.right, testname + " tooltip width"); + ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); + + // make sure that the tooltip is larger than it was before by just + // checking against the original height plus an arbitrary 15 pixels + ok(gOriginalWidth + 15 < rect.right - rect.left, testname + " tooltip is wider"); + ok(gOriginalHeight + 15 < rect.bottom - rect.top, testname + " tooltip is taller"); + } +}, +{ + testname: "close tooltip with hidePopup", + events: [ "popuphiding thetooltip", "popuphidden thetooltip", + "DOMMenuInactive thetooltip" ], + test: function() { + document.getElementById("thetooltip").hidePopup(); + }, +}, +{ + testname: "hover tooltip after size decreased", + events: [ "popupshowing thetooltip", "popupshown thetooltip" ], + autohide: "thetooltip", + test: function() { + var label = document.getElementById("label"); + label.value = "This is a tooltip"; + gButton = document.getElementById("withtooltip"); + disableNonTestMouse(true); + synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); + synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); + synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); + disableNonTestMouse(false); + }, + result: function(testname) { + var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); + var rect = document.getElementById("thetooltip").getBoundingClientRect(); + var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); + var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), ""); + + is(Math.round(rect.left), + Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6), + testname + " top position of tooltip"); + is(Math.round(rect.top), + Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6), + testname + " top position of tooltip"); + + var labelrect = document.getElementById("label").getBoundingClientRect(); + ok(labelrect.right < rect.right, testname + " tooltip width"); + ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); + + is(gOriginalWidth, rect.right - rect.left, testname + " tooltip is original width"); + is(gOriginalHeight, rect.bottom - rect.top, testname + " tooltip is original height"); + } +}, + +]; + +SimpleTest.waitForFocus(runTest); +]]> </script> <body xmlns="http://www.w3.org/1999/xhtml"> diff --git a/toolkit/content/tests/widgets/test_tooltip_noautohide.xul b/toolkit/content/tests/widgets/test_tooltip_noautohide.xul index 5fe7e880977ca..dbfb8c8d2bbd9 100644 --- a/toolkit/content/tests/widgets/test_tooltip_noautohide.xul +++ b/toolkit/content/tests/widgets/test_tooltip_noautohide.xul @@ -24,10 +24,15 @@ var gChecked = false; function runTests() { + netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var button = document.getElementById("button"); + var windowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); + windowUtils.disableNonTestMouseEvents(true); synthesizeMouse(button, 2, 2, { type: "mouseover" }); synthesizeMouse(button, 4, 4, { type: "mousemove" }); synthesizeMouse(button, 6, 6, { type: "mousemove" }); + windowUtils.disableNonTestMouseEvents(false); } function tooltipStillShown() diff --git a/toolkit/content/tests/widgets/window_tooltip.xul b/toolkit/content/tests/widgets/window_tooltip.xul deleted file mode 100644 index 5bca1c5defbe0..0000000000000 --- a/toolkit/content/tests/widgets/window_tooltip.xul +++ /dev/null @@ -1,207 +0,0 @@ -<?xml version="1.0"?> -<?xml-stylesheet href="chrome://global/skin" type="text/css"?> - -<window title="Tooltip Tests" - onpopupshowing="checkCoords(event)" - xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> - - <title>Tooltip Tests</title> - <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> - <script type="application/javascript" src="popup_shared.js"></script> - -<tooltip id="thetooltip"> - <label id="label" value="This is a tooltip"/> -</tooltip> - -<box tooltiptext="Box Tooltip"> - <button id="withtext" label="Tooltip Text" tooltiptext="Button Tooltip" - style="-moz-appearance: none; padding: 0;"/> - <button id="without" label="No Tooltip" style="-moz-appearance: none; padding: 0;"/> - <!-- remove the native theme and borders to avoid some platform - specific sizing differences --> - <button id="withtooltip" label="Tooltip Element" tooltip="thetooltip" - class="plain" style="-moz-appearance: none; padding: 0;"/> -</box> - -<script class="testbody" type="application/javascript"> -<![CDATA[ - -var gOriginalWidth = -1; -var gOriginalHeight = -1; -var gButton = null; - -function runTests() -{ - startPopupTests(popupTests); -} - -function checkCoords(event) -{ - // all but one test open the tooltip at the button location offset by 6 - // in each direction. Test 5 opens it at 4 in each direction. - var mod = (gTestIndex == 5) ? 4 : 6; - - var rect = gButton.getBoundingClientRect(); - var popupstyle = window.getComputedStyle(gButton, ""); - is(event.clientX, Math.round(rect.left + mod), - "step " + (gTestIndex + 1) + " clientX"); - is(event.clientY, Math.round(rect.top + mod), - "step " + (gTestIndex + 1) + " clientY"); - ok(event.screenX > 0, "step " + (gTestIndex + 1) + " screenX"); - ok(event.screenY > 0, "step " + (gTestIndex + 1) + " screenY"); -} - -var popupTests = [ -{ - testname: "hover tooltiptext attribute", - events: [ "popupshowing #tooltip", "popupshown #tooltip" ], - test: function() { - gButton = document.getElementById("withtext"); - synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); - synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); - synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); - } -}, -{ - testname: "close tooltip", - events: [ "popuphiding #tooltip", "popuphidden #tooltip", - "DOMMenuInactive #tooltip" ], - test: function() { - synthesizeMouse(document.documentElement, 2, 2, { type: "mousemove" }); - }, -}, -{ - testname: "hover inherited tooltip", - events: [ "popupshowing #tooltip", "popupshown #tooltip" ], - test: function() { - gButton = document.getElementById("without"); - synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); - synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); - synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); - } -}, -{ - testname: "hover tooltip attribute", - events: [ "popuphiding #tooltip", "popuphidden #tooltip", - "DOMMenuInactive #tooltip", - "popupshowing thetooltip", "popupshown thetooltip" ], - test: function() { - gButton = document.getElementById("withtooltip"); - synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); - synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); - synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); - }, - result: function(testname) { - var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); - var rect = document.getElementById("thetooltip").getBoundingClientRect(); - var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); - - is(Math.round(rect.left), - Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6), - testname + " top position of tooltip"); - is(Math.round(rect.top), - Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6), - testname + " top position of tooltip"); - - var labelrect = document.getElementById("label").getBoundingClientRect(); - ok(labelrect.right < rect.right, testname + " tooltip width"); - ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); - - gOriginalWidth = rect.right - rect.left; - gOriginalHeight = rect.bottom - rect.top; - } -}, -{ - testname: "click to close tooltip", - events: [ "popuphiding thetooltip", "popuphidden thetooltip", - "command withtooltip", "DOMMenuInactive thetooltip" ], - test: function() { - gButton = document.getElementById("withtooltip"); - synthesizeMouse(gButton, 2, 2, { }); - }, -}, -{ - testname: "hover tooltip after size increased", - events: [ "popupshowing thetooltip", "popupshown thetooltip" ], - test: function() { - var label = document.getElementById("label"); - label.removeAttribute("value"); - label.textContent = "This is a longer tooltip than before\nIt has multiple lines\nIt is testing tooltip sizing\n"; - gButton = document.getElementById("withtooltip"); - synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); - synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); - synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); - }, - result: function(testname) { - var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); - var rect = document.getElementById("thetooltip").getBoundingClientRect(); - var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); - var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), ""); - - is(Math.round(rect.left), - Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 4), - testname + " top position of tooltip"); - is(Math.round(rect.top), - Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 4), - testname + " top position of tooltip"); - - var labelrect = document.getElementById("label").getBoundingClientRect(); - ok(labelrect.right < rect.right, testname + " tooltip width"); - ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); - - // make sure that the tooltip is larger than it was before by just - // checking against the original height plus an arbitrary 15 pixels - ok(gOriginalWidth + 15 < rect.right - rect.left, testname + " tooltip is wider"); - ok(gOriginalHeight + 15 < rect.bottom - rect.top, testname + " tooltip is taller"); - } -}, -{ - testname: "close tooltip with hidePopup", - events: [ "popuphiding thetooltip", "popuphidden thetooltip", - "DOMMenuInactive thetooltip" ], - test: function() { - document.getElementById("thetooltip").hidePopup(); - }, -}, -{ - testname: "hover tooltip after size decreased", - events: [ "popupshowing thetooltip", "popupshown thetooltip" ], - autohide: "thetooltip", - test: function() { - var label = document.getElementById("label"); - label.value = "This is a tooltip"; - gButton = document.getElementById("withtooltip"); - synthesizeMouse(gButton, 2, 2, { type: "mouseover" }); - synthesizeMouse(gButton, 4, 4, { type: "mousemove" }); - synthesizeMouse(gButton, 6, 6, { type: "mousemove" }); - }, - result: function(testname) { - var buttonrect = document.getElementById("withtooltip").getBoundingClientRect(); - var rect = document.getElementById("thetooltip").getBoundingClientRect(); - var popupstyle = window.getComputedStyle(document.getElementById("thetooltip"), ""); - var buttonstyle = window.getComputedStyle(document.getElementById("withtooltip"), ""); - - is(Math.round(rect.left), - Math.round(buttonrect.left + parseFloat(popupstyle.marginLeft) + 6), - testname + " top position of tooltip"); - is(Math.round(rect.top), - Math.round(buttonrect.top + parseFloat(popupstyle.marginTop) + 6), - testname + " top position of tooltip"); - - var labelrect = document.getElementById("label").getBoundingClientRect(); - ok(labelrect.right < rect.right, testname + " tooltip width"); - ok(labelrect.bottom < rect.bottom, testname + " tooltip height"); - - is(gOriginalWidth, rect.right - rect.left, testname + " tooltip is original width"); - is(gOriginalHeight, rect.bottom - rect.top, testname + " tooltip is original height"); - } -}, - -]; - -window.opener.SimpleTest.waitForFocus(runTests, window); - -]]> -</script> - -</window> -- GitLab