browser/devtools/debugger/test/browser_dbg_on-pause-raise.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_on-pause-raise.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,144 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Tests that the toolbox is raised when the debugger gets paused.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gNewTab, gFocusedWindow, gToolbox, gToolboxTab;
    1.15 +
    1.16 +function test() {
    1.17 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.18 +    gTab = aTab;
    1.19 +    gDebuggee = aDebuggee;
    1.20 +    gPanel = aPanel;
    1.21 +    gDebugger = gPanel.panelWin;
    1.22 +    gToolbox = gPanel._toolbox;
    1.23 +    gToolboxTab = gToolbox.doc.getElementById("toolbox-tab-jsdebugger");
    1.24 +
    1.25 +    waitForSourceShown(gPanel, ".html").then(performTest);
    1.26 +  });
    1.27 +}
    1.28 +
    1.29 +function performTest() {
    1.30 +  addTab(TAB_URL).then(aTab => {
    1.31 +    isnot(aTab, gTab,
    1.32 +      "The newly added tab is different from the debugger's tab.");
    1.33 +    is(gBrowser.selectedTab, aTab,
    1.34 +      "Debugger's tab is not the selected tab.");
    1.35 +
    1.36 +    gNewTab = aTab;
    1.37 +    gFocusedWindow = window;
    1.38 +    testPause();
    1.39 +  });
    1.40 +}
    1.41 +
    1.42 +function focusMainWindow() {
    1.43 +  // Make sure toolbox is not focused.
    1.44 +  window.addEventListener("focus", onFocus, true);
    1.45 +  info("Focusing main window.")
    1.46 +
    1.47 +  // Execute soon to avoid any race conditions between toolbox and main window
    1.48 +  // getting focused.
    1.49 +  executeSoon(() => {
    1.50 +    window.focus();
    1.51 +  });
    1.52 +}
    1.53 +
    1.54 +function onFocus() {
    1.55 +  window.removeEventListener("focus", onFocus, true);
    1.56 +  info("Main window focused.")
    1.57 +
    1.58 +  gFocusedWindow = window;
    1.59 +  testPause();
    1.60 +}
    1.61 +
    1.62 +function testPause() {
    1.63 +  is(gDebugger.gThreadClient.paused, false,
    1.64 +    "Should be running after starting the test.");
    1.65 +
    1.66 +  is(gFocusedWindow, window,
    1.67 +    "Main window is the top level window before pause.");
    1.68 +
    1.69 +  if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
    1.70 +    gToolbox._host._window.onfocus = () => {
    1.71 +      gFocusedWindow = gToolbox._host._window;
    1.72 +    };
    1.73 +  }
    1.74 +
    1.75 +  gDebugger.gThreadClient.addOneTimeListener("paused", () => {
    1.76 +    if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) {
    1.77 +      is(gFocusedWindow, gToolbox._host._window,
    1.78 +         "Toolbox window is the top level window on pause.");
    1.79 +    } else {
    1.80 +      is(gBrowser.selectedTab, gTab,
    1.81 +        "Debugger's tab got selected.");
    1.82 +    }
    1.83 +    gToolbox.selectTool("webconsole").then(() => {
    1.84 +      ok(gToolboxTab.hasAttribute("highlighted") &&
    1.85 +         gToolboxTab.getAttribute("highlighted") == "true",
    1.86 +        "The highlighted class is present");
    1.87 +      ok(!gToolboxTab.hasAttribute("selected") ||
    1.88 +          gToolboxTab.getAttribute("selected") != "true",
    1.89 +        "The tab is not selected");
    1.90 +    }).then(() => gToolbox.selectTool("jsdebugger")).then(() => {
    1.91 +      ok(gToolboxTab.hasAttribute("highlighted") &&
    1.92 +         gToolboxTab.getAttribute("highlighted") == "true",
    1.93 +        "The highlighted class is present");
    1.94 +      ok(gToolboxTab.hasAttribute("selected") &&
    1.95 +         gToolboxTab.getAttribute("selected") == "true",
    1.96 +        "...and the tab is selected, so the glow will not be present.");
    1.97 +    }).then(testResume);
    1.98 +  });
    1.99 +
   1.100 +  EventUtils.sendMouseEvent({ type: "mousedown" },
   1.101 +    gDebugger.document.getElementById("resume"),
   1.102 +    gDebugger);
   1.103 +}
   1.104 +
   1.105 +function testResume() {
   1.106 +  gDebugger.gThreadClient.addOneTimeListener("resumed", () => {
   1.107 +    gToolbox.selectTool("webconsole").then(() => {
   1.108 +      ok(!gToolboxTab.hasAttribute("highlighted") ||
   1.109 +          gToolboxTab.getAttribute("highlighted") != "true",
   1.110 +        "The highlighted class is not present now after the resume");
   1.111 +      ok(!gToolboxTab.hasAttribute("selected") ||
   1.112 +          gToolboxTab.getAttribute("selected") != "true",
   1.113 +        "The tab is not selected");
   1.114 +    }).then(maybeEndTest);
   1.115 +  });
   1.116 +
   1.117 +  EventUtils.sendMouseEvent({ type: "mousedown" },
   1.118 +    gDebugger.document.getElementById("resume"),
   1.119 +    gDebugger);
   1.120 +}
   1.121 +
   1.122 +function maybeEndTest() {
   1.123 +  if (gToolbox.hostType == devtools.Toolbox.HostType.BOTTOM) {
   1.124 +    info("Switching to a toolbox window host.");
   1.125 +    gToolbox.switchHost(devtools.Toolbox.HostType.WINDOW).then(focusMainWindow);
   1.126 +  } else {
   1.127 +    info("Switching to main window host.");
   1.128 +    gToolbox.switchHost(devtools.Toolbox.HostType.BOTTOM).then(() => closeDebuggerAndFinish(gPanel));
   1.129 +  }
   1.130 +}
   1.131 +
   1.132 +registerCleanupFunction(function() {
   1.133 +  // Revert to the default toolbox host, so that the following tests proceed
   1.134 +  // normally and not inside a non-default host.
   1.135 +  Services.prefs.setCharPref("devtools.toolbox.host", devtools.Toolbox.HostType.BOTTOM);
   1.136 +
   1.137 +  gTab = null;
   1.138 +  gDebuggee = null;
   1.139 +  gPanel = null;
   1.140 +  gDebugger = null;
   1.141 +
   1.142 +  removeTab(gNewTab);
   1.143 +  gNewTab = null;
   1.144 +  gFocusedWindow = null;
   1.145 +  gToolbox = null;
   1.146 +  gToolboxTab = null;
   1.147 +});

mercurial