From a3272dcdc079265b46a6eea5b436c041ebeca3f4 Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Sat, 5 Oct 2013 16:26:08 +0300 Subject: [PATCH] Bug 923779 - Native code event listeners can get listed multiple times in the events pane, r=past --- browser/devtools/debugger/debugger-panes.js | 13 ++- browser/devtools/debugger/test/browser.ini | 1 + .../test/browser_dbg_break-on-dom-07.js | 104 ++++++++++++++++++ 3 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 browser/devtools/debugger/test/browser_dbg_break-on-dom-07.js diff --git a/browser/devtools/debugger/debugger-panes.js b/browser/devtools/debugger/debugger-panes.js index 00633ca943bf..6733549fb756 100644 --- a/browser/devtools/debugger/debugger-panes.js +++ b/browser/devtools/debugger/debugger-panes.js @@ -1552,6 +1552,13 @@ EventListenersView.prototype = Heritage.extend(WidgetMethods, { */ addListener: function(aListener, aOptions = {}) { let { node: { selector }, function: { url }, type } = aListener; + if (!type) return; + + // Some listener objects may be added from plugins, thus getting + // translated to native code. + if (!url) { + url = this._inNativeCodeString; + } // If an event item for this listener's url and type was already added, // avoid polluting the view and simply increase the "targets" count. @@ -1627,12 +1634,6 @@ EventListenersView.prototype = Heritage.extend(WidgetMethods, { group = L10N.getStr("otherEvents"); } - // Some listener objects may be added from plugins, thus getting - // translated to native code. - if (!url) { - url = this._inNativeCodeString; - } - // Create the element node for the event listener item. let itemView = this._createItemView(type, selector, url); diff --git a/browser/devtools/debugger/test/browser.ini b/browser/devtools/debugger/test/browser.ini index 2043b66647e8..581cdc3d662c 100644 --- a/browser/devtools/debugger/test/browser.ini +++ b/browser/devtools/debugger/test/browser.ini @@ -74,6 +74,7 @@ support-files = [browser_dbg_break-on-dom-04.js] [browser_dbg_break-on-dom-05.js] [browser_dbg_break-on-dom-06.js] +[browser_dbg_break-on-dom-07.js] [browser_dbg_breakpoints-actual-location.js] [browser_dbg_breakpoints-contextmenu.js] [browser_dbg_breakpoints-disabled-reload.js] diff --git a/browser/devtools/debugger/test/browser_dbg_break-on-dom-07.js b/browser/devtools/debugger/test/browser_dbg_break-on-dom-07.js new file mode 100644 index 000000000000..937785066912 --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_break-on-dom-07.js @@ -0,0 +1,104 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests that system event listeners don't get duplicated in the view. + */ + +function test() { + initDebugger("about:blank").then(([aTab, aDebuggee, aPanel]) => { + let gDebugger = aPanel.panelWin; + let gView = gDebugger.DebuggerView; + let gEvents = gView.EventListeners; + let gL10N = gDebugger.L10N; + + is(gEvents.itemCount, 0, + "There are no events displayed in the corresponding pane yet."); + + gEvents.addListener({ + type: "foo", + node: { selector: "#first" }, + function: { url: null } + }); + + is(gEvents.itemCount, 1, + "There was a system event listener added in the view."); + is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), + "The correct string is used as the event's url."); + is(gEvents.attachments[0].type, "foo", + "The correct string is used as the event's type."); + is(gEvents.attachments[0].selectors.toString(), "#first", + "The correct array of selectors is used as the event's target."); + + gEvents.addListener({ + type: "bar", + node: { selector: "#second" }, + function: { url: null } + }); + + is(gEvents.itemCount, 2, + "There was another system event listener added in the view."); + is(gEvents.attachments[1].url, gL10N.getStr("eventNative"), + "The correct string is used as the event's url."); + is(gEvents.attachments[1].type, "bar", + "The correct string is used as the event's type."); + is(gEvents.attachments[1].selectors.toString(), "#second", + "The correct array of selectors is used as the event's target."); + + gEvents.addListener({ + type: "foo", + node: { selector: "#first" }, + function: { url: null } + }); + + is(gEvents.itemCount, 2, + "There wasn't another system event listener added in the view."); + is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), + "The correct string is used as the event's url."); + is(gEvents.attachments[0].type, "foo", + "The correct string is used as the event's type."); + is(gEvents.attachments[0].selectors.toString(), "#first", + "The correct array of selectors is used as the event's target."); + + gEvents.addListener({ + type: "foo", + node: { selector: "#second" }, + function: { url: null } + }); + + is(gEvents.itemCount, 2, + "There still wasn't another system event listener added in the view."); + is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), + "The correct string is used as the event's url."); + is(gEvents.attachments[0].type, "foo", + "The correct string is used as the event's type."); + is(gEvents.attachments[0].selectors.toString(), "#first,#second", + "The correct array of selectors is used as the event's target."); + + + gEvents.addListener({ + type: null, + node: { selector: "#bogus" }, + function: { url: null } + }); + + is(gEvents.itemCount, 2, + "No bogus system event listener was added in the view."); + + is(gEvents.attachments[0].url, gL10N.getStr("eventNative"), + "The correct string is used as the first event's url."); + is(gEvents.attachments[0].type, "foo", + "The correct string is used as the first event's type."); + is(gEvents.attachments[0].selectors.toString(), "#first,#second", + "The correct array of selectors is used as the first event's target."); + + is(gEvents.attachments[1].url, gL10N.getStr("eventNative"), + "The correct string is used as the second event's url."); + is(gEvents.attachments[1].type, "bar", + "The correct string is used as the second event's type."); + is(gEvents.attachments[1].selectors.toString(), "#second", + "The correct array of selectors is used as the second event's target."); + + closeDebuggerAndFinish(aPanel); + }); +}