toolkit/devtools/server/tests/mochitest/test_connection-manager.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 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 Bug 898485 - [app manager] Implement an abstract connection manager
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>
michael@0 15
michael@0 16 window.onload = function() {
michael@0 17 SimpleTest.waitForExplicitFinish();
michael@0 18
michael@0 19 var Cu = Components.utils;
michael@0 20
michael@0 21 Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
michael@0 22 Cu.import("resource://gre/modules/devtools/Loader.jsm");
michael@0 23 Cu.import("resource://gre/modules/Services.jsm");
michael@0 24
michael@0 25 DebuggerServer.init(function () { return true; });
michael@0 26 DebuggerServer.addBrowserActors();
michael@0 27
michael@0 28 var {ConnectionManager, Connection} = devtools.require("devtools/client/connection-manager");
michael@0 29
michael@0 30 var orgCount = ConnectionManager.connections.length;
michael@0 31
michael@0 32 ConnectionManager.once("new", (event, c) => {
michael@0 33 is(ConnectionManager.connections[orgCount], c, "new event fired, with correct connection");
michael@0 34 });
michael@0 35
michael@0 36 var c1 = ConnectionManager.createConnection();
michael@0 37 var c2 = ConnectionManager.createConnection();
michael@0 38
michael@0 39 is(ConnectionManager.connections[orgCount], c1, "Connection 1 registered");
michael@0 40 is(ConnectionManager.connections[orgCount + 1], c2, "Connection 2 registered");
michael@0 41
michael@0 42 c1.once(Connection.Events.DESTROYED, function() {
michael@0 43 is(ConnectionManager.connections.length, orgCount + 1, "Connection 1 destroyed");
michael@0 44
michael@0 45 var c = c2;
michael@0 46
michael@0 47 var eventsRef = "connecting connected disconnecting disconnected host-changed disconnected timeout destroyed";
michael@0 48 var events = [];
michael@0 49
michael@0 50 var s = Connection.Status;
michael@0 51
michael@0 52 is(c.status, s.DISCONNECTED, "disconnected");
michael@0 53
michael@0 54 c.once(Connection.Events.CONNECTING, function(e) { events.push(e); is(c.status, s.CONNECTING, "connecting"); });
michael@0 55 c.once(Connection.Events.CONNECTED, function(e) { events.push(e); is(c.status, s.CONNECTED, "connected"); c.disconnect()});
michael@0 56 c.once(Connection.Events.DISCONNECTING, function(e) { events.push(e); is(c.status, s.DISCONNECTING, "disconnecting"); });
michael@0 57 c.once(Connection.Events.DISCONNECTED, function(e) { events.push(e); is(c.status, s.DISCONNECTED, "disconnected"); testError()});
michael@0 58 c.once(Connection.Events.DESTROYED, function(e) { events.push(e); is(c.status, s.DESTROYED, "destroyed"); finish()});
michael@0 59
michael@0 60 c.connect();
michael@0 61
michael@0 62 function testStore() {
michael@0 63 c.store.on("set", function(e,path) {
michael@0 64 if (path.join(".") == "device.width") {
michael@0 65 is(c.store.object.device.width, window.screen.width, "Store is fed with valid data");
michael@0 66 c.disconnect();
michael@0 67 }
michael@0 68 });
michael@0 69 }
michael@0 70
michael@0 71 function testError() {
michael@0 72 c.once(Connection.Events.DISCONNECTED, function(e) {
michael@0 73 events.push(e);
michael@0 74 testKeepConnecting();
michael@0 75 });
michael@0 76 c.once(Connection.Events.HOST_CHANGED, function(e) {
michael@0 77 events.push(e);
michael@0 78 c.connect();
michael@0 79 });
michael@0 80 c.port = 1;
michael@0 81 c.host = "localhost";
michael@0 82 }
michael@0 83
michael@0 84 function testKeepConnecting() {
michael@0 85 // ensure that keepConnecting keep trying connecting
michael@0 86 // until the connection attempts timeout
michael@0 87 var originalTimeout = Services.prefs.getIntPref("devtools.debugger.remote-timeout");
michael@0 88 Services.prefs.setIntPref("devtools.debugger.remote-timeout", 1000);
michael@0 89 c.once("timeout", function (e) {
michael@0 90 events.push(e);
michael@0 91 Services.prefs.setIntPref("devtools.debugger.remote-timeout", originalTimeout);
michael@0 92 ConnectionManager.destroyConnection(c);
michael@0 93 });
michael@0 94 c.keepConnecting = true;
michael@0 95 var port = ConnectionManager.getFreeTCPPort();
michael@0 96 ok(parseInt(port), "Free TCP port looks like a port number");
michael@0 97 c.port = port;
michael@0 98 c.host = "locahost";
michael@0 99 c.connect();
michael@0 100 }
michael@0 101
michael@0 102 function finish() {
michael@0 103 is(events.join(" "), eventsRef, "Events received in the right order");
michael@0 104 DebuggerServer.destroy();
michael@0 105 SimpleTest.finish();
michael@0 106 }
michael@0 107
michael@0 108 });
michael@0 109
michael@0 110 ConnectionManager.destroyConnection(c1);
michael@0 111
michael@0 112
michael@0 113 }
michael@0 114 </script>
michael@0 115 </pre>
michael@0 116 </body>
michael@0 117 </html>

mercurial