browser/devtools/debugger/test/browser_dbg_breakpoints-editor.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 723069: Test the debugger breakpoint API and connection to the
     6  * source editor.
     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   function performTest() {
    31     is(gDebugger.gThreadClient.state, "paused",
    32       "Should only be getting stack frames while paused.");
    33     is(gSources.itemCount, 2,
    34       "Found the expected number of sources.");
    35     is(gEditor.getText().indexOf("debugger"), 172,
    36       "The correct source was loaded initially.");
    37     is(gSources.selectedValue, gSources.values[1],
    38       "The correct source is selected.");
    40     is(gBreakpointsAdded.size, 0,
    41       "No breakpoints currently added.");
    42     is(gBreakpointsRemoving.size, 0,
    43       "No breakpoints currently being removed.");
    44     is(gEditor.getBreakpoints().length, 0,
    45       "No breakpoints currently shown in the editor.");
    47     ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
    48       "_getAdded('foo', 3) returns falsey.");
    49     ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
    50       "_getRemoving('bar', 3) returns falsey.");
    52     is(gSources.values[1], gSources.selectedValue,
    53       "The second source should be currently selected.");
    55     info("Add the first breakpoint.");
    56     let location = { url: gSources.selectedValue, line: 6 };
    57     gEditor.once("breakpointAdded", onEditorBreakpointAddFirst);
    58     gPanel.addBreakpoint(location).then(onBreakpointAddFirst);
    59   }
    61   let breakpointsAdded = 0;
    62   let breakpointsRemoved = 0;
    63   let editorBreakpointChanges = 0;
    65   function onEditorBreakpointAddFirst(aEvent, aLine) {
    66     editorBreakpointChanges++;
    68     ok(aEvent,
    69       "breakpoint1 added to the editor.");
    70     is(aLine, 5,
    71       "Editor breakpoint line is correct.");
    73     is(gEditor.getBreakpoints().length, 1,
    74       "editor.getBreakpoints().length is correct.");
    75   }
    77   function onBreakpointAddFirst(aBreakpointClient) {
    78     breakpointsAdded++;
    80     ok(aBreakpointClient,
    81       "breakpoint1 added, client received.");
    82     is(aBreakpointClient.location.url, gSources.selectedValue,
    83       "breakpoint1 client url is correct.");
    84     is(aBreakpointClient.location.line, 6,
    85       "breakpoint1 client line is correct.");
    87     ok(gBreakpoints._getAdded(aBreakpointClient.location),
    88       "breakpoint1 client found in the list of added breakpoints.");
    89     ok(!gBreakpoints._getRemoving(aBreakpointClient.location),
    90       "breakpoint1 client found in the list of removing breakpoints.");
    92     is(gBreakpointsAdded.size, 1,
    93       "The list of added breakpoints holds only one breakpoint.");
    94     is(gBreakpointsRemoving.size, 0,
    95       "The list of removing breakpoints holds no breakpoint.");
    97     gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => {
    98       is(aClient, aBreakpointClient,
    99         "_getAdded() returns the correct breakpoint.");
   100     });
   102     is(gSources.values[1], gSources.selectedValue,
   103       "The second source should be currently selected.");
   105     info("Remove the first breakpoint.");
   106     gEditor.once("breakpointRemoved", onEditorBreakpointRemoveFirst);
   107     gPanel.removeBreakpoint(aBreakpointClient.location).then(onBreakpointRemoveFirst);
   108   }
   110   function onEditorBreakpointRemoveFirst(aEvent, aLine) {
   111     editorBreakpointChanges++;
   113     ok(aEvent,
   114       "breakpoint1 removed from the editor.");
   115     is(aLine, 5,
   116       "Editor breakpoint line is correct.");
   118     is(gEditor.getBreakpoints().length, 0,
   119       "editor.getBreakpoints().length is correct.");
   120   }
   122   function onBreakpointRemoveFirst(aLocation) {
   123     breakpointsRemoved++;
   125     ok(aLocation,
   126       "breakpoint1 removed");
   127     is(aLocation.url, gSources.selectedValue,
   128       "breakpoint1 removal url is correct.");
   129     is(aLocation.line, 6,
   130       "breakpoint1 removal line is correct.");
   132     testBreakpointAddBackground();
   133   }
   135   function testBreakpointAddBackground() {
   136     is(gBreakpointsAdded.size, 0,
   137       "No breakpoints currently added.");
   138     is(gBreakpointsRemoving.size, 0,
   139       "No breakpoints currently being removed.");
   140     is(gEditor.getBreakpoints().length, 0,
   141       "No breakpoints currently shown in the editor.");
   143     ok(!gBreakpoints._getAdded({ url: gSources.selectedValue, line: 6 }),
   144       "_getAdded('gSources.selectedValue', 6) returns falsey.");
   145     ok(!gBreakpoints._getRemoving({ url: gSources.selectedValue, line: 6 }),
   146       "_getRemoving('gSources.selectedValue', 6) returns falsey.");
   148     is(gSources.values[1], gSources.selectedValue,
   149       "The second source should be currently selected.");
   151     info("Add a breakpoint to the first source, which is not selected.");
   152     let location = { url: gSources.values[0], line: 5 };
   153     let options = { noEditorUpdate: true };
   154     gEditor.on("breakpointAdded", onEditorBreakpointAddBackgroundTrap);
   155     gPanel.addBreakpoint(location, options).then(onBreakpointAddBackground);
   156   }
   158   function onEditorBreakpointAddBackgroundTrap() {
   159     // Trap listener: no breakpoint must be added to the editor when a
   160     // breakpoint is added to a source that is not currently selected.
   161     editorBreakpointChanges++;
   162     ok(false, "breakpoint2 must not be added to the editor.");
   163   }
   165   function onBreakpointAddBackground(aBreakpointClient, aResponseError) {
   166     breakpointsAdded++;
   168     ok(aBreakpointClient,
   169       "breakpoint2 added, client received");
   170     is(aBreakpointClient.location.url, gSources.values[0],
   171       "breakpoint2 client url is correct.");
   172     is(aBreakpointClient.location.line, 5,
   173       "breakpoint2 client line is correct.");
   175     ok(gBreakpoints._getAdded(aBreakpointClient.location),
   176       "breakpoint2 client found in the list of added breakpoints.");
   177     ok(!gBreakpoints._getRemoving(aBreakpointClient.location),
   178       "breakpoint2 client found in the list of removing breakpoints.");
   180     is(gBreakpointsAdded.size, 1,
   181       "The list of added breakpoints holds only one breakpoint.");
   182     is(gBreakpointsRemoving.size, 0,
   183       "The list of removing breakpoints holds no breakpoint.");
   185     gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => {
   186       is(aClient, aBreakpointClient,
   187         "_getAdded() returns the correct breakpoint.");
   188     });
   190     is(gSources.values[1], gSources.selectedValue,
   191       "The second source should be currently selected.");
   193     // Remove the trap listener.
   194     gEditor.off("breakpointAdded", onEditorBreakpointAddBackgroundTrap);
   196     info("Switch to the first source, which is not yet selected");
   197     gEditor.once("breakpointAdded", onEditorBreakpointAddSwitch);
   198     gEditor.once("change", onEditorTextChanged);
   199     gSources.selectedIndex = 0;
   200   }
   202   function onEditorBreakpointAddSwitch(aEvent, aLine) {
   203     editorBreakpointChanges++;
   205     ok(aEvent,
   206       "breakpoint2 added to the editor.");
   207     is(aLine, 4,
   208       "Editor breakpoint line is correct.");
   210     is(gEditor.getBreakpoints().length, 1,
   211       "editor.getBreakpoints().length is correct");
   212   }
   214   function onEditorTextChanged() {
   215     // Wait for the actual text to be shown.
   216     if (gEditor.getText() == gDebugger.L10N.getStr("loadingText"))
   217       return void gEditor.once("change", onEditorTextChanged);
   219     is(gEditor.getText().indexOf("debugger"), -1,
   220       "The second source is no longer displayed.");
   221     is(gEditor.getText().indexOf("firstCall"), 118,
   222       "The first source is displayed.");
   224     is(gSources.values[0], gSources.selectedValue,
   225       "The first source should be currently selected.");
   227     let window = gEditor.container.contentWindow;
   228     executeSoon(() => window.mozRequestAnimationFrame(onReadyForClick));
   229   }
   231   function onReadyForClick() {
   232     info("Remove the second breakpoint using the mouse.");
   233     gEditor.once("breakpointRemoved", onEditorBreakpointRemoveSecond);
   235     let iframe = gEditor.container;
   236     let testWin = iframe.ownerDocument.defaultView;
   238     // Flush the layout for the iframe.
   239     info("rect " + iframe.contentDocument.documentElement.getBoundingClientRect());
   241     let utils = testWin
   242       .QueryInterface(Ci.nsIInterfaceRequestor)
   243       .getInterface(Ci.nsIDOMWindowUtils);
   245     let coords = gEditor.getCoordsFromPosition({ line: 4, ch: 0 });
   246     let rect = iframe.getBoundingClientRect();
   247     let left = rect.left + 10;
   248     let top = rect.top + coords.top + 4;
   249     utils.sendMouseEventToWindow("mousedown", left, top, 0, 1, 0, false, 0, 0);
   250     utils.sendMouseEventToWindow("mouseup", left, top, 0, 1, 0, false, 0, 0);
   251   }
   253   function onEditorBreakpointRemoveSecond(aEvent, aLine) {
   254     editorBreakpointChanges++;
   256     ok(aEvent,
   257       "breakpoint2 removed from the editor.");
   258     is(aLine, 4,
   259       "Editor breakpoint line is correct.");
   261     is(gEditor.getBreakpoints().length, 0,
   262       "editor.getBreakpoints().length is correct.");
   264     waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
   265       finalCheck();
   266       closeDebuggerAndFinish(gPanel);
   267     });
   269     gDebugger.gThreadClient.resume();
   270   }
   272   function finalCheck() {
   273     is(gBreakpointsAdded.size, 0,
   274       "No breakpoints currently added.");
   275     is(gBreakpointsRemoving.size, 0,
   276       "No breakpoints currently being removed.");
   277     is(gEditor.getBreakpoints().length, 0,
   278       "No breakpoints currently shown in the editor.");
   280     ok(!gBreakpoints._getAdded({ url: gSources.values[0], line: 5 }),
   281       "_getAdded('gSources.values[0]', 5) returns falsey.");
   282     ok(!gBreakpoints._getRemoving({ url: gSources.values[0], line: 5 }),
   283       "_getRemoving('gSources.values[0]', 5) returns falsey.");
   285     ok(!gBreakpoints._getAdded({ url: gSources.values[1], line: 6 }),
   286       "_getAdded('gSources.values[1]', 6) returns falsey.");
   287     ok(!gBreakpoints._getRemoving({ url: gSources.values[1], line: 6 }),
   288       "_getRemoving('gSources.values[1]', 6) returns falsey.");
   290     ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
   291       "_getAdded('foo', 3) returns falsey.");
   292     ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
   293       "_getRemoving('bar', 3) returns falsey.");
   295     is(breakpointsAdded, 2,
   296       "Correct number of breakpoints have been added.");
   297     is(breakpointsRemoved, 1,
   298       "Correct number of breakpoints have been removed.");
   299     is(editorBreakpointChanges, 4,
   300       "Correct number of editor breakpoint changes.");
   301   }
   302 }

mercurial