Bug 957174 - Avoid a race in CodeMirror initialization when setting breakpoints and don't let ESC stop navigation if the debugger is paused. r=vporof, a=sledru
authorPanos Astithas <past@mozilla.com>
Thu, 19 Jun 2014 10:15:14 +0300
changeset 228814 4c3696a11b7674e1ce66d11b7c6cf8009430e3a4
parent 228813 f9aaf665255ce66f5e7086c037a86cd9b3850d3d
child 228815 12c2cc3329cbdd38f9247f295ec758ba1b0308f9
push id6
push userryanvm@gmail.com
push dateMon, 12 Jan 2015 22:04:06 +0000
treeherdermozilla-b2g37_v2_2@895c8fc7b734 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof, sledru
bugs957174
milestone32.0a2
Bug 957174 - Avoid a race in CodeMirror initialization when setting breakpoints and don't let ESC stop navigation if the debugger is paused. r=vporof, a=sledru
browser/devtools/debugger/debugger-controller.js
browser/devtools/debugger/test/browser.ini
browser/devtools/debugger/test/browser_dbg_split-console-paused-reload.js
browser/devtools/debugger/test/doc_split-console-paused-reload.html
browser/devtools/framework/toolbox.js
--- a/browser/devtools/debugger/debugger-controller.js
+++ b/browser/devtools/debugger/debugger-controller.js
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
 
 const DBG_STRINGS_URI = "chrome://browser/locale/devtools/debugger.properties";
 const NEW_SOURCE_IGNORED_URLS = ["debugger eval code", "self-hosted", "XStringBundle"];
 const NEW_SOURCE_DISPLAY_DELAY = 200; // ms
+const EDITOR_BREAKPOINTS_UPDATE_DELAY = 200; // ms
 const FETCH_SOURCE_RESPONSE_DELAY = 200; // ms
 const FETCH_EVENT_LISTENERS_DELAY = 200; // ms
 const FRAME_STEP_CLEAR_DELAY = 100; // ms
 const CALL_STACK_PAGE_SIZE = 25; // frames
 
 // The panel's window global is an EventEmitter firing the following events:
 const EVENTS = {
   // When the debugger's source editor instance finishes loading or unloading.
@@ -1158,18 +1159,20 @@ SourceScripts.prototype = {
         if (!DebuggerView.Sources.selectedValue) {
           DebuggerView.Sources.selectedIndex = 0;
         }
       });
     }
 
     // If there are any stored breakpoints for this source, display them again,
     // both in the editor and the breakpoints pane.
-    DebuggerController.Breakpoints.updateEditorBreakpoints();
     DebuggerController.Breakpoints.updatePaneBreakpoints();
+    setNamedTimeout("update-editor-bp", EDITOR_BREAKPOINTS_UPDATE_DELAY, () => {
+      DebuggerController.Breakpoints.updateEditorBreakpoints();
+    });
 
     // Make sure the events listeners are up to date.
     if (DebuggerView.instrumentsPaneTab == "events-tab") {
       DebuggerController.Breakpoints.DOM.scheduleEventListenersFetch();
     }
 
     // Signal that a new source has been added.
     window.emit(EVENTS.NEW_SOURCE);
@@ -1210,18 +1213,18 @@ SourceScripts.prototype = {
     }
     // ..or the first entry if there's no one selected yet.
     else if (!DebuggerView.Sources.selectedValue) {
       DebuggerView.Sources.selectedIndex = 0;
     }
 
     // If there are any stored breakpoints for the sources, display them again,
     // both in the editor and the breakpoints pane.
+    DebuggerController.Breakpoints.updatePaneBreakpoints();
     DebuggerController.Breakpoints.updateEditorBreakpoints();
-    DebuggerController.Breakpoints.updatePaneBreakpoints();
 
     // Signal that sources have been added.
     window.emit(EVENTS.SOURCES_ADDED);
   },
 
   /**
    * Handler for the debugger client's 'blackboxchange' notification.
    */
--- a/browser/devtools/debugger/test/browser.ini
+++ b/browser/devtools/debugger/test/browser.ini
@@ -73,16 +73,17 @@ support-files =
   doc_random-javascript.html
   doc_recursion-stack.html
   doc_scope-variable.html
   doc_scope-variable-2.html
   doc_scope-variable-3.html
   doc_scope-variable-4.html
   doc_script-switching-01.html
   doc_script-switching-02.html
+  doc_split-console-paused-reload.html
   doc_step-out.html
   doc_terminate-on-tab-close.html
   doc_tracing-01.html
   doc_watch-expressions.html
   doc_watch-expression-button.html
   doc_with-frame.html
   head.js
   sjs_random-javascript.sjs
@@ -231,16 +232,17 @@ skip-if = os == "linux" || e10s # Bug 88
 [browser_dbg_searchbox-parse.js]
 [browser_dbg_source-maps-01.js]
 [browser_dbg_source-maps-02.js]
 [browser_dbg_source-maps-03.js]
 [browser_dbg_source-maps-04.js]
 [browser_dbg_sources-cache.js]
 [browser_dbg_sources-labels.js]
 [browser_dbg_sources-sorting.js]
+[browser_dbg_split-console-paused-reload.js]
 [browser_dbg_stack-01.js]
 [browser_dbg_stack-02.js]
 [browser_dbg_stack-03.js]
 [browser_dbg_stack-04.js]
 [browser_dbg_stack-05.js]
 [browser_dbg_stack-06.js]
 [browser_dbg_stack-07.js]
 [browser_dbg_step-out.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/browser_dbg_split-console-paused-reload.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Hitting ESC to open the split console when paused on reload should not stop
+ * the pending navigation.
+ */
+
+function test() {
+  Task.spawn(runTests);
+}
+
+function* runTests() {
+  const TAB_URL = EXAMPLE_URL + "doc_split-console-paused-reload.html";
+  let [,, panel] = yield initDebugger(TAB_URL);
+  let dbgWin = panel.panelWin;
+  let frames = dbgWin.DebuggerView.StackFrames;
+  let toolbox = gDevTools.getToolbox(panel.target);
+
+  yield panel.addBreakpoint({ url: TAB_URL, line: 16 });
+  info("Breakpoint was set.");
+  dbgWin.DebuggerController._target.activeTab.reload();
+  info("Page reloaded.");
+  yield waitForSourceAndCaretAndScopes(panel, ".html", 16);
+  yield ensureThreadClientState(panel, "paused");
+  info("Breakpoint was hit.");
+  EventUtils.sendMouseEvent({ type: "mousedown" },
+    frames.selectedItem.target,
+    dbgWin);
+  info("The breadcrumb received focus.");
+
+  // This is the meat of the test.
+  let result = toolbox.once("webconsole-ready", () => {
+    ok(toolbox.splitConsole, "Split console is shown.");
+    is(dbgWin.gThreadClient.state, "paused", "Execution is still paused.");
+  });
+  EventUtils.synthesizeKey("VK_ESCAPE", {}, dbgWin);
+  yield result;
+  yield resumeDebuggerThenCloseAndFinish(panel);
+}
new file mode 100644
--- /dev/null
+++ b/browser/devtools/debugger/test/doc_split-console-paused-reload.html
@@ -0,0 +1,20 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <title>Test page for opening a split-console when execution is paused</title>
+  </head>
+
+  <body>
+    <script type="text/javascript">
+      function runDebuggerStatement() {
+        debugger;
+      }
+      window.foobar = 1;
+    </script>
+  </body>
+
+</html>
--- a/browser/devtools/framework/toolbox.js
+++ b/browser/devtools/framework/toolbox.js
@@ -288,16 +288,22 @@ Toolbox.prototype = {
     }
     return responsiveModeActive;
   },
 
   _splitConsoleOnKeypress: function(e) {
     let responsiveModeActive = this._isResponsiveModeActive();
     if (e.keyCode === e.DOM_VK_ESCAPE && !responsiveModeActive) {
       this.toggleSplitConsole();
+      // If the debugger is paused, don't let the ESC key stop any pending
+      // navigation.
+      let jsdebugger = this.getPanel("jsdebugger");
+      if (jsdebugger && jsdebugger.panelWin.gThreadClient.state == "paused") {
+        e.preventDefault();
+      }
     }
   },
 
   _addReloadKeys: function() {
     [
       ["toolbox-reload-key", false],
       ["toolbox-reload-key2", false],
       ["toolbox-force-reload-key", true],