browser/devtools/debugger/test/browser_dbg_breakpoints-pane.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_breakpoints-pane.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,255 @@
     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 + * Bug 723071: Test adding a pane to display the list of breakpoints across
     1.9 + * all sources in the debuggee.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.13 +
    1.14 +function test() {
    1.15 +  let gTab, gDebuggee, gPanel, gDebugger;
    1.16 +  let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
    1.17 +
    1.18 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.19 +    gTab = aTab;
    1.20 +    gDebuggee = aDebuggee;
    1.21 +    gPanel = aPanel;
    1.22 +    gDebugger = gPanel.panelWin;
    1.23 +    gEditor = gDebugger.DebuggerView.editor;
    1.24 +    gSources = gDebugger.DebuggerView.Sources;
    1.25 +    gBreakpoints = gDebugger.DebuggerController.Breakpoints;
    1.26 +    gBreakpointsAdded = gBreakpoints._added;
    1.27 +    gBreakpointsRemoving = gBreakpoints._removing;
    1.28 +
    1.29 +    waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest);
    1.30 +    gDebuggee.firstCall();
    1.31 +  });
    1.32 +
    1.33 +  let breakpointsAdded = 0;
    1.34 +  let breakpointsDisabled = 0;
    1.35 +  let breakpointsRemoved = 0;
    1.36 +
    1.37 +  function performTest() {
    1.38 +    is(gDebugger.gThreadClient.state, "paused",
    1.39 +      "Should only be getting stack frames while paused.");
    1.40 +    is(gSources.itemCount, 2,
    1.41 +      "Found the expected number of sources.");
    1.42 +    is(gEditor.getText().indexOf("debugger"), 172,
    1.43 +      "The correct source was loaded initially.");
    1.44 +    is(gSources.selectedValue, gSources.values[1],
    1.45 +      "The correct source is selected.");
    1.46 +
    1.47 +    is(gBreakpointsAdded.size, 0,
    1.48 +      "No breakpoints currently added.");
    1.49 +    is(gBreakpointsRemoving.size, 0,
    1.50 +      "No breakpoints currently being removed.");
    1.51 +    is(gEditor.getBreakpoints().length, 0,
    1.52 +      "No breakpoints currently shown in the editor.");
    1.53 +
    1.54 +    ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
    1.55 +      "_getAdded('foo', 3) returns falsey.");
    1.56 +    ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
    1.57 +      "_getRemoving('bar', 3) returns falsey.");
    1.58 +
    1.59 +    let breakpointsParent = gSources.widget._parent;
    1.60 +    let breakpointsList = gSources.widget._list;
    1.61 +
    1.62 +    is(breakpointsParent.childNodes.length, 1, // one sources list
    1.63 +      "Found junk in the breakpoints container.");
    1.64 +    is(breakpointsList.childNodes.length, 1, // one sources group
    1.65 +      "Found junk in the breakpoints container.");
    1.66 +    is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
    1.67 +      "No breakpoints should be visible at this point.");
    1.68 +
    1.69 +    addBreakpoints(true).then(() => {
    1.70 +      is(breakpointsAdded, 3,
    1.71 +        "Should have added 3 breakpoints so far.");
    1.72 +      is(breakpointsDisabled, 0,
    1.73 +        "Shouldn't have disabled anything so far.");
    1.74 +      is(breakpointsRemoved, 0,
    1.75 +        "Shouldn't have removed anything so far.");
    1.76 +
    1.77 +      is(breakpointsParent.childNodes.length, 1, // one sources list
    1.78 +        "Found junk in the breakpoints container.");
    1.79 +      is(breakpointsList.childNodes.length, 1, // one sources group
    1.80 +        "Found junk in the breakpoints container.");
    1.81 +      is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 3,
    1.82 +        "3 breakpoints should be visible at this point.");
    1.83 +
    1.84 +      disableBreakpoints().then(() => {
    1.85 +        is(breakpointsAdded, 3,
    1.86 +          "Should still have 3 breakpoints added so far.");
    1.87 +        is(breakpointsDisabled, 3,
    1.88 +          "Should have 3 disabled breakpoints.");
    1.89 +        is(breakpointsRemoved, 0,
    1.90 +          "Shouldn't have removed anything so far.");
    1.91 +
    1.92 +        is(breakpointsParent.childNodes.length, 1, // one sources list
    1.93 +          "Found junk in the breakpoints container.");
    1.94 +        is(breakpointsList.childNodes.length, 1, // one sources group
    1.95 +          "Found junk in the breakpoints container.");
    1.96 +        is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
    1.97 +          "Should have the same number of breakpoints in the pane.");
    1.98 +        is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsDisabled,
    1.99 +          "Should have the same number of disabled breakpoints.");
   1.100 +
   1.101 +        addBreakpoints().then(() => {
   1.102 +          is(breakpointsAdded, 3,
   1.103 +            "Should still have only 3 breakpoints added so far.");
   1.104 +          is(breakpointsDisabled, 3,
   1.105 +            "Should still have 3 disabled breakpoints.");
   1.106 +          is(breakpointsRemoved, 0,
   1.107 +            "Shouldn't have removed anything so far.");
   1.108 +
   1.109 +          is(breakpointsParent.childNodes.length, 1, // one sources list
   1.110 +            "Found junk in the breakpoints container.");
   1.111 +          is(breakpointsList.childNodes.length, 1, // one sources group
   1.112 +            "Found junk in the breakpoints container.");
   1.113 +          is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
   1.114 +            "Since half of the breakpoints already existed, but disabled, " +
   1.115 +            "only half of the added breakpoints are actually in the pane.");
   1.116 +
   1.117 +          removeBreakpoints().then(() => {
   1.118 +            is(breakpointsRemoved, 3,
   1.119 +              "Should have 3 removed breakpoints.");
   1.120 +
   1.121 +            is(breakpointsParent.childNodes.length, 1, // one sources list
   1.122 +               "Found junk in the breakpoints container.");
   1.123 +            is(breakpointsList.childNodes.length, 1, // one sources group
   1.124 +               "Found junk in the breakpoints container.");
   1.125 +            is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
   1.126 +               "No breakpoints should be visible at this point.");
   1.127 +
   1.128 +            waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
   1.129 +              finalCheck();
   1.130 +              closeDebuggerAndFinish(gPanel);
   1.131 +            });
   1.132 +
   1.133 +            gDebugger.gThreadClient.resume();
   1.134 +          });
   1.135 +        });
   1.136 +      });
   1.137 +    });
   1.138 +
   1.139 +    function addBreakpoints(aIncrementFlag) {
   1.140 +      let deferred = promise.defer();
   1.141 +
   1.142 +      gPanel.addBreakpoint({ url: gSources.selectedValue, line: 6 }).then(aClient => {
   1.143 +        onBreakpointAdd(aClient, {
   1.144 +          increment: aIncrementFlag,
   1.145 +          line: 6,
   1.146 +          text: "eval(\"debugger;\");"
   1.147 +        });
   1.148 +
   1.149 +        gPanel.addBreakpoint({ url: gSources.selectedValue, line: 7 }).then(aClient => {
   1.150 +          onBreakpointAdd(aClient, {
   1.151 +            increment: aIncrementFlag,
   1.152 +            line: 7,
   1.153 +            text: "function foo() {}"
   1.154 +          });
   1.155 +
   1.156 +          gPanel.addBreakpoint({ url: gSources.selectedValue, line: 9 }).then(aClient => {
   1.157 +            onBreakpointAdd(aClient, {
   1.158 +              increment: aIncrementFlag,
   1.159 +              line: 9,
   1.160 +              text: "foo();"
   1.161 +            });
   1.162 +
   1.163 +            deferred.resolve();
   1.164 +          });
   1.165 +        });
   1.166 +      });
   1.167 +
   1.168 +      return deferred.promise;
   1.169 +    }
   1.170 +
   1.171 +    function disableBreakpoints() {
   1.172 +      let deferred = promise.defer();
   1.173 +
   1.174 +      let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
   1.175 +      info("Nodes to disable: " + breakpointsAdded.length);
   1.176 +
   1.177 +      is(nodes.length, breakpointsAdded,
   1.178 +        "The number of nodes to disable is incorrect.");
   1.179 +
   1.180 +      for (let node of nodes) {
   1.181 +        info("Disabling breakpoint: " + node.id);
   1.182 +
   1.183 +        let sourceItem = gSources.getItemForElement(node);
   1.184 +        let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
   1.185 +        info("Found data: " + breakpointItem.attachment.toSource());
   1.186 +
   1.187 +        gSources.disableBreakpoint(breakpointItem.attachment).then(() => {
   1.188 +          if (++breakpointsDisabled == breakpointsAdded) {
   1.189 +            deferred.resolve();
   1.190 +          }
   1.191 +        });
   1.192 +      }
   1.193 +
   1.194 +      return deferred.promise;
   1.195 +    }
   1.196 +
   1.197 +    function removeBreakpoints() {
   1.198 +      let deferred = promise.defer();
   1.199 +
   1.200 +      let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
   1.201 +      info("Nodes to remove: " + breakpointsAdded.length);
   1.202 +
   1.203 +      is(nodes.length, breakpointsAdded,
   1.204 +        "The number of nodes to remove is incorrect.");
   1.205 +
   1.206 +      for (let node of nodes) {
   1.207 +        info("Removing breakpoint: " + node.id);
   1.208 +
   1.209 +        let sourceItem = gSources.getItemForElement(node);
   1.210 +        let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
   1.211 +        info("Found data: " + breakpointItem.attachment.toSource());
   1.212 +
   1.213 +        gPanel.removeBreakpoint(breakpointItem.attachment).then(() => {
   1.214 +          if (++breakpointsRemoved == breakpointsAdded) {
   1.215 +            deferred.resolve();
   1.216 +          }
   1.217 +        });
   1.218 +      }
   1.219 +
   1.220 +      return deferred.promise;
   1.221 +    }
   1.222 +
   1.223 +    function onBreakpointAdd(aBreakpointClient, aTestData) {
   1.224 +      if (aTestData.increment) {
   1.225 +        breakpointsAdded++;
   1.226 +      }
   1.227 +
   1.228 +      is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
   1.229 +        aTestData.increment
   1.230 +          ? "Should have added a breakpoint in the pane."
   1.231 +          : "Should have the same number of breakpoints in the pane.");
   1.232 +
   1.233 +      let identifier = gBreakpoints.getIdentifier(aBreakpointClient.location);
   1.234 +      let node = gDebugger.document.getElementById("breakpoint-" + identifier);
   1.235 +      let line = node.getElementsByClassName("dbg-breakpoint-line")[0];
   1.236 +      let text = node.getElementsByClassName("dbg-breakpoint-text")[0];
   1.237 +      let check = node.querySelector("checkbox");
   1.238 +
   1.239 +      ok(node,
   1.240 +        "Breakpoint element found successfully.");
   1.241 +      is(line.getAttribute("value"), aTestData.line,
   1.242 +        "The expected information wasn't found in the breakpoint element.");
   1.243 +      is(text.getAttribute("value"), aTestData.text,
   1.244 +        "The expected line text wasn't found in the breakpoint element.");
   1.245 +      is(check.getAttribute("checked"), "true",
   1.246 +        "The breakpoint enable checkbox is checked as expected.");
   1.247 +    }
   1.248 +  }
   1.249 +
   1.250 +  function finalCheck() {
   1.251 +    is(gBreakpointsAdded.size, 0,
   1.252 +      "No breakpoints currently added.");
   1.253 +    is(gBreakpointsRemoving.size, 0,
   1.254 +      "No breakpoints currently being removed.");
   1.255 +    is(gEditor.getBreakpoints().length, 0,
   1.256 +      "No breakpoints currently shown in the editor.");
   1.257 +  }
   1.258 +}

mercurial