diff options
Diffstat (limited to 'devtools/client/webconsole')
-rw-r--r-- | devtools/client/webconsole/hudservice.js | 58 | ||||
-rw-r--r-- | devtools/client/webconsole/panel.js | 2 | ||||
-rw-r--r-- | devtools/client/webconsole/test/browser.ini | 1 | ||||
-rw-r--r-- | devtools/client/webconsole/test/browser_console.js | 19 | ||||
-rw-r--r-- | devtools/client/webconsole/test/browser_console_restore.js | 30 | ||||
-rw-r--r-- | devtools/client/webconsole/test/head.js | 17 |
6 files changed, 96 insertions, 31 deletions
diff --git a/devtools/client/webconsole/hudservice.js b/devtools/client/webconsole/hudservice.js index 46b4f2a13..3023b7bb3 100644 --- a/devtools/client/webconsole/hudservice.js +++ b/devtools/client/webconsole/hudservice.js @@ -51,6 +51,23 @@ HUD_SERVICE.prototype = */ consoles: null, + _browerConsoleSessionState: false, + storeBrowserConsoleSessionState() { + this._browerConsoleSessionState = !!this.getBrowserConsole(); + }, + getBrowserConsoleSessionState() { + return this._browerConsoleSessionState; + }, + + /** + * Restore the Browser Console as provided by SessionStore. + */ + restoreBrowserConsoleSession: function HS_restoreBrowserConsoleSession() { + if (!HUDService.getBrowserConsole()) { + HUDService.toggleBrowserConsole(); + } + }, + /** * Assign a function to this property to listen for every request that * completes. Used by unit tests. The callback takes one argument: the HTTP @@ -647,6 +664,9 @@ BrowserConsole.prototype = extend(WebConsole.prototype, { return this._bc_init; } + // Only add the shutdown observer if we've opened a Browser Console window. + ShutdownObserver.init(); + this.ui._filterPrefsPrefix = BROWSER_CONSOLE_FILTER_PREFS_PREFIX; let window = this.iframeWindow; @@ -703,16 +723,32 @@ BrowserConsole.prototype = extend(WebConsole.prototype, { }); const HUDService = new HUD_SERVICE(); +exports.HUDService = HUDService; -(() => { - let methods = ["openWebConsole", "openBrowserConsole", - "toggleBrowserConsole", "getOpenWebConsole", - "getBrowserConsole", "getHudByWindow", - "openBrowserConsoleOrFocus", "getHudReferenceById"]; - for (let method of methods) { - exports[method] = HUDService[method].bind(HUDService); - } +/** + * The ShutdownObserver listens for app shutdown and saves the current state + * of the Browser Console for session restore. + */ +var ShutdownObserver = { + _initialized: false, + init() { + if (this._initialized) { + return; + } + + Services.obs.addObserver(this, "quit-application-granted", false); + + this._initialized = true; + }, - exports.consoles = HUDService.consoles; - exports.lastFinishedRequest = HUDService.lastFinishedRequest; -})(); + observe(message, topic) { + if (topic == "quit-application-granted") { + HUDService.storeBrowserConsoleSessionState(); + this.uninit(); + } + }, + + uninit() { + Services.obs.removeObserver(this, "quit-application-granted"); + } +}; diff --git a/devtools/client/webconsole/panel.js b/devtools/client/webconsole/panel.js index 3e3a4f4b9..b692de681 100644 --- a/devtools/client/webconsole/panel.js +++ b/devtools/client/webconsole/panel.js @@ -8,7 +8,7 @@ const promise = require("promise"); -loader.lazyGetter(this, "HUDService", () => require("devtools/client/webconsole/hudservice")); +loader.lazyRequireGetter(this, "HUDService", "devtools/client/webconsole/hudservice", true); loader.lazyGetter(this, "EventEmitter", () => require("devtools/shared/event-emitter")); /** diff --git a/devtools/client/webconsole/test/browser.ini b/devtools/client/webconsole/test/browser.ini index 918411182..1c7913835 100644 --- a/devtools/client/webconsole/test/browser.ini +++ b/devtools/client/webconsole/test/browser.ini @@ -182,6 +182,7 @@ subsuite = clipboard [browser_console_optimized_out_vars.js] [browser_console_private_browsing.js] skip-if = e10s # Bug 1042253 - webconsole e10s tests +[browser_console_restore.js] [browser_console_server_logging.js] [browser_console_variables_view.js] [browser_console_variables_view_filter.js] diff --git a/devtools/client/webconsole/test/browser_console.js b/devtools/client/webconsole/test/browser_console.js index 7bd1ffdc2..4358ac0f1 100644 --- a/devtools/client/webconsole/test/browser_console.js +++ b/devtools/client/webconsole/test/browser_console.js @@ -22,7 +22,7 @@ const TEST_IMAGE = "http://example.com/browser/devtools/client/webconsole/" + add_task(function* () { yield loadTab(TEST_URI); - let opened = waitForConsole(); + let opened = waitForBrowserConsole(); let hud = HUDService.getBrowserConsole(); ok(!hud, "browser console is not open"); @@ -141,20 +141,3 @@ function consoleOpened(hud) { ], }); } - -function waitForConsole() { - let deferred = promise.defer(); - - Services.obs.addObserver(function observer(aSubject) { - Services.obs.removeObserver(observer, "web-console-created"); - aSubject.QueryInterface(Ci.nsISupportsString); - - let hud = HUDService.getBrowserConsole(); - ok(hud, "browser console is open"); - is(aSubject.data, hud.hudId, "notification hudId is correct"); - - executeSoon(() => deferred.resolve(hud)); - }, "web-console-created", false); - - return deferred.promise; -} diff --git a/devtools/client/webconsole/test/browser_console_restore.js b/devtools/client/webconsole/test/browser_console_restore.js new file mode 100644 index 000000000..fb08d9c70 --- /dev/null +++ b/devtools/client/webconsole/test/browser_console_restore.js @@ -0,0 +1,30 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Check that the browser console gets session state is set correctly, and that +// it re-opens when restore is requested. + +"use strict"; + +add_task(function* () { + is(HUDService.getBrowserConsoleSessionState(), false, "Session state false by default"); + HUDService.storeBrowserConsoleSessionState(); + is(HUDService.getBrowserConsoleSessionState(), false, + "Session state still not true even after setting (since Browser Console is closed)"); + + yield HUDService.toggleBrowserConsole(); + HUDService.storeBrowserConsoleSessionState(); + is(HUDService.getBrowserConsoleSessionState(), true, + "Session state true (since Browser Console is opened)"); + + info("Closing the browser console and waiting for the session restore to reopen it") + yield HUDService.toggleBrowserConsole(); + + let opened = waitForBrowserConsole(); + HUDService.restoreBrowserConsoleSession(); + + info("Waiting for the console to open after session restore") + yield opened; +}); diff --git a/devtools/client/webconsole/test/head.js b/devtools/client/webconsole/test/head.js index 519cb78b0..2787933c4 100644 --- a/devtools/client/webconsole/test/head.js +++ b/devtools/client/webconsole/test/head.js @@ -12,7 +12,7 @@ Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtool var {Utils: WebConsoleUtils} = require("devtools/client/webconsole/utils"); var {Messages} = require("devtools/client/webconsole/console-output"); const asyncStorage = require("devtools/shared/async-storage"); -const HUDService = require("devtools/client/webconsole/hudservice"); +const {HUDService} = require("devtools/client/webconsole/hudservice"); // Services.prefs.setBoolPref("devtools.debugger.log", true); @@ -1842,3 +1842,18 @@ function getRenderedSource(root) { column: location.getAttribute("data-column"), } : null; } + +function waitForBrowserConsole() { + return new Promise(resolve => { + Services.obs.addObserver(function observer(subject) { + Services.obs.removeObserver(observer, "web-console-created"); + subject.QueryInterface(Ci.nsISupportsString); + + let hud = HUDService.getBrowserConsole(); + ok(hud, "browser console is open"); + is(subject.data, hud.hudId, "notification hudId is correct"); + + executeSoon(() => resolve(hud)); + }, "web-console-created"); + }); +} |