tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

websocket_helpers.js (1434B)


      1 // This file expects a tests array to be defined in the global scope.
      2 /* global tests */
      3 
      4 var current_test = 0;
      5 
      6 function shouldNotOpen(e) {
      7  var ws = e.target;
      8  ok(false, "onopen shouldn't be called on test " + ws._testNumber + "!");
      9 }
     10 
     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"
     16  );
     17 }
     18 
     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"
     26  );
     27 }
     28 
     29 function ignoreError() {}
     30 
     31 function CreateTestWS(ws_location, ws_protocol) {
     32  var ws;
     33 
     34  if (ws_protocol == undefined) {
     35    ws = new WebSocket(ws_location);
     36  } else {
     37    ws = new WebSocket(ws_location, ws_protocol);
     38  }
     39 
     40  ws._testNumber = current_test;
     41  ok(true, "Created websocket for test " + ws._testNumber + "\n");
     42 
     43  ws.onerror = function (e) {
     44    ok(false, "onerror called on test " + e.target._testNumber + "!");
     45  };
     46 
     47  return ws;
     48 }
     49 
     50 function forcegc() {
     51  SpecialPowers.forceGC();
     52  SpecialPowers.gc();
     53 }
     54 
     55 function feedback() {
     56  $("feedback").innerHTML =
     57    "executing test: " + (current_test + 1) + " of " + tests.length + " tests.";
     58 }
     59 
     60 function finish() {
     61  SimpleTest.finish();
     62 }
     63 
     64 function doTest() {
     65  if (current_test >= tests.length) {
     66    finish();
     67    return;
     68  }
     69 
     70  feedback();
     71  tests[current_test++]().then(doTest);
     72 }