summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_bug1081686.html
blob: bd00c3f64f1d0456b1a8e600bc2cacdc0ed0f8de (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
<!DOCTYPE HTML>
<html>
<!--
-->
<head>
  <title>bug 1081686</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body onload="testWebSocket()">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

var ws;

function forcegc()
{
  SpecialPowers.forceGC();
  SpecialPowers.gc();
  setTimeout(function()
  {
    SpecialPowers.gc();
  }, 0);
}

function testWebSocket () {
  ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/file_websocket_hello");
  ws.onopen = function(e) {
    ws.send("data");
  }
  ws.onclose = function(e) {
    forcegc();
    setTimeout(function() {
      is(ws.readyState, 3, 'WebSocket is closed');
      is(ws.bufferedAmount, 0, 'WebSocket.bufferedAmount should be empty.');
      is(ws.binaryType, 'blob', 'WebSocket.binaryType is blob');
      ws.binaryType = 'arraybuffer';
      is(ws.binaryType, 'arraybuffer', 'WebSocket.binaryType is arraybuffer');
      is(ws.url, 'ws://mochi.test:8888/tests/dom/base/test/file_websocket_hello', 'WebSocket.url is correct');
      ws.close();
      ws.send('foobar');
      SimpleTest.finish();
    }, 1000);
  }

  ws.onerror = function(e) {
    ok(false, "onerror called!");
    SimpleTest.finish();
  }
  ws.onmessage = function(e) {
    is(e.data, "Hello world!", "Wrong data");
    ws.close();
  }
}

SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("untriaged");

</script>
</pre>
<div>


</div>


</body>
</html>