013.html (1381B)
1 <!doctype html> 2 <title>WebSockets: multiple WebSocket objects</title> 3 <meta name=timeout content=long> 4 <script src=/resources/testharness.js></script> 5 <script src=/resources/testharnessreport.js></script> 6 <script src=../constants.sub.js></script> 7 <meta name="variant" content="?default"> 8 <meta name="variant" content="?wss"> 9 <meta name="variant" content="?wpt_flags=h2"> 10 <div id=log></div> 11 <script> 12 async_test(function(t) { 13 // test that the events are fired as they should when opening 25 websockets and 14 // sending a message on each and then closing when getting the message back 15 var ws = []; 16 var events = 0; 17 for (var i = 0; i < 25; ++i) { 18 ws[i] = new WebSocket(SCHEME_DOMAIN_PORT+'/echo'); 19 ws[i].id = i; 20 ws[i].onopen = t.step_func(function(e) { 21 events++; 22 this.send(this.id); 23 this.onopen = t.step_func(function() {assert_unreached()}); 24 }, ws[i]); 25 ws[i].onmessage = t.step_func(function(e) { 26 events++; 27 assert_equals(e.data, ''+this.id); 28 this.close(); 29 this.onmessage = t.step_func(function() {assert_unreached()}); 30 }, ws[i]); 31 ws[i].onclose = t.step_func(function(e) { 32 events++; 33 if (events == 75) { 34 t.done(); 35 } 36 this.onclose = t.step_func(function() {assert_unreached()}); 37 }, ws[i]); 38 ws[i].onerror = t.step_func(function() {assert_unreached()}); 39 } 40 }); 41 </script>