browser/devtools/debugger/test/browser_dbg_conditional-breakpoints-01.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 740825: Test the debugger conditional breakpoints.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
    10 function test() {
    11   // Linux debug test slaves are a bit slow at this test sometimes.
    12   requestLongerTimeout(2);
    14   let gTab, gDebuggee, gPanel, gDebugger;
    15   let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
    17   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    18     gTab = aTab;
    19     gDebuggee = aDebuggee;
    20     gPanel = aPanel;
    21     gDebugger = gPanel.panelWin;
    22     gEditor = gDebugger.DebuggerView.editor;
    23     gSources = gDebugger.DebuggerView.Sources;
    24     gBreakpoints = gDebugger.DebuggerController.Breakpoints;
    25     gBreakpointsAdded = gBreakpoints._added;
    26     gBreakpointsRemoving = gBreakpoints._removing;
    28     // This test forces conditional breakpoints to be evaluated on the
    29     // client-side
    30     var client = gPanel.target.client;
    31     client.mainRoot.traits.conditionalBreakpoints = false;
    33     waitForSourceAndCaretAndScopes(gPanel, ".html", 17)
    34       .then(() => addBreakpoints())
    35       .then(() => initialChecks())
    36       .then(() => resumeAndTestBreakpoint(20))
    37       .then(() => resumeAndTestBreakpoint(21))
    38       .then(() => resumeAndTestBreakpoint(22))
    39       .then(() => resumeAndTestBreakpoint(23))
    40       .then(() => resumeAndTestBreakpoint(24))
    41       .then(() => resumeAndTestBreakpoint(25))
    42       .then(() => resumeAndTestBreakpoint(27))
    43       .then(() => resumeAndTestBreakpoint(28))
    44       .then(() => {
    45         // Note: the breakpoint on line 29 should not be hit since the
    46         // conditional expression evaluates to undefined. It used to
    47         // be on line 30, but it can't be the last breakpoint because
    48         // there is a race condition (the "frames cleared" event might
    49         // fire from the conditional expression evaluation if it's too
    50         // slow, which is what we wait for to reload the page)
    51         return resumeAndTestBreakpoint(30);
    52       })
    53       .then(() => resumeAndTestNoBreakpoint())
    54       .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN, 13))
    55       .then(() => testAfterReload())
    56       .then(() => closeDebuggerAndFinish(gPanel))
    57       .then(null, aError => {
    58         ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    59       });
    61     gDebuggee.ermahgerd();
    62   });
    64   function addBreakpoints() {
    65     return promise.resolve(null)
    66       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 18 }))
    67       .then(aClient => aClient.conditionalExpression = "undefined")
    68       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 19 }))
    69       .then(aClient => aClient.conditionalExpression = "null")
    70       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 20 }))
    71       .then(aClient => aClient.conditionalExpression = "42")
    72       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 21 }))
    73       .then(aClient => aClient.conditionalExpression = "true")
    74       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 22 }))
    75       .then(aClient => aClient.conditionalExpression = "'nasu'")
    76       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 23 }))
    77       .then(aClient => aClient.conditionalExpression = "/regexp/")
    78       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 24 }))
    79       .then(aClient => aClient.conditionalExpression = "({})")
    80       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 25 }))
    81       .then(aClient => aClient.conditionalExpression = "(function() {})")
    82       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 26 }))
    83       .then(aClient => aClient.conditionalExpression = "(function() { return false; })()")
    84       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 27 }))
    85       .then(aClient => aClient.conditionalExpression = "a")
    86       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 28 }))
    87       .then(aClient => aClient.conditionalExpression = "a !== undefined")
    88       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 29 }))
    89       .then(aClient => aClient.conditionalExpression = "b")
    90       .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, line: 30 }))
    91       .then(aClient => aClient.conditionalExpression = "a !== null");
    92   }
    94   function initialChecks() {
    95     is(gDebugger.gThreadClient.state, "paused",
    96       "Should only be getting stack frames while paused.");
    97     is(gSources.itemCount, 1,
    98       "Found the expected number of sources.");
    99     is(gEditor.getText().indexOf("ermahgerd"), 253,
   100       "The correct source was loaded initially.");
   101     is(gSources.selectedValue, gSources.values[0],
   102       "The correct source is selected.");
   104     is(gBreakpointsAdded.size, 13,
   105       "13 breakpoints currently added.");
   106     is(gBreakpointsRemoving.size, 0,
   107       "No breakpoints currently being removed.");
   108     is(gEditor.getBreakpoints().length, 13,
   109       "13 breakpoints currently shown in the editor.");
   111     ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
   112       "_getAdded('foo', 3) returns falsey.");
   113     ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
   114       "_getRemoving('bar', 3) returns falsey.");
   115   }
   117   function resumeAndTestBreakpoint(aLine) {
   118     let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine));
   120     EventUtils.sendMouseEvent({ type: "mousedown" },
   121       gDebugger.document.getElementById("resume"),
   122       gDebugger);
   124     return finished;
   125   }
   127   function resumeAndTestNoBreakpoint() {
   128     let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
   129       is(gSources.itemCount, 1,
   130         "Found the expected number of sources.");
   131       is(gEditor.getText().indexOf("ermahgerd"), 253,
   132         "The correct source was loaded initially.");
   133       is(gSources.selectedValue, gSources.values[0],
   134         "The correct source is selected.");
   136       ok(gSources.selectedItem,
   137         "There should be a selected source in the sources pane.")
   138       ok(!gSources._selectedBreakpointItem,
   139         "There should be no selected breakpoint in the sources pane.")
   140       is(gSources._conditionalPopupVisible, false,
   141         "The breakpoint conditional expression popup should not be shown.");
   143       is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0,
   144         "There should be no visible stackframes.");
   145       is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 13,
   146         "There should be thirteen visible breakpoints.");
   147     });
   149     gDebugger.gThreadClient.resume();
   151     return finished;
   152   }
   154   function testBreakpoint(aLine, aHighlightBreakpoint) {
   155     // Highlight the breakpoint only if required.
   156     if (aHighlightBreakpoint) {
   157       let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine));
   158       gSources.highlightBreakpoint({ url: gSources.selectedValue, line: aLine });
   159       return finished;
   160     }
   162     let selectedUrl = gSources.selectedValue;
   163     let selectedBreakpoint = gSources._selectedBreakpointItem;
   165     ok(selectedUrl,
   166       "There should be a selected item in the sources pane.");
   167     ok(selectedBreakpoint,
   168       "There should be a selected breakpoint in the sources pane.");
   170     is(selectedBreakpoint.attachment.url, selectedUrl,
   171       "The breakpoint on line " + aLine + " wasn't added on the correct source.");
   172     is(selectedBreakpoint.attachment.line, aLine,
   173       "The breakpoint on line " + aLine + " wasn't found.");
   174     is(!!selectedBreakpoint.attachment.disabled, false,
   175       "The breakpoint on line " + aLine + " should be enabled.");
   176     is(!!selectedBreakpoint.attachment.openPopup, false,
   177       "The breakpoint on line " + aLine + " should not have opened a popup.");
   178     is(gSources._conditionalPopupVisible, false,
   179       "The breakpoint conditional expression popup should not have been shown.");
   181     return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => {
   182       is(aBreakpointClient.location.url, selectedUrl,
   183         "The breakpoint's client url is correct");
   184       is(aBreakpointClient.location.line, aLine,
   185         "The breakpoint's client line is correct");
   186       isnot(aBreakpointClient.conditionalExpression, undefined,
   187         "The breakpoint on line " + aLine + " should have a conditional expression.");
   189       ok(isCaretPos(gPanel, aLine),
   190         "The editor caret position is not properly set.");
   191     });
   192   }
   194   function testAfterReload() {
   195     let selectedUrl = gSources.selectedValue;
   196     let selectedBreakpoint = gSources._selectedBreakpointItem;
   198     ok(selectedUrl,
   199       "There should be a selected item in the sources pane after reload.");
   200     ok(!selectedBreakpoint,
   201       "There should be no selected breakpoint in the sources pane after reload.");
   203     return promise.resolve(null)
   204       .then(() => testBreakpoint(18, true))
   205       .then(() => testBreakpoint(19, true))
   206       .then(() => testBreakpoint(20, true))
   207       .then(() => testBreakpoint(21, true))
   208       .then(() => testBreakpoint(22, true))
   209       .then(() => testBreakpoint(23, true))
   210       .then(() => testBreakpoint(24, true))
   211       .then(() => testBreakpoint(25, true))
   212       .then(() => testBreakpoint(26, true))
   213       .then(() => testBreakpoint(27, true))
   214       .then(() => testBreakpoint(28, true))
   215       .then(() => testBreakpoint(29, true))
   216       .then(() => testBreakpoint(30, true))
   217       .then(() => {
   218         is(gSources.itemCount, 1,
   219           "Found the expected number of sources.");
   220         is(gEditor.getText().indexOf("ermahgerd"), 253,
   221           "The correct source was loaded again.");
   222         is(gSources.selectedValue, gSources.values[0],
   223           "The correct source is selected.");
   225         ok(gSources.selectedItem,
   226           "There should be a selected source in the sources pane.")
   227         ok(gSources._selectedBreakpointItem,
   228           "There should be a selected breakpoint in the sources pane.")
   229         is(gSources._conditionalPopupVisible, false,
   230           "The breakpoint conditional expression popup should not be shown.");
   231       });
   232   }
   233 }

mercurial