browser/devtools/debugger/test/browser_dbg_breakpoints-pane.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 /**
     5  * Bug 723071: Test adding a pane to display the list of breakpoints across
     6  * all sources in the debuggee.
     7  */
     9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    11 function test() {
    12   let gTab, gDebuggee, gPanel, gDebugger;
    13   let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
    15   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    16     gTab = aTab;
    17     gDebuggee = aDebuggee;
    18     gPanel = aPanel;
    19     gDebugger = gPanel.panelWin;
    20     gEditor = gDebugger.DebuggerView.editor;
    21     gSources = gDebugger.DebuggerView.Sources;
    22     gBreakpoints = gDebugger.DebuggerController.Breakpoints;
    23     gBreakpointsAdded = gBreakpoints._added;
    24     gBreakpointsRemoving = gBreakpoints._removing;
    26     waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest);
    27     gDebuggee.firstCall();
    28   });
    30   let breakpointsAdded = 0;
    31   let breakpointsDisabled = 0;
    32   let breakpointsRemoved = 0;
    34   function performTest() {
    35     is(gDebugger.gThreadClient.state, "paused",
    36       "Should only be getting stack frames while paused.");
    37     is(gSources.itemCount, 2,
    38       "Found the expected number of sources.");
    39     is(gEditor.getText().indexOf("debugger"), 172,
    40       "The correct source was loaded initially.");
    41     is(gSources.selectedValue, gSources.values[1],
    42       "The correct source is selected.");
    44     is(gBreakpointsAdded.size, 0,
    45       "No breakpoints currently added.");
    46     is(gBreakpointsRemoving.size, 0,
    47       "No breakpoints currently being removed.");
    48     is(gEditor.getBreakpoints().length, 0,
    49       "No breakpoints currently shown in the editor.");
    51     ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
    52       "_getAdded('foo', 3) returns falsey.");
    53     ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
    54       "_getRemoving('bar', 3) returns falsey.");
    56     let breakpointsParent = gSources.widget._parent;
    57     let breakpointsList = gSources.widget._list;
    59     is(breakpointsParent.childNodes.length, 1, // one sources list
    60       "Found junk in the breakpoints container.");
    61     is(breakpointsList.childNodes.length, 1, // one sources group
    62       "Found junk in the breakpoints container.");
    63     is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
    64       "No breakpoints should be visible at this point.");
    66     addBreakpoints(true).then(() => {
    67       is(breakpointsAdded, 3,
    68         "Should have added 3 breakpoints so far.");
    69       is(breakpointsDisabled, 0,
    70         "Shouldn't have disabled anything so far.");
    71       is(breakpointsRemoved, 0,
    72         "Shouldn't have removed anything so far.");
    74       is(breakpointsParent.childNodes.length, 1, // one sources list
    75         "Found junk in the breakpoints container.");
    76       is(breakpointsList.childNodes.length, 1, // one sources group
    77         "Found junk in the breakpoints container.");
    78       is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 3,
    79         "3 breakpoints should be visible at this point.");
    81       disableBreakpoints().then(() => {
    82         is(breakpointsAdded, 3,
    83           "Should still have 3 breakpoints added so far.");
    84         is(breakpointsDisabled, 3,
    85           "Should have 3 disabled breakpoints.");
    86         is(breakpointsRemoved, 0,
    87           "Shouldn't have removed anything so far.");
    89         is(breakpointsParent.childNodes.length, 1, // one sources list
    90           "Found junk in the breakpoints container.");
    91         is(breakpointsList.childNodes.length, 1, // one sources group
    92           "Found junk in the breakpoints container.");
    93         is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
    94           "Should have the same number of breakpoints in the pane.");
    95         is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsDisabled,
    96           "Should have the same number of disabled breakpoints.");
    98         addBreakpoints().then(() => {
    99           is(breakpointsAdded, 3,
   100             "Should still have only 3 breakpoints added so far.");
   101           is(breakpointsDisabled, 3,
   102             "Should still have 3 disabled breakpoints.");
   103           is(breakpointsRemoved, 0,
   104             "Shouldn't have removed anything so far.");
   106           is(breakpointsParent.childNodes.length, 1, // one sources list
   107             "Found junk in the breakpoints container.");
   108           is(breakpointsList.childNodes.length, 1, // one sources group
   109             "Found junk in the breakpoints container.");
   110           is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
   111             "Since half of the breakpoints already existed, but disabled, " +
   112             "only half of the added breakpoints are actually in the pane.");
   114           removeBreakpoints().then(() => {
   115             is(breakpointsRemoved, 3,
   116               "Should have 3 removed breakpoints.");
   118             is(breakpointsParent.childNodes.length, 1, // one sources list
   119                "Found junk in the breakpoints container.");
   120             is(breakpointsList.childNodes.length, 1, // one sources group
   121                "Found junk in the breakpoints container.");
   122             is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0,
   123                "No breakpoints should be visible at this point.");
   125             waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
   126               finalCheck();
   127               closeDebuggerAndFinish(gPanel);
   128             });
   130             gDebugger.gThreadClient.resume();
   131           });
   132         });
   133       });
   134     });
   136     function addBreakpoints(aIncrementFlag) {
   137       let deferred = promise.defer();
   139       gPanel.addBreakpoint({ url: gSources.selectedValue, line: 6 }).then(aClient => {
   140         onBreakpointAdd(aClient, {
   141           increment: aIncrementFlag,
   142           line: 6,
   143           text: "eval(\"debugger;\");"
   144         });
   146         gPanel.addBreakpoint({ url: gSources.selectedValue, line: 7 }).then(aClient => {
   147           onBreakpointAdd(aClient, {
   148             increment: aIncrementFlag,
   149             line: 7,
   150             text: "function foo() {}"
   151           });
   153           gPanel.addBreakpoint({ url: gSources.selectedValue, line: 9 }).then(aClient => {
   154             onBreakpointAdd(aClient, {
   155               increment: aIncrementFlag,
   156               line: 9,
   157               text: "foo();"
   158             });
   160             deferred.resolve();
   161           });
   162         });
   163       });
   165       return deferred.promise;
   166     }
   168     function disableBreakpoints() {
   169       let deferred = promise.defer();
   171       let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
   172       info("Nodes to disable: " + breakpointsAdded.length);
   174       is(nodes.length, breakpointsAdded,
   175         "The number of nodes to disable is incorrect.");
   177       for (let node of nodes) {
   178         info("Disabling breakpoint: " + node.id);
   180         let sourceItem = gSources.getItemForElement(node);
   181         let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
   182         info("Found data: " + breakpointItem.attachment.toSource());
   184         gSources.disableBreakpoint(breakpointItem.attachment).then(() => {
   185           if (++breakpointsDisabled == breakpointsAdded) {
   186             deferred.resolve();
   187           }
   188         });
   189       }
   191       return deferred.promise;
   192     }
   194     function removeBreakpoints() {
   195       let deferred = promise.defer();
   197       let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint");
   198       info("Nodes to remove: " + breakpointsAdded.length);
   200       is(nodes.length, breakpointsAdded,
   201         "The number of nodes to remove is incorrect.");
   203       for (let node of nodes) {
   204         info("Removing breakpoint: " + node.id);
   206         let sourceItem = gSources.getItemForElement(node);
   207         let breakpointItem = gSources.getItemForElement.call(sourceItem, node);
   208         info("Found data: " + breakpointItem.attachment.toSource());
   210         gPanel.removeBreakpoint(breakpointItem.attachment).then(() => {
   211           if (++breakpointsRemoved == breakpointsAdded) {
   212             deferred.resolve();
   213           }
   214         });
   215       }
   217       return deferred.promise;
   218     }
   220     function onBreakpointAdd(aBreakpointClient, aTestData) {
   221       if (aTestData.increment) {
   222         breakpointsAdded++;
   223       }
   225       is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded,
   226         aTestData.increment
   227           ? "Should have added a breakpoint in the pane."
   228           : "Should have the same number of breakpoints in the pane.");
   230       let identifier = gBreakpoints.getIdentifier(aBreakpointClient.location);
   231       let node = gDebugger.document.getElementById("breakpoint-" + identifier);
   232       let line = node.getElementsByClassName("dbg-breakpoint-line")[0];
   233       let text = node.getElementsByClassName("dbg-breakpoint-text")[0];
   234       let check = node.querySelector("checkbox");
   236       ok(node,
   237         "Breakpoint element found successfully.");
   238       is(line.getAttribute("value"), aTestData.line,
   239         "The expected information wasn't found in the breakpoint element.");
   240       is(text.getAttribute("value"), aTestData.text,
   241         "The expected line text wasn't found in the breakpoint element.");
   242       is(check.getAttribute("checked"), "true",
   243         "The breakpoint enable checkbox is checked as expected.");
   244     }
   245   }
   247   function finalCheck() {
   248     is(gBreakpointsAdded.size, 0,
   249       "No breakpoints currently added.");
   250     is(gBreakpointsRemoving.size, 0,
   251       "No breakpoints currently being removed.");
   252     is(gEditor.getBreakpoints().length, 0,
   253       "No breakpoints currently shown in the editor.");
   254   }
   255 }

mercurial