зеркало из https://github.com/mozilla/gecko-dev.git
133 строки
4.0 KiB
HTML
133 строки
4.0 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
Bug 898485 - [app manager] Implement an abstract connection manager
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Mozilla Bug</title>
|
|
<script 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>
|
|
"use strict";
|
|
|
|
window.onload = function() {
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
|
|
const {DebuggerServer} = require("devtools/server/debugger-server");
|
|
const Services = require("Services");
|
|
|
|
DebuggerServer.init();
|
|
DebuggerServer.registerAllActors();
|
|
|
|
const {
|
|
ConnectionManager,
|
|
Connection,
|
|
} = require("devtools/shared/client/connection-manager");
|
|
|
|
const orgCount = ConnectionManager.connections.length;
|
|
|
|
ConnectionManager.once("new", c => {
|
|
is(ConnectionManager.connections[orgCount], c,
|
|
"new event fired, with correct connection");
|
|
});
|
|
|
|
const c1 = ConnectionManager.createConnection();
|
|
const c2 = ConnectionManager.createConnection();
|
|
|
|
is(ConnectionManager.connections[orgCount], c1, "Connection 1 registered");
|
|
is(ConnectionManager.connections[orgCount + 1], c2, "Connection 2 registered");
|
|
|
|
c1.once(Connection.Events.DESTROYED, function() {
|
|
is(ConnectionManager.connections.length, orgCount + 1, "Connection 1 destroyed");
|
|
|
|
const c = c2;
|
|
|
|
const eventsRef = "connecting connected disconnecting disconnected host-changed"
|
|
+ " disconnected timeout destroyed";
|
|
const events = [];
|
|
|
|
const s = Connection.Status;
|
|
|
|
is(c.status, s.DISCONNECTED, "disconnected");
|
|
|
|
c.once(Connection.Events.CONNECTING, function() {
|
|
events.push(Connection.Events.CONNECTING);
|
|
is(c.status, s.CONNECTING, "connecting");
|
|
});
|
|
|
|
c.once(Connection.Events.CONNECTED, function() {
|
|
events.push(Connection.Events.CONNECTED);
|
|
is(c.status, s.CONNECTED, "connected");
|
|
c.disconnect();
|
|
});
|
|
|
|
c.once(Connection.Events.DISCONNECTING, function() {
|
|
events.push(Connection.Events.DISCONNECTING);
|
|
is(c.status, s.DISCONNECTING, "disconnecting");
|
|
});
|
|
|
|
c.once(Connection.Events.DISCONNECTED, function() {
|
|
events.push(Connection.Events.DISCONNECTED);
|
|
is(c.status, s.DISCONNECTED, "disconnected");
|
|
testError();
|
|
});
|
|
|
|
c.once(Connection.Events.DESTROYED, function() {
|
|
events.push(Connection.Events.DESTROYED);
|
|
is(c.status, s.DESTROYED, "destroyed");
|
|
finish();
|
|
});
|
|
|
|
c.connect();
|
|
|
|
function testError() {
|
|
c.once(Connection.Events.DISCONNECTED, function() {
|
|
events.push(Connection.Events.DISCONNECTED);
|
|
testKeepConnecting();
|
|
});
|
|
c.once(Connection.Events.HOST_CHANGED, function() {
|
|
events.push(Connection.Events.HOST_CHANGED);
|
|
c.connect();
|
|
});
|
|
c.port = 1;
|
|
c.host = "localhost";
|
|
}
|
|
|
|
function testKeepConnecting() {
|
|
// ensure that keepConnecting keep trying connecting
|
|
// until the connection attempts timeout
|
|
const prefRemoteTimeout = "devtools.debugger.remote-timeout";
|
|
const originalTimeout = Services.prefs.getIntPref(prefRemoteTimeout);
|
|
Services.prefs.setIntPref("devtools.debugger.remote-timeout", 1000);
|
|
c.once(Connection.Events.TIMEOUT, function() {
|
|
events.push(Connection.Events.TIMEOUT);
|
|
Services.prefs.setIntPref(prefRemoteTimeout, originalTimeout);
|
|
ConnectionManager.destroyConnection(c);
|
|
});
|
|
c.keepConnecting = true;
|
|
const port = ConnectionManager.getFreeTCPPort();
|
|
ok(parseInt(port, 10), "Free TCP port looks like a port number");
|
|
c.port = port;
|
|
c.host = "locahost";
|
|
c.connect();
|
|
}
|
|
|
|
function finish() {
|
|
is(events.join(" "), eventsRef, "Events received in the right order");
|
|
DebuggerServer.destroy();
|
|
SimpleTest.finish();
|
|
}
|
|
});
|
|
|
|
ConnectionManager.destroyConnection(c1);
|
|
};
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|