Bug 692829 - Display cached messages from iframes; r=msucan

This commit is contained in:
Rob Campbell 2013-06-14 11:19:26 -04:00
parent 1ef43077ae
commit 0fcd222292
8 changed files with 212 additions and 14 deletions

View File

@ -140,6 +140,7 @@ MOCHITEST_BROWSER_FILES = \
browser_console_keyboard_accessibility.js \
browser_console_filters.js \
browser_console_dead_objects.js \
browser_console_iframe_messages.js \
head.js \
$(NULL)
@ -239,6 +240,10 @@ MOCHITEST_BROWSER_FILES += \
test-bug-837351-security-errors.html \
test-bug-869003-top-window.html \
test-bug-869003-iframe.html \
test-consoleiframes.html \
test-iframe1.html \
test-iframe2.html \
test-iframe3.html \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,99 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Check that cached messages from nested iframes are displayed in the
// Web/Browser Console.
const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-consoleiframes.html";
function test()
{
expectUncaughtException();
addTab(TEST_URI);
browser.addEventListener("load", function onLoad() {
browser.removeEventListener("load", onLoad, true);
// Test for cached nsIConsoleMessages.
Services.console.logStringMessage("test1 for bug859756");
info("open web console");
openConsole(null, consoleOpened);
}, true);
}
function consoleOpened(hud)
{
ok(hud, "web console opened");
waitForMessages({
webconsole: hud,
messages: [
{
text: "main file",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
},
{
text: "blah",
category: CATEGORY_JS,
severity: SEVERITY_ERROR
},
{
text: "iframe 1",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
count: 2
},
{
text: "iframe 2",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG
}
],
}).then(() => {
closeConsole(null, onWebConsoleClose);
});
}
function onWebConsoleClose()
{
info("web console closed");
HUDConsoleUI.toggleBrowserConsole().then(onBrowserConsoleOpen);
}
function onBrowserConsoleOpen(hud)
{
ok(hud, "browser console opened");
Services.console.logStringMessage("test2 for bug859756");
waitForMessages({
webconsole: hud,
messages: [
{
text: "main file",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
},
{
text: "blah",
category: CATEGORY_JS,
severity: SEVERITY_ERROR
},
{
text: "iframe 1",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG,
count: 2
},
{
text: "iframe 2",
category: CATEGORY_WEBDEV,
severity: SEVERITY_LOG
}
],
}).then(() => {
closeConsole(null, finishTest);
});
}

View File

@ -15,6 +15,7 @@ let TargetFactory = tempScope.devtools.TargetFactory;
Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
let console = tempScope.console;
let Promise = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {}).Promise;
// Promise._reportErrors = true; // please never leave me.
let gPendingOutputTest = 0;

View File

@ -0,0 +1,13 @@
<html>
<head>
<script>
console.log("main file");
</script>
</head>
<body>
<h1>iframe console test</h1>
<iframe src="test-iframe1.html"></iframe>
<iframe src="test-iframe2.html"></iframe>
<iframe src="test-iframe3.html"></iframe>
</body>
</html>

View File

@ -0,0 +1,10 @@
<html>
<head>
<script>
console.log("iframe 1");
</script>
</head>
<body>
<h1>iframe 1</h1>
</body>
</html>

View File

@ -0,0 +1,11 @@
<html>
<head>
<script>
console.log("iframe 2");
blah;
</script>
</head>
<body>
<h1>iframe 2</h1>
</body>
</html>

View File

@ -0,0 +1,11 @@
<html>
<head>
<script>
console.log("iframe 3");
</script>
</head>
<body>
<h1>iframe 3</h1>
<iframe src="test-iframe1.html"></iframe>
</body>
</html>

View File

@ -144,9 +144,33 @@ this.WebConsoleUtils = {
getInnerWindowId: function WCU_getInnerWindowId(aWindow)
{
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
},
/**
* Recursively gather a list of inner window ids given a
* top level window.
*
* @param nsIDOMWindow aWindow
* @return Array
* list of inner window ids.
*/
getInnerWindowIDsForFrames: function WCU_getInnerWindowIDsForFrames(aWindow)
{
let innerWindowID = this.getInnerWindowId(aWindow);
let ids = [innerWindowID];
if (aWindow.frames) {
for (let i = 0; i < aWindow.frames.length; i++) {
let frame = aWindow.frames[i];
ids = ids.concat(this.getInnerWindowIDsForFrames(frame));
}
}
return ids;
},
/**
* Gets the ID of the outer window of this DOM window.
*
@ -986,7 +1010,7 @@ ConsoleServiceListener.prototype =
},
/**
* Get the cached page errors for the current inner window.
* Get the cached page errors for the current inner window and its (i)frames.
*
* @param boolean [aIncludePrivate=false]
* Tells if you want to also retrieve messages coming from private
@ -997,22 +1021,36 @@ ConsoleServiceListener.prototype =
*/
getCachedMessages: function CSL_getCachedMessages(aIncludePrivate = false)
{
let innerWindowID = this.window ?
WebConsoleUtils.getInnerWindowId(this.window) : null;
let errors = Services.console.getMessageArray() || [];
// if !this.window, we're in a browser console. Still need to filter
// private messages.
if (!this.window) {
return errors.filter((aError) => {
if (aError instanceof Ci.nsIScriptError) {
if (!aIncludePrivate && aError.isFromPrivateWindow) {
return false;
}
}
return true;
});
}
let ids = WebConsoleUtils.getInnerWindowIDsForFrames(this.window);
return errors.filter((aError) => {
if (aError instanceof Ci.nsIScriptError) {
if (!aIncludePrivate && aError.isFromPrivateWindow) {
return false;
}
if (innerWindowID &&
(aError.innerWindowID != innerWindowID ||
if (ids &&
(ids.indexOf(aError.innerWindowID) == -1 ||
!this.isCategoryAllowed(aError.category))) {
return false;
}
}
else if (innerWindowID) {
else if (ids && ids[0]) {
// If this is not an nsIScriptError and we need to do window-based
// filtering we skip this message.
return false;
@ -1115,7 +1153,7 @@ ConsoleAPIListener.prototype =
},
/**
* Get the cached messages for the current inner window.
* Get the cached messages for the current inner window and its (i)frames.
*
* @param boolean [aIncludePrivate=false]
* Tells if you want to also retrieve messages coming from private
@ -1125,14 +1163,24 @@ ConsoleAPIListener.prototype =
*/
getCachedMessages: function CAL_getCachedMessages(aIncludePrivate = false)
{
let innerWindowId = this.window ?
WebConsoleUtils.getInnerWindowId(this.window) : null;
let events = ConsoleAPIStorage.getEvents(innerWindowId);
if (aIncludePrivate) {
return events;
let messages = [];
// if !this.window, we're in a browser console. Retrieve all events
// for filtering based on privacy.
if (!this.window) {
messages = ConsoleAPIStorage.getEvents();
} else {
let ids = WebConsoleUtils.getInnerWindowIDsForFrames(this.window);
ids.forEach((id) => {
messages = messages.concat(ConsoleAPIStorage.getEvents(id));
});
}
return events.filter((m) => !m.private);
if (aIncludePrivate) {
return messages;
}
return messages.filter((m) => !m.private);
},
/**