From fbc64fb6e0125343112aac0e64a97d55c4afbda6 Mon Sep 17 00:00:00 2001 From: Panos Astithas Date: Wed, 31 Oct 2012 16:02:07 +0200 Subject: [PATCH] Bug 771655 - Debugger does not show up if any progress listener (e.g. NoScript) reads the WebProgress argument's DOMWindow property in onStateChange(); r=vporof --- .../devtools/debugger/debugger-controller.js | 2 + browser/devtools/debugger/debugger-view.js | 2 +- browser/devtools/debugger/test/Makefile.in | 1 + .../test/browser_dbg_progress-listener-bug.js | 70 +++++++++++++++++++ 4 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 browser/devtools/debugger/test/browser_dbg_progress-listener-bug.js diff --git a/browser/devtools/debugger/debugger-controller.js b/browser/devtools/debugger/debugger-controller.js index 251a3820305..7226f814657 100644 --- a/browser/devtools/debugger/debugger-controller.js +++ b/browser/devtools/debugger/debugger-controller.js @@ -51,6 +51,7 @@ let DebuggerController = { window.removeEventListener("load", this._startupDebugger, true); DebuggerView.initialize(function() { + DebuggerView._isInitialized = true; window.dispatchEvent("Debugger:Loaded"); this._connect(); }.bind(this)); @@ -67,6 +68,7 @@ let DebuggerController = { window.removeEventListener("unload", this._shutdownDebugger, true); DebuggerView.destroy(function() { + DebuggerView._isDestroyed = true; this.SourceScripts.disconnect(); this.StackFrames.disconnect(); this.ThreadState.disconnect(); diff --git a/browser/devtools/debugger/debugger-view.js b/browser/devtools/debugger/debugger-view.js index b77ecf54e2a..96034a0878e 100644 --- a/browser/devtools/debugger/debugger-view.js +++ b/browser/devtools/debugger/debugger-view.js @@ -45,7 +45,6 @@ let DebuggerView = { this._initializePanes(); this._initializeEditor(aCallback) - this._isInitialized = true; }, /** @@ -419,6 +418,7 @@ let DebuggerView = { _stackframesAndBreakpoints: null, _variables: null, _isInitialized: false, + _isDestroyed: false }; /** diff --git a/browser/devtools/debugger/test/Makefile.in b/browser/devtools/debugger/test/Makefile.in index e166872588c..52011b33cae 100644 --- a/browser/devtools/debugger/test/Makefile.in +++ b/browser/devtools/debugger/test/Makefile.in @@ -73,6 +73,7 @@ MOCHITEST_BROWSER_TESTS = \ browser_dbg_bfcache.js \ browser_dbg_breakpoint-new-script.js \ browser_dbg_bug737803_editor_actual_location.js \ + browser_dbg_progress-listener-bug.js \ head.js \ $(NULL) diff --git a/browser/devtools/debugger/test/browser_dbg_progress-listener-bug.js b/browser/devtools/debugger/test/browser_dbg_progress-listener-bug.js new file mode 100644 index 00000000000..73e1ed50fac --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_progress-listener-bug.js @@ -0,0 +1,70 @@ +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests that the debugger does show up even if a progress listener reads the +// WebProgress argument's DOMWindow property in onStateChange() (bug 771655). + +var gPane = null; +var gTab = null; +var gOldListener = null; + +const TEST_URL = EXAMPLE_URL + "browser_dbg_script-switching.html"; + +function test() { + installListener(); + + debug_tab_pane(TEST_URL, function(aTab, aDebuggee, aPane) { + gTab = aTab; + gPane = aPane; + let gDebugger = gPane.contentWindow; + + is(gDebugger.DebuggerController._isInitialized, true, + "Controller should be initialized after debug_tab_pane."); + is(gDebugger.DebuggerView._isInitialized, true, + "View should be initialized after debug_tab_pane."); + + closeDebuggerAndFinish(); + }); +} + +// This is taken almost verbatim from bug 771655. +function installListener() { + if ("_testPL" in window) { + gOldListener = _testPL; + Cc['@mozilla.org/docloaderservice;1'].getService(Ci.nsIWebProgress) + .removeProgressListener(_testPL); + } + + window._testPL = { + START_DOC: Ci.nsIWebProgressListener.STATE_START | + Ci.nsIWebProgressListener.STATE_IS_DOCUMENT, + onStateChange: function(wp, req, stateFlags, status) { + if ((stateFlags & this.START_DOC) === this.START_DOC) { + // This DOMWindow access triggers the unload event. + wp.DOMWindow; + } + }, + QueryInterface: function(iid) { + if (iid.equals(Ci.nsISupportsWeakReference) || + iid.equals(Ci.nsIWebProgressListener)) + return this; + throw Cr.NS_ERROR_NO_INTERFACE; + } + } + + Cc['@mozilla.org/docloaderservice;1'].getService(Ci.nsIWebProgress) + .addProgressListener(_testPL, Ci.nsIWebProgress.NOTIFY_STATE_REQUEST); +} + +registerCleanupFunction(function() { + if (gOldListener) { + window._testPL = gOldListener; + } else { + delete window._testPL; + } + removeTab(gTab); + gPane = null; + gTab = null; +});