summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/mochitest/test_connectToChild.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/server/tests/mochitest/test_connectToChild.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/tests/mochitest/test_connectToChild.html')
-rw-r--r--devtools/server/tests/mochitest/test_connectToChild.html134
1 files changed, 134 insertions, 0 deletions
diff --git a/devtools/server/tests/mochitest/test_connectToChild.html b/devtools/server/tests/mochitest/test_connectToChild.html
new file mode 100644
index 000000000..3bda7b566
--- /dev/null
+++ b/devtools/server/tests/mochitest/test_connectToChild.html
@@ -0,0 +1,134 @@
+<SDOCTYPv HTM.>
+<html>
+<!--
+Bug 966991 - Test DebuggerServer.connectToChild
+-->
+<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],
+ ["dom.mozBrowserFramesEnabled", true]
+ ]
+ }, runTests);
+}
+
+function runTests() {
+ // Create a minimal iframe with a message manager
+ let iframe = document.createElement("iframe");
+ iframe.mozbrowser = true;
+ document.body.appendChild(iframe);
+
+ let mm = iframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
+
+ // Register a test actor in the child process so that we can know if and when
+ // this fake actor is disconnected.
+ mm.loadFrameScript("data:text/javascript,new " + function FrameScriptScope() {
+ const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
+ const { DebuggerServer } = require("devtools/server/main");
+
+ if (!DebuggerServer.initialized) {
+ DebuggerServer.init();
+ }
+
+ function TestActor() {dump("instanciate test actor\n");}
+ TestActor.prototype = {
+ actorPrefix: "test",
+
+ disconnect: function () {
+ sendAsyncMessage("test-actor-disconnected", null);
+ },
+ hello: function () {
+ return {msg:"world"};
+ }
+ };
+ TestActor.prototype.requestTypes = {
+ "hello": TestActor.prototype.hello
+ };
+ DebuggerServer.addTabActor(TestActor, "testActor");
+ }, false);
+
+ // Instantiate a minimal server
+ if (!DebuggerServer.initialized) {
+ DebuggerServer.init();
+ }
+ if (!DebuggerServer.createRootActor) {
+ DebuggerServer.addBrowserActors();
+ }
+
+ function firstClient() {
+ // Fake a first connection to an iframe
+ let transport = DebuggerServer.connectPipe();
+ let conn = transport._serverConnection;
+ let client = new DebuggerClient(transport);
+ DebuggerServer.connectToChild(conn, iframe).then(actor => {
+ ok(actor.testActor, "Got the test actor");
+
+ // Ensure sending at least one request to our actor,
+ // otherwise it won't be instanciated, nor be disconnected...
+ client.request({
+ to: actor.testActor,
+ type: "hello",
+ }, function (response) {
+
+ // Then close the client. That should end up cleaning our test actor
+ client.close();
+
+ // Ensure that our test actor got cleaned up;
+ // its disconnect method should be called
+ mm.addMessageListener("test-actor-disconnected", function listener() {
+ mm.removeMessageListener("test-actor-disconnected", listener);
+ ok(true, "Actor is cleaned up");
+
+ secondClient(actor.testActor);
+ });
+ });
+ });
+ }
+
+ function secondClient(firstActor) {
+ // Then fake a second one, that should spawn a new set of tab actors
+ let transport = DebuggerServer.connectPipe();
+ let conn = transport._serverConnection;
+ let client = new DebuggerClient(transport);
+ DebuggerServer.connectToChild(conn, iframe).then(actor => {
+ ok(actor.testActor, "Got a test actor for the second connection");
+ isnot(actor.testActor, firstActor, "We get different actor instances between two connections");
+
+ client.close(cleanup);
+ });
+ }
+
+ function cleanup() {
+ DebuggerServer.destroy();
+ iframe.remove();
+ SimpleTest.finish()
+ }
+
+ firstClient();
+}
+
+</script>
+</pre>
+</body>
+</html>