toolkit/devtools/server/tests/mochitest/test_connectToChild.html

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <SDOCTYPv HTM.>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 Bug 966991 - Test DebuggerServer.connectToChild
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Mozilla Bug</title>
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <pre id="test">
michael@0 14 <script type="application/javascript;version=1.8">
michael@0 15
michael@0 16 let Cu = Components.utils;
michael@0 17 let Cc = Components.classes;
michael@0 18 let Ci = Components.interfaces;
michael@0 19
michael@0 20 Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
michael@0 21 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
michael@0 22
michael@0 23 window.onload = function() {
michael@0 24 SimpleTest.waitForExplicitFinish();
michael@0 25
michael@0 26 SpecialPowers.pushPrefEnv({
michael@0 27 "set": [
michael@0 28 // Always log packets when running tests.
michael@0 29 ["devtools.debugger.log", true],
michael@0 30 ["dom.mozBrowserFramesEnabled", true]
michael@0 31 ]
michael@0 32 }, runTests);
michael@0 33 }
michael@0 34
michael@0 35 function runTests() {
michael@0 36 // Create a minimal iframe with a message manager
michael@0 37 let iframe = document.createElement("iframe");
michael@0 38 iframe.mozbrowser = true;
michael@0 39 document.body.appendChild(iframe);
michael@0 40
michael@0 41 let mm = iframe.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
michael@0 42
michael@0 43 // Register a test actor in the child process so that we can know if and when
michael@0 44 // this fake actor is disconnected.
michael@0 45 mm.loadFrameScript("data:text/javascript,new " + function FrameScriptScope() {
michael@0 46 const {DebuggerServer} = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
michael@0 47
michael@0 48 if (!DebuggerServer.initialized) {
michael@0 49 DebuggerServer.init();
michael@0 50 }
michael@0 51
michael@0 52 function TestActor() {dump("instanciate test actor");}
michael@0 53 TestActor.prototype = {
michael@0 54 actorPrefix: "test",
michael@0 55
michael@0 56 disconnect: function () {
michael@0 57 sendAsyncMessage("test-actor-disconnected", null);
michael@0 58 },
michael@0 59 hello: function () {
michael@0 60 return {msg:"world"};
michael@0 61 }
michael@0 62 };
michael@0 63 TestActor.prototype.requestTypes = {
michael@0 64 "hello": TestActor.prototype.hello
michael@0 65 };
michael@0 66 DebuggerServer.addTabActor(TestActor, "testActor");
michael@0 67 }, false);
michael@0 68
michael@0 69 // Instantiate a minimal server
michael@0 70 DebuggerServer.init(function () { return true; });
michael@0 71 DebuggerServer.addBrowserActors();
michael@0 72
michael@0 73 function firstClient() {
michael@0 74 // Fake a first connection to an iframe
michael@0 75 let transport = DebuggerServer.connectPipe();
michael@0 76 let conn = transport._serverConnection;
michael@0 77 let client = new DebuggerClient(transport);
michael@0 78 DebuggerServer.connectToChild(conn, iframe).then(actor => {
michael@0 79 ok(actor.testActor, "Got the test actor");
michael@0 80
michael@0 81 // Ensure sending at least one request to our actor,
michael@0 82 // otherwise it won't be instanciated, nor be disconnected...
michael@0 83 client.request({
michael@0 84 to: actor.testActor,
michael@0 85 type: "hello",
michael@0 86 }, function (response) {
michael@0 87
michael@0 88 // Then close the client. That should end up cleaning our test actor
michael@0 89 client.close();
michael@0 90
michael@0 91 // Ensure that our test actor got cleaned up;
michael@0 92 // its disconnect method should be called
michael@0 93 mm.addMessageListener("test-actor-disconnected", function listener() {
michael@0 94 mm.removeMessageListener("test-actor-disconnected", listener);
michael@0 95 ok(true, "Actor is cleaned up");
michael@0 96
michael@0 97 secondClient(actor.testActor);
michael@0 98 });
michael@0 99 });
michael@0 100 });
michael@0 101 }
michael@0 102
michael@0 103 function secondClient(firstActor) {
michael@0 104 // Then fake a second one, that should spawn a new set of tab actors
michael@0 105 let transport = DebuggerServer.connectPipe();
michael@0 106 let conn = transport._serverConnection;
michael@0 107 let client = new DebuggerClient(transport);
michael@0 108 DebuggerServer.connectToChild(conn, iframe).then(actor => {
michael@0 109 ok(actor.testActor, "Got a test actor for the second connection");
michael@0 110 isnot(actor.testActor, firstActor, "We get different actor instances between two connections");
michael@0 111
michael@0 112 client.close(cleanup);
michael@0 113 });
michael@0 114 }
michael@0 115
michael@0 116 function cleanup() {
michael@0 117 DebuggerServer.destroy();
michael@0 118 iframe.remove();
michael@0 119 SimpleTest.finish()
michael@0 120 }
michael@0 121
michael@0 122 firstClient();
michael@0 123 }
michael@0 124
michael@0 125 </script>
michael@0 126 </pre>
michael@0 127 </body>
michael@0 128 </html>

mercurial