From 3ab0cc3efa23071528b7611a6c9b802b55e245a1 Mon Sep 17 00:00:00 2001 From: Jonathan Griffin Date: Wed, 17 Jul 2013 15:13:09 -0700 Subject: [PATCH] Bug 894953 - Don't leak onDOMConentLoaded event handlers, r=mdas --- .../client/marionette/tests/unit/test_navigation.py | 2 +- testing/marionette/marionette-listener.js | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/testing/marionette/client/marionette/tests/unit/test_navigation.py b/testing/marionette/client/marionette/tests/unit/test_navigation.py index 901f92f5774..b70e6b0835e 100644 --- a/testing/marionette/client/marionette/tests/unit/test_navigation.py +++ b/testing/marionette/client/marionette/tests/unit/test_navigation.py @@ -97,7 +97,7 @@ class TestNavigate(MarionetteTestCase): self.assertTrue(self.marionette.find_element("id", "mozLink")) self.fail("Should have thrown a MarionetteException") except MarionetteException as e: - self.assertEqual(str(e), "Error loading page, timed out") + self.assertTrue("Error loading page, timed out" in str(e)) except Exception as inst: import traceback print traceback.format_exc() diff --git a/testing/marionette/marionette-listener.js b/testing/marionette/marionette-listener.js index 0561736f6bd..dc7fd980a3a 100644 --- a/testing/marionette/marionette-listener.js +++ b/testing/marionette/marionette-listener.js @@ -1093,24 +1093,26 @@ function goUrl(msg) { let start = new Date().getTime(); let end = null; function checkLoad(){ + checkTimer.cancel(); end = new Date().getTime(); let errorRegex = /about:.+(error)|(blocked)\?/; let elapse = end - start; if (msg.json.pageTimeout == null || elapse <= msg.json.pageTimeout){ if (curWindow.document.readyState == "complete"){ + removeEventListener("DOMContentLoaded", onDOMContentLoaded, false); sendOk(command_id); - checkTimer.cancel(); } else if (curWindow.document.readyState == "interactive" && errorRegex.exec(curWindow.document.baseURI)){ + removeEventListener("DOMContentLoaded", onDOMContentLoaded, false); sendError("Error loading page", 13, null, command_id); } else{ - checkTimer.cancel(); checkTimer.initWithCallback(checkLoad, 100, Ci.nsITimer.TYPE_ONE_SHOT); } } else{ - sendError("Error loading page, timed out", 21, null, command_id); + removeEventListener("DOMContentLoaded", onDOMContentLoaded, false); + sendError("Error loading page, timed out (checkLoad)", 21, null, command_id); } } // Prevent DOMContentLoaded events from frames from invoking this code, @@ -1124,8 +1126,8 @@ function goUrl(msg) { }; function timerFunc(){ - sendError("Error loading page, timed out", 21, null, command_id); removeEventListener("DOMContentLoaded", onDOMContentLoaded, false); + sendError("Error loading page, timed out (onDOMContentLoaded)", 21, null, command_id); } if (msg.json.pageTimeout != null){ checkTimer.initWithCallback(timerFunc, msg.json.pageTimeout, Ci.nsITimer.TYPE_ONE_SHOT);