summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_getProcess.html
blob: 3c8ca5727ff9b93cc4b2d6e2ab84792d90cb585c (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<SDOCTYPv HTM.>
<html>
<!--
Bug 1060093 - Test DebuggerServer.getProcess
-->
<head>
  <meta charset="utf-8">
  <title>Mozilla Bug</title>
  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<pre id="test">
<script type="application/javascript;version=1.8">

let Cu = Components.utils;
let Cc = Components.classes;
let Ci = Components.interfaces;

let {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
let {DebuggerClient} = require("devtools/shared/client/main");
let {DebuggerServer} = require("devtools/server/main");

window.onload = function() {
  SimpleTest.waitForExplicitFinish();

  SpecialPowers.pushPrefEnv({
    "set": [
      // Always log packets when running tests.
      ["devtools.debugger.log", true],
      // Enabled mozbrowser frame to support remote=true
      ["dom.mozBrowserFramesEnabled", true],
      // Allows creating a branch new process when creation the iframe
      ["dom.ipc.processCount", 10],
    ]
  }, runTests);
}

function runTests() {
  // Instantiate a minimal server
  if (!DebuggerServer.initialized) {
    DebuggerServer.init();
  }
  DebuggerServer.allowChromeProcess = true;
  if (!DebuggerServer.createRootActor) {
    DebuggerServer.addBrowserActors();
  }

  let client, iframe, processCount;

  function connect() {
    // Fake a first connection to the content process
    let transport = DebuggerServer.connectPipe();
    client = new DebuggerClient(transport);
    client.connect().then(listProcess);
  }

  function listProcess() {
    // Call listProcesses in order to start receiving new process notifications
    client.addListener("processListChanged", function listener() {
      client.removeListener("processListChanged", listener);
      ok(true, "Received processListChanged event");
      getProcess();
    });
    client.mainRoot.listProcesses(response => {
      processCount = response.processes.length;
      // Create a remote iframe to spawn a new process
      createRemoteIframe();
    });
  }

  function createRemoteIframe() {
    iframe = document.createElement("iframe");
    iframe.mozbrowser = true;
    iframe.setAttribute("remote", "true");
    iframe.setAttribute("src", "data:text/html,foo");
    document.body.appendChild(iframe);
  }

  function getProcess() {
    client.mainRoot.listProcesses(response => {
      ok(response.processes.length >= 2, "Got at least the parent process and one child");
      is(response.processes.length, processCount+1 , "Got one additional process on the second call to listProcesses");

      // Connect to the first content processe available
      let content = response.processes.filter(p => (!p.parent))[0];

      client.getProcess(content.id).then(response => {
        let actor = response.form;
        ok(actor.consoleActor, "Got the console actor");
        ok(actor.chromeDebugger, "Got the thread actor");

        // Ensure sending at least one request to an actor...
        client.request({
          to: actor.consoleActor,
          type: "evaluateJS",
          text: "var a = 42; a"
        }, function (response) {
          ok(response.result, 42, "console.eval worked");
          cleanup();
        });
      });
    });
  }

  function cleanup() {
    client.close().then(function () {
      DebuggerServer.destroy();
      iframe.remove();
      SimpleTest.finish()
    });
  }

  connect();
}

</script>
</pre>
</body>
</html>