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.

     1 <!DOCTYPE HTML>
     2 <html>
     3 <!--
     4 Bug 898485 - [app manager] Implement an abstract connection manager
     5 -->
     6 <head>
     7   <meta charset="utf-8">
     8   <title>Mozilla Bug</title>
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    10   <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
    11 </head>
    12 <body>
    13 <pre id="test">
    14 <script>
    16 window.onload = function() {
    17   SimpleTest.waitForExplicitFinish();
    19   var Cu = Components.utils;
    21   Cu.import("resource://gre/modules/devtools/dbg-server.jsm");
    22   Cu.import("resource://gre/modules/devtools/Loader.jsm");
    23   Cu.import("resource://gre/modules/Services.jsm");
    25   DebuggerServer.init(function () { return true; });
    26   DebuggerServer.addBrowserActors();
    28   var {ConnectionManager, Connection} = devtools.require("devtools/client/connection-manager");
    30   var orgCount = ConnectionManager.connections.length;
    32   ConnectionManager.once("new", (event, c) => {
    33     is(ConnectionManager.connections[orgCount], c, "new event fired, with correct connection");
    34   });
    36   var c1 = ConnectionManager.createConnection();
    37   var c2 = ConnectionManager.createConnection();
    39   is(ConnectionManager.connections[orgCount], c1, "Connection 1 registered");
    40   is(ConnectionManager.connections[orgCount + 1], c2, "Connection 2 registered");
    42   c1.once(Connection.Events.DESTROYED, function() {
    43     is(ConnectionManager.connections.length, orgCount + 1, "Connection 1 destroyed");
    45     var c = c2;
    47     var eventsRef = "connecting connected disconnecting disconnected host-changed disconnected timeout destroyed";
    48     var events = [];
    50     var s = Connection.Status;
    52     is(c.status, s.DISCONNECTED, "disconnected");
    54     c.once(Connection.Events.CONNECTING, function(e) { events.push(e); is(c.status, s.CONNECTING, "connecting"); });
    55     c.once(Connection.Events.CONNECTED, function(e) { events.push(e); is(c.status, s.CONNECTED, "connected"); c.disconnect()});
    56     c.once(Connection.Events.DISCONNECTING, function(e) { events.push(e); is(c.status, s.DISCONNECTING, "disconnecting"); });
    57     c.once(Connection.Events.DISCONNECTED, function(e) { events.push(e); is(c.status, s.DISCONNECTED, "disconnected"); testError()});
    58     c.once(Connection.Events.DESTROYED, function(e) { events.push(e); is(c.status, s.DESTROYED, "destroyed"); finish()});
    60     c.connect();
    62     function testStore() {
    63       c.store.on("set", function(e,path) {
    64         if (path.join(".") == "device.width") {
    65           is(c.store.object.device.width, window.screen.width, "Store is fed with valid data");
    66           c.disconnect();
    67         }
    68       });
    69     }
    71     function testError() {
    72       c.once(Connection.Events.DISCONNECTED, function(e) {
    73         events.push(e);
    74         testKeepConnecting();
    75       });
    76       c.once(Connection.Events.HOST_CHANGED, function(e) {
    77         events.push(e);
    78         c.connect();
    79       });
    80       c.port = 1;
    81       c.host = "localhost";
    82     }
    84     function testKeepConnecting() {
    85       // ensure that keepConnecting keep trying connecting
    86       // until the connection attempts timeout
    87       var originalTimeout = Services.prefs.getIntPref("devtools.debugger.remote-timeout");
    88       Services.prefs.setIntPref("devtools.debugger.remote-timeout", 1000);
    89       c.once("timeout", function (e) {
    90         events.push(e);
    91         Services.prefs.setIntPref("devtools.debugger.remote-timeout", originalTimeout);
    92         ConnectionManager.destroyConnection(c);
    93       });
    94       c.keepConnecting = true;
    95       var port = ConnectionManager.getFreeTCPPort();
    96       ok(parseInt(port), "Free TCP port looks like a port number");
    97       c.port = port;
    98       c.host = "locahost";
    99       c.connect();
   100     }
   102     function finish() {
   103       is(events.join(" "), eventsRef, "Events received in the right order");
   104       DebuggerServer.destroy();
   105       SimpleTest.finish();
   106     }
   108   });
   110   ConnectionManager.destroyConnection(c1);
   113 }
   114 </script>
   115 </pre>
   116 </body>
   117 </html>

mercurial