Bug 582201 - exceptions show twice in WebConsole, r=sdwilsh

This commit is contained in:
Mihai Sucan 2010-08-10 09:18:23 -03:00
parent ae5fb1827b
commit 6e97217b40
4 changed files with 111 additions and 24 deletions

View File

@ -26,6 +26,7 @@
* Johnathan Nightingale <jnightingale@mozilla.com>
* Patrick Walton <pcwalton@mozilla.com>
* Julian Viereck <jviereck@mozilla.com>
* Mihai Șucan <mihai.sucan@gmail.com>
*
* 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;
};
},

View File

@ -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)

View File

@ -22,6 +22,7 @@
* David Dahl <ddahl@mozilla.com>
* Patrick Walton <pcwalton@mozilla.com>
* Julian Viereck <jviereck@mozilla.com>
* Mihai Șucan <mihai.sucan@gmail.com>
*
* 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;
}
/**

View File

@ -0,0 +1,20 @@
<!DOCTYPE HTML>
<html dir="ltr" xml:lang="en-US" lang="en-US">
<head>
<title>Console duplicate error test</title>
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
See https://bugzilla.mozilla.org/show_bug.cgi?id=582201
-->
</head>
<body>
<h1>Heads Up Display - duplicate error test</h1>
<script type="text/javascript"><!--
fooDuplicateError1.bar();
// --></script>
</body>
</html>