toolkit/devtools/server/tests/unit/test_breakpoint-17.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_breakpoint-17.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     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 + * Test that when we add 2 breakpoints to the same line at different columns and
     1.9 + * then remove one of them, we don't remove them both.
    1.10 + */
    1.11 +
    1.12 +var gDebuggee;
    1.13 +var gClient;
    1.14 +var gThreadClient;
    1.15 +
    1.16 +function run_test()
    1.17 +{
    1.18 +  initTestDebuggerServer();
    1.19 +  gDebuggee = addTestGlobal("test-breakpoints");
    1.20 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.21 +  gClient.connect(function() {
    1.22 +    attachTestTabAndResume(gClient, "test-breakpoints", function(aResponse, aTabClient, aThreadClient) {
    1.23 +      gThreadClient = aThreadClient;
    1.24 +      test_breakpoints_columns();
    1.25 +    });
    1.26 +  });
    1.27 +  do_test_pending();
    1.28 +}
    1.29 +
    1.30 +const URL = "http://example.com/benderbendingrodriguez.js";
    1.31 +
    1.32 +const code =
    1.33 +"(" + function (global) {
    1.34 +  global.foo = function () {
    1.35 +    Math.abs(-1); Math.log(0.5);
    1.36 +    debugger;
    1.37 +  };
    1.38 +  debugger;
    1.39 +} + "(this))";
    1.40 +
    1.41 +const firstLocation = {
    1.42 +  url: URL,
    1.43 +  line: 3,
    1.44 +  column: 4
    1.45 +};
    1.46 +
    1.47 +const secondLocation = {
    1.48 +  url: URL,
    1.49 +  line: 3,
    1.50 +  column: 18
    1.51 +};
    1.52 +
    1.53 +function test_breakpoints_columns() {
    1.54 +  gClient.addOneTimeListener("paused", set_breakpoints);
    1.55 +
    1.56 +  Components.utils.evalInSandbox(code, gDebuggee, "1.8", URL, 1);
    1.57 +}
    1.58 +
    1.59 +function set_breakpoints() {
    1.60 +  let first, second;
    1.61 +
    1.62 +  gThreadClient.setBreakpoint(firstLocation, function ({ error, actualLocation },
    1.63 +                                                       aBreakpointClient) {
    1.64 +    do_check_true(!error, "Should not get an error setting the breakpoint");
    1.65 +    do_check_true(!actualLocation, "Should not get an actualLocation");
    1.66 +    first = aBreakpointClient;
    1.67 +
    1.68 +    gThreadClient.setBreakpoint(secondLocation, function ({ error, actualLocation },
    1.69 +                                                          aBreakpointClient) {
    1.70 +      do_check_true(!error, "Should not get an error setting the breakpoint");
    1.71 +      do_check_true(!actualLocation, "Should not get an actualLocation");
    1.72 +      second = aBreakpointClient;
    1.73 +
    1.74 +      test_different_actors(first, second);
    1.75 +    });
    1.76 +  });
    1.77 +}
    1.78 +
    1.79 +function test_different_actors(aFirst, aSecond) {
    1.80 +  do_check_neq(aFirst.actor, aSecond.actor,
    1.81 +               "Each breakpoint should have a different actor");
    1.82 +  test_remove_one(aFirst, aSecond);
    1.83 +}
    1.84 +
    1.85 +function test_remove_one(aFirst, aSecond) {
    1.86 +  aFirst.remove(function ({error}) {
    1.87 +    do_check_true(!error, "Should not get an error removing a breakpoint");
    1.88 +
    1.89 +    let hitSecond;
    1.90 +    gClient.addListener("paused", function _onPaused(aEvent, {why, frame}) {
    1.91 +      if (why.type == "breakpoint") {
    1.92 +        hitSecond = true;
    1.93 +        do_check_eq(why.actors.length, 1,
    1.94 +                    "Should only be paused because of one breakpoint actor");
    1.95 +        do_check_eq(why.actors[0], aSecond.actor,
    1.96 +                    "Should be paused because of the correct breakpoint actor");
    1.97 +        do_check_eq(frame.where.line, secondLocation.line,
    1.98 +                    "Should be at the right line");
    1.99 +        do_check_eq(frame.where.column, secondLocation.column,
   1.100 +                    "Should be at the right column");
   1.101 +        gThreadClient.resume();
   1.102 +        return;
   1.103 +      }
   1.104 +
   1.105 +      if (why.type == "debuggerStatement") {
   1.106 +        gClient.removeListener("paused", _onPaused);
   1.107 +        do_check_true(hitSecond,
   1.108 +                      "We should still hit `second`, but not `first`.");
   1.109 +
   1.110 +        finishClient(gClient);
   1.111 +        return;
   1.112 +      }
   1.113 +
   1.114 +      do_check_true(false, "Should never get here");
   1.115 +    });
   1.116 +
   1.117 +    gThreadClient.resume(() => gDebuggee.foo());
   1.118 +  });
   1.119 +}

mercurial