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
|
<!doctype html>
<title>WebSockets: addEventListener</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=../../../constants.js?pipe=sub></script>
<meta name="variant" content="">
<meta name="variant" content="?wss">
<div id=log></div>
<script>
async_test(function(t) {
var ws = new WebSocket(SCHEME_DOMAIN_PORT+'/echo');
var count = 0;
var checkCount = t.step_func(function (c, e) {
count++;
assert_equals(count, c);
});
// no spec requires this order for event listeners but the web does
ws.addEventListener('open', t.step_func(function(e) {
checkCount(1, e);
ws.send('Goodbye');
}), false);
ws.onopen = t.step_func(function(e) {checkCount(2, e) });
ws.addEventListener('open', t.step_func(function(e) {checkCount(3, e); }), false);
ws.addEventListener('message', t.step_func(function(e) {checkCount(4, e); }), false);
ws.onmessage = t.step_func(function(e) {checkCount(5, e) });
ws.addEventListener('message', t.step_func(function(e) {checkCount(6, e); }), false);
ws.addEventListener('close', t.step_func(function(e) {checkCount(7, e); }), false);
ws.onclose = t.step_func(function(e) {checkCount(8, e) });
ws.addEventListener('close', t.step_func(function(e) {
checkCount(9, e);
t.done();
}), false);
});
</script>
|