tor-browser

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

test_send-blob.html (1502B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      5  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      6 </head>
      7 <body>
      8 
      9 <p id="display">
     10 </p>
     11 <div id="content" style="display: none">
     12 </div>
     13 <pre id="test">
     14 
     15 <script class="testbody" type="text/javascript">
     16 
     17 function startsWith(target, prefix)
     18 {
     19    return target.indexOf(prefix) === 0;
     20 }
     21 
     22 function distinctBytes()
     23 {
     24    var array = [];
     25    for (var i = 0; i < 256; ++i)
     26        array[i] = i;
     27    // Concatenates chars into a single binary string
     28    return String.fromCharCode.apply(null, array);
     29 }
     30 
     31 var filesToCreate = [
     32  {name: "hellofile", data: "Hello, world!"},
     33  {name: "emptyfile"},
     34  {name: "allchars", data: distinctBytes()},
     35 ];
     36 
     37 SpecialPowers.createFiles(filesToCreate, function (files) {
     38  var ws = new WebSocket("ws://mochi.test:8888/tests/dom/websocket/tests/websocket_hybi/file_check-binary-messages");
     39 
     40  ws.onopen = function()
     41  {
     42      ws.send(files[0]);
     43      ws.send(files[1]);
     44      ws.send(files[2]);
     45  };
     46 
     47  ws.onmessage = function(event)
     48  {
     49      var message = event.data;
     50      if (startsWith(message, "PASS"))
     51          ok(true, message);
     52      else
     53          ok(false, message);
     54  };
     55 
     56  ws.onclose = function(event)
     57  {
     58    ok(event.wasClean, "should have closed cleanly");
     59    SimpleTest.finish();
     60  };
     61 },
     62 function (msg) {
     63  ok(false, "Failed to create files: " + msg);
     64  SimpleTest.finish();
     65 });
     66 
     67 SimpleTest.waitForExplicitFinish();
     68 
     69 </script>
     70 </body>
     71 </html>