summaryrefslogtreecommitdiff
path: root/browser/devtools/debugger/test/browser_dbg_debuggerstatement.js
blob: de18429f086b64102cbfcc9b82ae30955238e05a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* vim:set ts=2 sw=2 sts=2 et: */
/*
 * Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Tests the behavior of the debugger statement.

var gClient = null;
var gTab = null;
const DEBUGGER_TAB_URL = EXAMPLE_URL + "browser_dbg_debuggerstatement.html";

function test()
{
  let transport = DebuggerServer.connectPipe();
  gClient = new DebuggerClient(transport);
  gClient.connect(function(aType, aTraits) {
    gTab = addTab(DEBUGGER_TAB_URL, function() {
      attach_tab_actor_for_url(gClient, DEBUGGER_TAB_URL, function(actor, response) {
        test_early_debugger_statement(response);
      });
    });
  });
}

function test_early_debugger_statement(aActor)
{
  let paused = function(aEvent, aPacket) {
    ok(false, "Pause shouldn't be called before we've attached!\n");
    finish_test();
  };
  gClient.addListener("paused", paused);
  // This should continue without nesting an event loop and calling
  // the onPaused hook, because we haven't attached yet.
  gTab.linkedBrowser.contentWindow.wrappedJSObject.runDebuggerStatement();

  gClient.removeListener("paused", paused);

  // Now attach and resume...
  gClient.request({ to: aActor.threadActor, type: "attach" }, function(aResponse) {
    gClient.request({ to: aActor.threadActor, type: "resume" }, function(aResponse) {
      test_debugger_statement(aActor);
    });
  });
}

function test_debugger_statement(aActor)
{
  var stopped = false;
  gClient.addListener("paused", function(aEvent, aPacket) {
    stopped = true;

    gClient.request({ to: aActor.threadActor, type: "resume" }, function() {
      finish_test();
    });
  });

  // Reach around the debugging protocol and execute the debugger
  // statement.
  gTab.linkedBrowser.contentWindow.wrappedJSObject.runDebuggerStatement();
  ok(stopped, "Should trigger the pause handler on a debugger statement.");
}

function finish_test()
{
  removeTab(gTab);
  gClient.close(function() {
    finish();
  });
}