Backed out changeset 9d8b4c0b99ed (bug 1945683) for causing btime failures. CLOSED...
[gecko.git] / dom / websocket / tests / websocket_helpers.js
blob65b95506ff8a07122ab3a79dbf080d57cc547952
1 // This file expects a tests array to be defined in the global scope.
2 /* global tests */
4 var current_test = 0;
6 function shouldNotOpen(e) {
7 var ws = e.target;
8 ok(false, "onopen shouldn't be called on test " + ws._testNumber + "!");
11 function shouldCloseCleanly(e) {
12 var ws = e.target;
13 ok(
14 e.wasClean,
15 "the ws connection in test " + ws._testNumber + " should be closed cleanly"
19 function shouldCloseNotCleanly(e) {
20 var ws = e.target;
21 ok(
22 !e.wasClean,
23 "the ws connection in test " +
24 ws._testNumber +
25 " shouldn't be closed cleanly"
29 function ignoreError() {}
31 function CreateTestWS(ws_location, ws_protocol) {
32 var ws;
34 if (ws_protocol == undefined) {
35 ws = new WebSocket(ws_location);
36 } else {
37 ws = new WebSocket(ws_location, ws_protocol);
40 ws._testNumber = current_test;
41 ok(true, "Created websocket for test " + ws._testNumber + "\n");
43 ws.onerror = function (e) {
44 ok(false, "onerror called on test " + e.target._testNumber + "!");
47 return ws;
50 function forcegc() {
51 SpecialPowers.forceGC();
52 SpecialPowers.gc();
55 function feedback() {
56 $("feedback").innerHTML =
57 "executing test: " + (current_test + 1) + " of " + tests.length + " tests.";
60 function finish() {
61 SimpleTest.finish();
64 function doTest() {
65 if (current_test >= tests.length) {
66 finish();
67 return;
70 feedback();
71 tests[current_test++]().then(doTest);