summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_director_connectToChild.html
blob: cb348efe667da037f341ea2f18164572685ed058 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=
-->
<head>
  <meta charset="utf-8">
  <title>Test for 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" src="./director-helpers.js"></script>
  <script type="application/javascript;version=1.8">
window.onload = function() {
  Task.spawn(function* () {
    SimpleTest.waitForExplicitFinish();

    var tests = [
      runPropagateDirectorScriptsToChildTest,
    ].map((testCase) => {
      return function* () {
        setup();
        yield testCase().then(null, (e) => {
          ok(false, "Exception during testCase run: " + [e, e.fileName, e.lineNumber].join("\n\t"));
        });

        teardown();
      };
    });

    for (var test of tests) {
      yield test();
    }

    SimpleTest.finish();
  });
};

function setup() {
  if (!DebuggerServer.initialized) {
    DebuggerServer.init(() => true);
    DebuggerServer.addBrowserActors();
    SimpleTest.registerCleanupFunction(function() {
      DebuggerServer.destroy();
    });
  }
}

function teardown() {
  purgeInstalledDirectorScripts();
  DebuggerServer.destroy();
}

/***********************************
 *  test cases
 **********************************/

function runPropagateDirectorScriptsToChildTest() {
  let iframe = document.createElement("iframe");
  iframe.mozbrowser = true;

  document.body.appendChild(iframe);

  return Task.spawn(function* () {
    var { client, root, transport } = yield newConnectedDebuggerClient();

    var directorRegistryClient = new DirectorRegistryFront(client, root);

    // install a director script
    yield directorRegistryClient.install("testPropagatedDirectorScript", {
      scriptCode: "console.log('director script test');",
      scriptOptions: {}
    });

    var conn = transport._serverConnection;
    var childActor = yield DebuggerServer.connectToChild(conn, iframe);

    ok(typeof childActor.directorManagerActor !== "undefined",
       "childActor.directorActor should be defined");

    var childDirectorManagerClient = new DirectorManagerFront(client, childActor);

    var directorScriptList = yield childDirectorManagerClient.list();

    ok(directorScriptList.installed.length === 1 &&
       directorScriptList.installed[0] === "testPropagatedDirectorScript",
       "director scripts propagated correctly")

    yield client.close();
  });
}
  </script>
</pre>
</body>
</html>