toolkit/devtools/server/tests/unit/test_breakpoint-17.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  * Test that when we add 2 breakpoints to the same line at different columns and
     6  * then remove one of them, we don't remove them both.
     7  */
     9 var gDebuggee;
    10 var gClient;
    11 var gThreadClient;
    13 function run_test()
    14 {
    15   initTestDebuggerServer();
    16   gDebuggee = addTestGlobal("test-breakpoints");
    17   gClient = new DebuggerClient(DebuggerServer.connectPipe());
    18   gClient.connect(function() {
    19     attachTestTabAndResume(gClient, "test-breakpoints", function(aResponse, aTabClient, aThreadClient) {
    20       gThreadClient = aThreadClient;
    21       test_breakpoints_columns();
    22     });
    23   });
    24   do_test_pending();
    25 }
    27 const URL = "http://example.com/benderbendingrodriguez.js";
    29 const code =
    30 "(" + function (global) {
    31   global.foo = function () {
    32     Math.abs(-1); Math.log(0.5);
    33     debugger;
    34   };
    35   debugger;
    36 } + "(this))";
    38 const firstLocation = {
    39   url: URL,
    40   line: 3,
    41   column: 4
    42 };
    44 const secondLocation = {
    45   url: URL,
    46   line: 3,
    47   column: 18
    48 };
    50 function test_breakpoints_columns() {
    51   gClient.addOneTimeListener("paused", set_breakpoints);
    53   Components.utils.evalInSandbox(code, gDebuggee, "1.8", URL, 1);
    54 }
    56 function set_breakpoints() {
    57   let first, second;
    59   gThreadClient.setBreakpoint(firstLocation, function ({ error, actualLocation },
    60                                                        aBreakpointClient) {
    61     do_check_true(!error, "Should not get an error setting the breakpoint");
    62     do_check_true(!actualLocation, "Should not get an actualLocation");
    63     first = aBreakpointClient;
    65     gThreadClient.setBreakpoint(secondLocation, function ({ error, actualLocation },
    66                                                           aBreakpointClient) {
    67       do_check_true(!error, "Should not get an error setting the breakpoint");
    68       do_check_true(!actualLocation, "Should not get an actualLocation");
    69       second = aBreakpointClient;
    71       test_different_actors(first, second);
    72     });
    73   });
    74 }
    76 function test_different_actors(aFirst, aSecond) {
    77   do_check_neq(aFirst.actor, aSecond.actor,
    78                "Each breakpoint should have a different actor");
    79   test_remove_one(aFirst, aSecond);
    80 }
    82 function test_remove_one(aFirst, aSecond) {
    83   aFirst.remove(function ({error}) {
    84     do_check_true(!error, "Should not get an error removing a breakpoint");
    86     let hitSecond;
    87     gClient.addListener("paused", function _onPaused(aEvent, {why, frame}) {
    88       if (why.type == "breakpoint") {
    89         hitSecond = true;
    90         do_check_eq(why.actors.length, 1,
    91                     "Should only be paused because of one breakpoint actor");
    92         do_check_eq(why.actors[0], aSecond.actor,
    93                     "Should be paused because of the correct breakpoint actor");
    94         do_check_eq(frame.where.line, secondLocation.line,
    95                     "Should be at the right line");
    96         do_check_eq(frame.where.column, secondLocation.column,
    97                     "Should be at the right column");
    98         gThreadClient.resume();
    99         return;
   100       }
   102       if (why.type == "debuggerStatement") {
   103         gClient.removeListener("paused", _onPaused);
   104         do_check_true(hitSecond,
   105                       "We should still hit `second`, but not `first`.");
   107         finishClient(gClient);
   108         return;
   109       }
   111       do_check_true(false, "Should never get here");
   112     });
   114     gThreadClient.resume(() => gDebuggee.foo());
   115   });
   116 }

mercurial