gTestElement.textContent += "\nSending :";
for (var i = 0; i < params.length; ++i) {
gTestElement.textContent += " " + params[i];
ws.send(params[i]);
}
// Set this before onmessage() is called, so it is displayed once only.
gTestElement.textContent += "\nReceived:";
};
ws.onclose = function(e) {
is(results.length, 0, "[1] Number of unreceived messages");
ok(e.wasClean, "[1] Connection closed cleanly");
SimpleTest.executeSoon(testWebSocket2);
};
ws.onerror = function() {
ok(false, "[1] onerror() should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
ws.onmessage = function(e) {
is(e.data, results[0], "[1] Received message");
gTestElement.textContent += " " + e.data;
results.shift();
};
}
/**
* Sends 1000+1 test messages, then receives them.
*/
function testWebSocket2() {
gTestElement.textContent = "Running testWebSocket2()";
ws = new WebSocket(kUrl, "test");
ws.onopen = function() {
gTestElement.textContent += "\nSending :";
for (var i = 1; i <= testCount; ++i) {
if (i % displayInterval == 1) {
gTestElement.textContent += " " + i;
}
ws.send(testMessage + i);
}
gTestElement.textContent += " end";
ws.send("end");
// Set this before onmessage() is called, so it is displayed once only.
gTestElement.textContent += "\nReceived:";
};
ws.onclose = function(e) {
is(messageCount, testCount + 1, "[2] Number of received messages");
ok(e.wasClean, "[2] Connection closed cleanly");
SimpleTest.executeSoon(testWebSocket3);
};
ws.onerror = function() {
ok(false, "[2] onerror() should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
ws.onmessage = function(e) {
++messageCount;
if (messageCount > testCount)
is(e.data, "end", "[2] Received message");
else
is(e.data, testMessage + messageCount, "[2] Received message");
if (messageCount % displayInterval == 1) {
gTestElement.textContent += " " + messageCount;
}
};
}
/**
* Sends testcount+1 test messages, then receives them, calling forcegc() at each step.
*/
function testWebSocket3() {
gTestElement.textContent = "Running testWebSocket3() [can take a little while]";
ws = new WebSocket(kUrl, "test");
// Set this before onopen() is called,
// otherwise its display would be delayed by forcegc() calls...
gTestElement.textContent += "\nSending :";
ws.onopen = function() {
for (var i = 1; i <= testCount; ++i) {
forcegc();
if (i % displayInterval == 1) {
// Actual display is delayed by forcegc() calls...
gTestElement.textContent += " " + i;
}
ws.send(testMessage + i);
}
forcegc();
gTestElement.textContent += " end";
ws.send("end");
// Set this before onmessage() is called, so it is displayed once only.
gTestElement.textContent += "\nReceived:";
};
ws.onclose = function(e) {
is(messageCount, testCount + 1, "[3] Number of received messages");
ok(e.wasClean, "[3] Connection closed cleanly");
SimpleTest.executeSoon(testWebSocket4);
};
ws.onerror = function() {
ok(false, "[3] onerror() should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
ws.onmessage = function(e) {
forcegc();
++messageCount;
if (messageCount > testCount)
is(e.data, "end", "[3] Received message");
else
is(e.data, testMessage + messageCount, "[3] Received message");
if (messageCount % displayInterval == 1) {
// Actual display is delayed by forcegc() call(s)...
gTestElement.textContent += " " + messageCount;
}
};
}
/**
* Sends a huge test message, then receives it, then closes the WebSocket from client-side.
*/
function testWebSocket4() {
gTestElement.textContent = "Running testWebSocket4()";
ws = new WebSocket(kUrl, "test");
ws.onopen = function() {
is(this, ws, "[4, onopen()] 'this' should point to the WebSocket.");
gTestElement.textContent += "\nSending the huge message";
ws.send(longString);
};
ws.onclose = function(e) {
is(this, ws, "[4, onclose()] 'this' should point to the WebSocket.");
ok(e.wasClean, "[4] Connection closed cleanly");
SimpleTest.executeSoon(testWebSocket5);
};
ws.onerror = function() {
is(this, ws, "[4, onerror()] 'this' should point to the WebSocket.");
ok(false, "[4, onerror()] should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
ws.onmessage = function(e) {
is(this, ws, "[4, onmessage()] 'this' should point to the WebSocket.");
// Do not use |is(e.data, longString, "...");| that results in a _very_ long line.
is(e.data.length, longString.length, "[4] Length of received message");
ok(e.data == longString, "[4] Content of received message");
gTestElement.textContent += "\nReceived the huge message";
this.close();
};
}
/**
* Closes the WebSocket from client-side, then sends a test message that should be buffered.
*/
function testWebSocket5() {
gTestElement.textContent = "Running testWebSocket5()";
ws = new WebSocket(kUrl, "test");
ws.onopen = function() {
is(this.bufferedAmount, 0, "[5] Length of empty buffer before closing");
this.close();
};
ws.onclose = function(e) {
ok(e.wasClean, "[5] Connection closed cleanly");
is(this.bufferedAmount, 0, "[5] Length of empty buffer after closing");
var msg = "test message to be buffered";
this.send(msg);
is(this.bufferedAmount, msg.length, "[5] Length of buffered message sent after closing");
SimpleTest.executeSoon(testWebSocket6);
};
ws.onerror = function() {
ok(false, "[5] onerror() should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
}
function testWebSocket6() {
gTestElement.textContent = "Running testWebSocket6()";
SimpleTest.executeSoon(SimpleTest.finish);
};
ws.onerror = function() {
ok(false, "[6] onerror() should not have been called!");
gTestElement.textContent += "\nonerror() should not have been called!";
SimpleTest.executeSoon(SimpleTest.finish);
};
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.4Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.