summaryrefslogtreecommitdiffstats
path: root/dom/base/test/websocket_hybi/test_send-blob.html
blob: 291883cd7658c00e04d84c01badebd5edd592ef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

<p id="display">
</p>
<div id="content" style="display: none">
</div>
<pre id="test">

<script class="testbody" type="text/javascript">

function startsWith(target, prefix)
{
    return target.indexOf(prefix) === 0;
}

function distinctBytes()
{
    var array = new Array();
    for (var i = 0; i < 256; ++i)
        array[i] = i;
    // Concatenates chars into a single binary string
    return String.fromCharCode.apply(null, array);
}

var filesToCreate = [
  {name: "hellofile", data: "Hello, world!"},
  {name: "emptyfile"},
  {name: "allchars", data: distinctBytes()},
];

SpecialPowers.createFiles(filesToCreate, function (files) {
  var ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/websocket_hybi/file_check-binary-messages");
  var closeEvent;

  ws.onopen = function()
  {
      ws.send(files[0]);
      ws.send(files[1]);
      ws.send(files[2]);
  };

  ws.onmessage = function(event)
  {
      var message = event.data;
      if (startsWith(message, "PASS"))
          ok(true, message);
      else
          ok(false, message);
  };

  ws.onclose = function(event)
  {
    ok(event.wasClean, "should have closed cleanly");
    SimpleTest.finish();
  };
},
function (msg) {
  ok(false, "Failed to create files: " + msg);
  SimpleTest.finish();
});

SimpleTest.waitForExplicitFinish();

</script>
</body>
</html>