tor-browser

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

test_websocket_longString.html (1566B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></meta>
      5  <title>WebSocket test - big blob on content side</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <script type="text/javascript" src="websocket_helpers.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      9 </head>
     10 <body>
     11 <script class="testbody" type="text/javascript">
     12 
     13 var ws = new WebSocket("ws://mochi.test:8888/tests/dom/websocket/tests/file_websocket_basic", "test");
     14 is(ws.readyState, 0, "Initial readyState is 0");
     15 
     16 const longString = new Array(1024*1024).join('123456789ABCDEF');
     17 
     18 ws.onopen = function() {
     19  is(this, ws, "[onopen()] 'this' should point to the WebSocket.");
     20  ws.send(longString);
     21 };
     22 
     23 ws.onclose = function(e) {
     24  is(this, ws, "[onclose()] 'this' should point to the WebSocket.");
     25  ok(e.wasClean, "Connection closed cleanly");
     26 
     27  SimpleTest.executeSoon(SimpleTest.finish);
     28 };
     29 
     30 ws.onerror = function() {
     31  is(this, ws, "[onerror()] 'this' should point to the WebSocket.");
     32  ok(false, "onerror()] should not have been called!");
     33  SimpleTest.executeSoon(SimpleTest.finish);
     34 };
     35 
     36 ws.onmessage = function(e) {
     37  is(this, ws, "[onmessage()] 'this' should point to the WebSocket.");
     38  // Do not use |is(e.data, longString, "...");| that results in a _very_ long line.
     39  is(e.data.length, longString.length, "Length of received message");
     40  ok(e.data === longString, "Content of received message");
     41  this.close();
     42 };
     43 
     44 SimpleTest.waitForExplicitFinish();
     45 
     46 </script>
     47 </body>
     48 </html>