From 6e97217b40574c63bb66149778afa86b528a93ef Mon Sep 17 00:00:00 2001 From: Mihai Sucan Date: Tue, 10 Aug 2010 09:18:23 -0300 Subject: [PATCH] Bug 582201 - exceptions show twice in WebConsole, r=sdwilsh --- .../console/hudservice/HUDService.jsm | 13 ++- .../hudservice/tests/browser/Makefile.in | 1 + .../browser/browser_HUDServiceTestsAll.js | 101 ++++++++++++++---- .../tests/browser/test-duplicate-error.html | 20 ++++ 4 files changed, 111 insertions(+), 24 deletions(-) create mode 100644 toolkit/components/console/hudservice/tests/browser/test-duplicate-error.html diff --git a/toolkit/components/console/hudservice/HUDService.jsm b/toolkit/components/console/hudservice/HUDService.jsm index f42b4730e5e..9f314161dc5 100644 --- a/toolkit/components/console/hudservice/HUDService.jsm +++ b/toolkit/components/console/hudservice/HUDService.jsm @@ -26,6 +26,7 @@ * Johnathan Nightingale * Patrick Walton * Julian Viereck + * Mihai Șucan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -204,14 +205,18 @@ HUD_SERVICE.prototype = var origOnerrorFunc = window.onerror; window.onerror = function windowOnError(aErrorMsg, aURL, aLineNumber) { - var lineNum = ""; - if (aLineNumber) { - lineNum = self.getFormatStr("errLine", [aLineNumber]); + if (aURL && !(aURL in self.uriRegistry)) { + var lineNum = ""; + if (aLineNumber) { + lineNum = self.getFormatStr("errLine", [aLineNumber]); + } + console.error(aErrorMsg + " @ " + aURL + " " + lineNum); } - console.error(aErrorMsg + " @ " + aURL + " " + lineNum); + if (origOnerrorFunc) { origOnerrorFunc(aErrorMsg, aURL, aLineNumber); } + return false; }; }, diff --git a/toolkit/components/console/hudservice/tests/browser/Makefile.in b/toolkit/components/console/hudservice/tests/browser/Makefile.in index 8578ac192ad..c37ff13a97e 100644 --- a/toolkit/components/console/hudservice/tests/browser/Makefile.in +++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in @@ -57,6 +57,7 @@ _BROWSER_TEST_PAGES = \ test-data.json \ test-property-provider.html \ test-error.html \ + test-duplicate-error.html \ $(NULL) libs:: $(_BROWSER_TEST_FILES) diff --git a/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js b/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js index 8052bf55f5d..b68aa940d28 100644 --- a/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js +++ b/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js @@ -22,6 +22,7 @@ * David Dahl * Patrick Walton * Julian Viereck + * Mihai Șucan * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -69,6 +70,8 @@ const TEST_PROPERTY_PROVIDER_URI = "http://example.com/browser/toolkit/component const TEST_ERROR_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-error.html"; +const TEST_DUPLICATE_ERROR_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-duplicate-error.html"; + function noCacheUriSpec(aUriSpec) { return aUriSpec + "?_=" + Date.now(); } @@ -656,17 +659,47 @@ function testErrorOnPageReload() { // see bug 580030: the error handler fails silently after page reload. // https://bugzilla.mozilla.org/show_bug.cgi?id=580030 + var consoleObserver = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), + + observe: function (aMessage) + { + // we ignore errors we don't care about + if (!(aMessage instanceof Ci.nsIScriptError) || + aMessage.category != "content javascript") { + return; + } + + Services.console.unregisterListener(this); + + const successMsg = "Found the error message after page reload"; + const errMsg = "Could not get the error message after page reload"; + + var display = HUDService.getDisplayByURISpec(content.location.href); + var outputNode = display.querySelectorAll(".hud-output-node")[0]; + + executeSoon(function () { + testLogEntry(outputNode, "fooBazBaz", + { success: successMsg, err: errMsg }); + + testDuplicateError(); + }); + } + }; + var pageReloaded = false; - browser.addEventListener("DOMContentLoaded", function onDOMLoad() { + browser.addEventListener("load", function() { if (!pageReloaded) { pageReloaded = true; content.location.reload(); return; } - browser.removeEventListener("DOMContentLoaded", onDOMLoad, false); + browser.removeEventListener("load", arguments.callee, true); + + // dispatch a click event to the button in the test page and listen for + // errors. - // dispatch a click event to the button in the test page. var contentDocument = browser.contentDocument.wrappedJSObject; var button = contentDocument.getElementsByTagName("button")[0]; var clickEvent = contentDocument.createEvent("MouseEvents"); @@ -674,25 +707,53 @@ function testErrorOnPageReload() { browser.contentWindow.wrappedJSObject, 0, 0, 0, 0, 0, false, false, false, false, 0, null); - var successMsg = "Found the error message after page reload"; - var errMsg = "Could not get the error message after page reload"; - - var display = HUDService.getDisplayByURISpec(content.location.href); - var outputNode = display.querySelectorAll(".hud-output-node")[0]; - - button.addEventListener("click", function onClickHandler() { - button.removeEventListener("click", onClickHandler, false); - - testLogEntry(outputNode, "fooBazBaz", - { success: successMsg, err: errMsg }); - - testWebConsoleClose(); - }, false); - + Services.console.registerListener(consoleObserver); button.dispatchEvent(clickEvent); - }, false); + }, true); - content.location.href = TEST_ERROR_URI; + content.location = TEST_ERROR_URI; +} + +function testDuplicateError() { + // see bug 582201 - exceptions show twice in WebConsole + // https://bugzilla.mozilla.org/show_bug.cgi?id=582201 + + var consoleObserver = { + QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), + + observe: function (aMessage) + { + // we ignore errors we don't care about + if (!(aMessage instanceof Ci.nsIScriptError) || + aMessage.category != "content javascript") { + return; + } + + Services.console.unregisterListener(this); + + var display = HUDService.getDisplayByURISpec(content.location.href); + var outputNode = display.querySelectorAll(".hud-output-node")[0]; + + executeSoon(function () { + var text = outputNode.textContent; + var error1pos = text.indexOf("fooDuplicateError1"); + ok(error1pos > -1, "found fooDuplicateError1"); + if (error1pos > -1) { + ok(text.indexOf("fooDuplicateError1", error1pos + 1) == -1, + "no duplicate for fooDuplicateError1"); + } + + ok(text.indexOf("test-duplicate-error.html") > -1, + "found test-duplicate-error.html"); + + text = null; + testWebConsoleClose(); + }); + } + }; + + Services.console.registerListener(consoleObserver); + content.location = TEST_DUPLICATE_ERROR_URI; } /** diff --git a/toolkit/components/console/hudservice/tests/browser/test-duplicate-error.html b/toolkit/components/console/hudservice/tests/browser/test-duplicate-error.html new file mode 100644 index 00000000000..fab0fbebe08 --- /dev/null +++ b/toolkit/components/console/hudservice/tests/browser/test-duplicate-error.html @@ -0,0 +1,20 @@ + + + + Console duplicate error test + + + +

Heads Up Display - duplicate error test

+ + + + +