Bug 534421 - Intermittent failure in test_platform_colors.xul. test_native_mouse_mac.xul needs to remove its event listeners when it's finished.
authorMarkus Stange <mstange@themasta.com>
Tue, 15 Dec 2009 14:36:34 +0100
changeset 36208 cbbe13b9c4219ce76e782d173190d28377c434a3
parent 36207 805ee8a862519a007d2c89471d531095e9d4e7be
child 36209 00537ed09b5526eca96102c6d84295f4dc83c5d8
push idunknown
push userunknown
push dateunknown
bugs534421
milestone1.9.3a1pre
Bug 534421 - Intermittent failure in test_platform_colors.xul. test_native_mouse_mac.xul needs to remove its event listeners when it's finished.
widget/tests/native_mouse_mac_window.xul
--- a/widget/tests/native_mouse_mac_window.xul
+++ b/widget/tests/native_mouse_mac_window.xul
@@ -67,16 +67,19 @@
       window.opener.wrappedJSObject.SimpleTest.todo(condition, message);
     }
 
     function todo_is(a, b, message) {
       window.opener.wrappedJSObject.SimpleTest.todo_is(a, b, message);
     }
 
     function onTestsFinished() {
+      observe(window, eventMonitor, false);
+      observe(gRightWindow, eventMonitor, false);
+      observe(gPopup, eventMonitor, false);
       gRightWindow.close();
       window.close();
       window.opener.wrappedJSObject.SimpleTest.finish();
     }
 
     const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
     const xulWin = 'data:application/vnd.mozilla.xul+xml,<?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin" type="text/css"?><window xmlns="' + XUL_NS + '"/>';
 
@@ -180,39 +183,40 @@
       is(e.screenY, expectedEvent.screenY, gEventNum + " | wrong Y coord for event " + eventToString(e));
       is(e.type, expectedEvent.type, gEventNum + " | wrong event type for event " + eventToString(e));
       is(e.target, expectedEvent.target, gEventNum + " | wrong target for event " + eventToString(e));
       if (expectedEvent.todoShouldNotHaveFired) {
         todo(false, gEventNum + " | Got an event that should not have fired: " + eventToString(e));
       }
     }
 
-    function observe(elem, fun) {
-      elem.addEventListener("mousemove", fun, false);
-      elem.addEventListener("mouseover", fun, false);
-      elem.addEventListener("mouseout", fun, false);
-      elem.addEventListener("mousedown", fun, false);
-      elem.addEventListener("mouseup", fun, false);
-      elem.addEventListener("click", fun, false);
+    function observe(elem, fun, add) {
+      var addOrRemove = add ? "addEventListener" : "removeEventListener";
+      elem[addOrRemove]("mousemove", fun, false);
+      elem[addOrRemove]("mouseover", fun, false);
+      elem[addOrRemove]("mouseout", fun, false);
+      elem[addOrRemove]("mousedown", fun, false);
+      elem[addOrRemove]("mouseup", fun, false);
+      elem[addOrRemove]("click", fun, false);
     }
 
     function start() {
       window.resizeTo(200, 200);
       window.moveTo(50, 50);
       gRightWindow = open(xulWin, '', 'chrome,screenX=300,screenY=50,width=200,height=200');
       eventListenOnce(gRightWindow, "focus", function () {
         focusAndThen(window, runTests);
       });
       gPopup = document.getElementById("popup");
     }
 
     function runTests() {
-      observe(window, eventMonitor);
-      observe(gRightWindow, eventMonitor);
-      observe(gPopup, eventMonitor);
+      observe(window, eventMonitor, true);
+      observe(gRightWindow, eventMonitor, true);
+      observe(gPopup, eventMonitor, true);
       var left = window, right = gRightWindow;
       var leftElem = document.getElementById("box");
       var rightElem = gRightWindow.document.documentElement;
       var panel = document.getElementById("panel");
       var tooltip = (function createTooltipInRightWindow() {
         var _tooltip = right.document.createElementNS(XUL_NS, "tooltip");
         _tooltip.setAttribute("id", "tip");
         _tooltip.setAttribute("width", "80");