diff --git a/browser/devtools/debugger/debugger-controller.js b/browser/devtools/debugger/debugger-controller.js index e7ca09b013ca..c0b4fb5c52c1 100644 --- a/browser/devtools/debugger/debugger-controller.js +++ b/browser/devtools/debugger/debugger-controller.js @@ -544,7 +544,7 @@ StackFrames.prototype = { // Watch expressions are evaluated in the context of the topmost frame, - // and the results and displayed in the variables view. + // and the results are displayed in the variables view. if (this.currentWatchExpressions) { // Evaluation causes the stack frames to be cleared and active thread to // pause, sending a 'clientEvaluated' packed and adding the frames again. diff --git a/browser/devtools/debugger/debugger-panes.js b/browser/devtools/debugger/debugger-panes.js index 3b1b8ec3c4c2..95549a346cc1 100644 --- a/browser/devtools/debugger/debugger-panes.js +++ b/browser/devtools/debugger/debugger-panes.js @@ -100,7 +100,7 @@ create({ constructor: SourcesView, proto: MenuContainer.prototype }, { * - forced: force the source to be immediately added */ addSource: function(aSource, aOptions = {}) { - let url = NetworkHelper.convertToUnicode(unescape(aSource.url)); + let url = aSource.url; let label = SourceUtils.getSourceLabel(url.split(" -> ").pop()); let group = SourceUtils.getSourceGroup(url.split(" -> ").pop()); diff --git a/browser/devtools/debugger/test/Makefile.in b/browser/devtools/debugger/test/Makefile.in index 61f0079e7da3..88d006acc21e 100644 --- a/browser/devtools/debugger/test/Makefile.in +++ b/browser/devtools/debugger/test/Makefile.in @@ -63,6 +63,7 @@ MOCHITEST_BROWSER_TESTS = \ browser_dbg_location-changes-bp.js \ browser_dbg_sources-cache.js \ browser_dbg_scripts-switching.js \ + browser_dbg_scripts-switching-02.js \ browser_dbg_scripts-sorting.js \ browser_dbg_scripts-searching-01.js \ browser_dbg_scripts-searching-02.js \ @@ -110,6 +111,7 @@ MOCHITEST_BROWSER_PAGES = \ browser_dbg_debuggerstatement.html \ browser_dbg_stack.html \ browser_dbg_script-switching.html \ + browser_dbg_script-switching-02.html \ test-script-switching-01.js \ test-script-switching-02.js \ browser_dbg_big-data.html \ diff --git a/browser/devtools/debugger/test/browser_dbg_script-switching-02.html b/browser/devtools/debugger/test/browser_dbg_script-switching-02.html new file mode 100644 index 000000000000..42d960a15b96 --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_script-switching-02.html @@ -0,0 +1,13 @@ + + + + + Browser Debugger Script Switching Test + + + + + + + diff --git a/browser/devtools/debugger/test/browser_dbg_scripts-switching-02.js b/browser/devtools/debugger/test/browser_dbg_scripts-switching-02.js new file mode 100644 index 000000000000..b444ae100062 --- /dev/null +++ b/browser/devtools/debugger/test/browser_dbg_scripts-switching-02.js @@ -0,0 +1,175 @@ +/* vim:set ts=2 sw=2 sts=2 et: */ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Make sure that switching the displayed script in the UI works as advertised + * when urls are escaped. + */ + +const TAB_URL = EXAMPLE_URL + "browser_dbg_script-switching-02.html"; + +var gPane = null; +var gTab = null; +var gDebuggee = null; +var gDebugger = null; +var gSources = null; + +function test() +{ + let scriptShown = false; + let framesAdded = false; + let resumed = false; + let testStarted = false; + + debug_tab_pane(TAB_URL, function(aTab, aDebuggee, aPane) { + gTab = aTab; + gDebuggee = aDebuggee; + gPane = aPane; + gDebugger = gPane.panelWin; + resumed = true; + + gDebugger.addEventListener("Debugger:SourceShown", onScriptShown); + + gDebugger.DebuggerController.activeThread.addOneTimeListener("framesadded", function() { + framesAdded = true; + executeSoon(startTest); + }); + + executeSoon(function() { + gDebuggee.firstCall(); + }); + }); + + function onScriptShown(aEvent) + { + scriptShown = aEvent.detail.url.indexOf("-02.js") != -1; + executeSoon(startTest); + } + + function startTest() + { + if (scriptShown && framesAdded && resumed && !testStarted) { + gDebugger.removeEventListener("Debugger:SourceShown", onScriptShown); + testStarted = true; + Services.tm.currentThread.dispatch({ run: testScriptsDisplay }, 0); + } + } +} + +function testScriptsDisplay() { + gSources = gDebugger.DebuggerView.Sources; + + is(gDebugger.DebuggerController.activeThread.state, "paused", + "Should only be getting stack frames while paused."); + + is(gSources.itemCount, 2, + "Found the expected number of scripts."); + + for (let i = 0; i < gSources.itemCount; i++) { + info("label: " + i + " " + gSources.getItemAtIndex(i).target.getAttribute("label")); + } + + let label1 = "test-script-switching-01.js"; + let label2 = "test-script-switching-02.js"; + let params = "?foo=bar,baz|lol"; + + ok(gDebugger.DebuggerView.Sources.containsValue(EXAMPLE_URL + + label1), "First script url is incorrect."); + ok(gDebugger.DebuggerView.Sources.containsValue(EXAMPLE_URL + + label2 + params), "Second script url is incorrect."); + + ok(gDebugger.DebuggerView.Sources.containsLabel( + label1), "First script label is incorrect."); + ok(gDebugger.DebuggerView.Sources.containsLabel( + label2), "Second script label is incorrect."); + + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label2, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label2 + params, "The selected value is the sources pane is incorrect."); + + ok(gDebugger.editor.getText().search(/debugger/) != -1, + "The correct script was loaded initially."); + + is(gDebugger.editor.getDebugLocation(), 5, + "Editor debugger location is correct."); + + gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) { + let url = aEvent.detail.url; + if (url.indexOf("-01.js") != -1) { + gDebugger.removeEventListener(aEvent.type, _onEvent); + testSwitch1(); + } + }); + + gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL + label1; +} + +function testSwitch1() { + dump("Debugger editor text:\n" + gDebugger.editor.getText() + "\n"); + + let label1 = "test-script-switching-01.js"; + let label2 = "test-script-switching-02.js"; + let params = "?foo=bar,baz|lol"; + + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label1, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label1, "The selected value is the sources pane is incorrect."); + + ok(gDebugger.editor.getText().search(/debugger/) == -1, + "The second script is no longer displayed."); + + ok(gDebugger.editor.getText().search(/firstCall/) != -1, + "The first script is displayed."); + + is(gDebugger.editor.getDebugLocation(), -1, + "Editor debugger location has been cleared."); + + gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) { + let url = aEvent.detail.url; + if (url.indexOf("-02.js") != -1) { + gDebugger.removeEventListener(aEvent.type, _onEvent); + testSwitch2(); + } + }); + + gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL + label2 + params; +} + +function testSwitch2() { + dump("Debugger editor text:\n" + gDebugger.editor.getText() + "\n"); + + let label1 = "test-script-switching-01.js"; + let label2 = "test-script-switching-02.js"; + let params = "?foo=bar,baz|lol"; + + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label2, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label2 + params, "The selected value is the sources pane is incorrect."); + + ok(gDebugger.editor.getText().search(/debugger/) != -1, + "The correct script was loaded initially."); + + is(gDebugger.editor.getDebugLocation(), 5, + "Editor debugger location is correct."); + + closeDebuggerAndFinish(); +} + +registerCleanupFunction(function() { + removeTab(gTab); + gPane = null; + gTab = null; + gDebuggee = null; + gDebugger = null; + gSources = null; +}); diff --git a/browser/devtools/debugger/test/browser_dbg_scripts-switching.js b/browser/devtools/debugger/test/browser_dbg_scripts-switching.js index df97a49d650d..e291bf7c90e2 100644 --- a/browser/devtools/debugger/test/browser_dbg_scripts-switching.js +++ b/browser/devtools/debugger/test/browser_dbg_scripts-switching.js @@ -82,6 +82,13 @@ function testScriptsDisplay() { ok(gDebugger.DebuggerView.Sources.containsLabel( label2), "Second script label is incorrect."); + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label2, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label2, "The selected value is the sources pane is incorrect."); + ok(gDebugger.editor.getText().search(/debugger/) != -1, "The correct script was loaded initially."); @@ -101,6 +108,18 @@ function testScriptsDisplay() { function testSwitchPaused() { + dump("Debugger editor text:\n" + gDebugger.editor.getText() + "\n"); + + let label1 = "test-script-switching-01.js"; + let label2 = "test-script-switching-02.js"; + + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label1, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label1, "The selected value is the sources pane is incorrect."); + ok(gDebugger.editor.getText().search(/debugger/) == -1, "The second script is no longer displayed."); @@ -108,7 +127,7 @@ function testSwitchPaused() "The first script is displayed."); is(gDebugger.editor.getDebugLocation(), -1, - "editor debugger location has been cleared."); + "Editor debugger location has been cleared."); gDebugger.DebuggerController.activeThread.resume(function() { gDebugger.addEventListener("Debugger:SourceShown", function _onEvent(aEvent) { @@ -119,8 +138,7 @@ function testSwitchPaused() } }); - gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL + - "test-script-switching-02.js"; + gDebugger.DebuggerView.Sources.selectedValue = EXAMPLE_URL + label2; }); } @@ -128,6 +146,16 @@ function testSwitchRunning() { dump("Debugger editor text:\n" + gDebugger.editor.getText() + "\n"); + let label1 = "test-script-switching-01.js"; + let label2 = "test-script-switching-02.js"; + + ok(gDebugger.DebuggerView.Sources.selectedItem, + "There should be a selected item in the sources pane."); + is(gDebugger.DebuggerView.Sources.selectedLabel, + label2, "The selected label is the sources pane is incorrect."); + is(gDebugger.DebuggerView.Sources.selectedValue, EXAMPLE_URL + + label2, "The selected value is the sources pane is incorrect."); + ok(gDebugger.editor.getText().search(/debugger/) != -1, "The second script is displayed again."); @@ -135,7 +163,7 @@ function testSwitchRunning() "The first script is no longer displayed."); is(gDebugger.editor.getDebugLocation(), -1, - "editor debugger location is still -1."); + "Editor debugger location is still -1."); closeDebuggerAndFinish(); } diff --git a/browser/devtools/shared/widgets/SideMenuWidget.jsm b/browser/devtools/shared/widgets/SideMenuWidget.jsm index 81c9ac52e44d..885736b38193 100644 --- a/browser/devtools/shared/widgets/SideMenuWidget.jsm +++ b/browser/devtools/shared/widgets/SideMenuWidget.jsm @@ -10,9 +10,13 @@ const Cu = Components.utils; const ENSURE_SELECTION_VISIBLE_DELAY = 50; // ms +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource:///modules/devtools/ViewHelpers.jsm"); Cu.import("resource:///modules/devtools/shared/event-emitter.js"); +XPCOMUtils.defineLazyModuleGetter(this, "NetworkHelper", + "resource://gre/modules/devtools/NetworkHelper.jsm"); + this.EXPORTED_SYMBOLS = ["SideMenuWidget"]; /** @@ -50,8 +54,8 @@ this.SideMenuWidget = function SideMenuWidget(aNode, aShowArrows = true) { this._list.setAttribute("orient", "vertical"); this._list.setAttribute("with-arrow", aShowArrows); this._list.setAttribute("tabindex", "0"); - this._list.addEventListener("keypress", e => this.emit("keyPress", e), true); - this._list.addEventListener("mousedown", e => this.emit("mousePress", e), true); + this._list.addEventListener("keypress", e => this.emit("keyPress", e), false); + this._list.addEventListener("mousedown", e => this.emit("mousePress", e), false); this._parent.appendChild(this._list); this._boxObject = this._list.boxObject.QueryInterface(Ci.nsIScrollBoxObject); @@ -112,6 +116,9 @@ SideMenuWidget.prototype = { * The element associated with the displayed item. */ insertItemAt: function(aIndex, aContents, aTooltip = "", aGroup = "") { + aTooltip = NetworkHelper.convertToUnicode(unescape(aTooltip)); + aGroup = NetworkHelper.convertToUnicode(unescape(aGroup)); + // Invalidate any notices set on this widget. this.removeAttribute("notice");