diff --git a/browser/devtools/webconsole/HUDService.jsm b/browser/devtools/webconsole/HUDService.jsm index bfece24da8a..632bfd8e2d9 100644 --- a/browser/devtools/webconsole/HUDService.jsm +++ b/browser/devtools/webconsole/HUDService.jsm @@ -125,6 +125,12 @@ XPCOMUtils.defineLazyGetter(this, "namesAndValuesOf", function () { return obj.namesAndValuesOf; }); +XPCOMUtils.defineLazyGetter(this, "gConsoleStorage", function () { + let obj = {}; + Cu.import("resource://gre/modules/ConsoleAPIStorage.jsm", obj); + return obj.ConsoleAPIStorage; +}); + function LogFactory(aMessagePrefix) { function log(aMessage) { @@ -1414,6 +1420,18 @@ HUD_SERVICE.prototype = return aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).outerWindowID; }, + /** + * Gets the ID of the inner window of this DOM window + * + * @param nsIDOMWindow aWindow + * @returns integer + */ + getInnerWindowId: function HS_getInnerWindowId(aWindow) + { + return aWindow.QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID; + }, + /** * Gets the top level content window that has an outer window with * the given ID or returns null if no such content window exists @@ -2891,7 +2909,7 @@ HUD_SERVICE.prototype = if (!hudNode) { // get nBox object and call new HUD let config = { parentNode: nBox, - contentWindow: aContentWindow + contentWindow: aContentWindow.top }; hud = new HeadsUpDisplay(config); @@ -2904,6 +2922,8 @@ HUD_SERVICE.prototype = _browser.webProgress.addProgressListener(hud.progressListener, Ci.nsIWebProgress.NOTIFY_STATE_ALL); + + hud.displayCachedConsoleMessages(); } else { hud = this.hudReferences[hudId]; @@ -3572,6 +3592,35 @@ HeadsUpDisplay.prototype = { } }, + /** + * Display cached messages that may have been collected before the UI is + * displayed. + * + * @returns void + */ + displayCachedConsoleMessages: function HUD_displayCachedConsoleMessages() + { + // Get the messages from the ConsoleStorageService. + let windowId = HUDService.getInnerWindowId(this.contentWindow); + + let messages = gConsoleStorage.getEvents(windowId); + + // Turn off scrolling for the moment. + ConsoleUtils.scroll = false; + + messages.forEach(function(aMessage) { + HUDService.logConsoleAPIMessage(this.hudId, aMessage); + }, this); + + ConsoleUtils.scroll = true; + + // Scroll to bottom. + let numChildren = this.outputNode.childNodes.length; + if (numChildren) { + this.outputNode.ensureIndexIsVisible(numChildren - 1); + } + }, + /** * Re-attaches a console when the contentWindow is recreated * @@ -5662,6 +5711,11 @@ FirefoxApplicationHooks.prototype = { */ ConsoleUtils = { + /** + * Flag to turn on and off scrolling. + */ + scroll: true, + supString: function ConsoleUtils_supString(aString) { let str = Cc["@mozilla.org/supports-string;1"]. @@ -5705,6 +5759,10 @@ ConsoleUtils = { * @returns void */ scrollToVisible: function ConsoleUtils_scrollToVisible(aNode) { + if (!this.scroll) { + return; + } + // Find the enclosing richlistbox node. let richListBoxNode = aNode.parentNode; while (richListBoxNode.tagName != "richlistbox") { diff --git a/browser/devtools/webconsole/test/Makefile.in b/browser/devtools/webconsole/test/Makefile.in index d9f08c4b70b..05d89cdbe51 100644 --- a/browser/devtools/webconsole/test/Makefile.in +++ b/browser/devtools/webconsole/test/Makefile.in @@ -150,6 +150,7 @@ _BROWSER_TEST_FILES = \ browser_webconsole_bug_658368_time_methods.js \ browser_webconsole_bug_622303_persistent_filters.js \ browser_webconsole_window_zombie.js \ + browser_ConsoleAPICachedMessages.js \ head.js \ $(NULL) diff --git a/browser/devtools/webconsole/test/browser_ConsoleAPICachedMessages.js b/browser/devtools/webconsole/test/browser_ConsoleAPICachedMessages.js new file mode 100644 index 00000000000..523e9d0eff8 --- /dev/null +++ b/browser/devtools/webconsole/test/browser_ConsoleAPICachedMessages.js @@ -0,0 +1,74 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is DevTools test code. + * + * The Initial Developer of the Original Code is Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * David Dahl + * Mihai Sucan + * + * 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 + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const TEST_URI = "data:text/html,

Web Console test for bug 609890"; + +function test() +{ + waitForExplicitFinish(); + + gBrowser.selectedTab = gBrowser.addTab(TEST_URI); + + gBrowser.selectedBrowser.addEventListener("load", testOpenUI, true); +} + +function testOpenUI() +{ + gBrowser.selectedBrowser.removeEventListener("load", testOpenUI, true); + + // test to see if the messages are + // displayed when the console UI is opened + + let console = content.wrappedJSObject.console; + console.log("log Bazzle"); + console.info("info Bazzle"); + console.warn("warn Bazzle"); + console.error("error Bazzle"); + + HUDService.activateHUDForContext(gBrowser.selectedTab); + let hudId = HUDService.getHudIdByWindow(content); + let hud = HUDService.getHudReferenceById(hudId); + + testLogEntry(hud.outputNode, "log Bazzle", + "Find a console log entry from before console UI is opened", + false, null); + + HUDService.deactivateHUDForContext(gBrowser.selectedTab); + + executeSoon(finish); +} diff --git a/browser/devtools/webconsole/test/browser_webconsole_notifications.js b/browser/devtools/webconsole/test/browser_webconsole_notifications.js index 8815a067fe9..9ef948da0cb 100644 --- a/browser/devtools/webconsole/test/browser_webconsole_notifications.js +++ b/browser/devtools/webconsole/test/browser_webconsole_notifications.js @@ -19,7 +19,8 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): - * David Dahl + * David Dahl + * Mihai Sucan * * 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 @@ -35,37 +36,34 @@ * * ***** END LICENSE BLOCK ***** */ -const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test//test-console.html"; +const TEST_URI = "data:text/html,

Web Console test for notifications"; function test() { observer.init(); addTab(TEST_URI); - browser.addEventListener("DOMContentLoaded", onLoad, false); + browser.addEventListener("load", onLoad, true); } function webConsoleCreated(aID) { Services.obs.removeObserver(observer, "web-console-created"); - executeSoon(function (){ - ok(HUDService.hudReferences[aID], "We have a hud reference"); - let console = browser.contentWindow.wrappedJSObject.console; - console.log("adding a log message"); - }); + ok(HUDService.hudReferences[aID], "We have a hud reference"); + content.wrappedJSObject.console.log("adding a log message"); } function webConsoleDestroyed(aID) { Services.obs.removeObserver(observer, "web-console-destroyed"); ok(!HUDService.hudReferences[aID], "We do not have a hud reference"); - finishTest(); + executeSoon(finishTest); } function webConsoleMessage(aID, aNodeID) { Services.obs.removeObserver(observer, "web-console-message-created"); ok(aID, "we have a console ID"); - ok(typeof aNodeID == 'string', "message node id is not null"); - closeConsole(); + is(typeof aNodeID, "string", "message node id is a string"); + executeSoon(closeConsole); } let observer = { @@ -100,6 +98,6 @@ let observer = { }; function onLoad() { - browser.removeEventListener("DOMContentLoaded", onLoad, false); + browser.removeEventListener("load", onLoad, true); openConsole(); }