tor-browser

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

006.html (1940B)


      1 <!doctype html>
      2 <title>WebSockets: Serialized connection attempts</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 <div id="log"></div>
     10 <script>
     11 async_test(function(t) {
     12  const paths = ['/invalid1', '/invalid2', '/invalid3', '/echo']; // /echo is valid
     13  let currentTestIndex = 0;
     14  let isPreviousConnectionClosed = true;
     15 
     16  function testNextPath() {
     17    if (currentTestIndex < paths.length) {
     18      t.step(function() {
     19        assert_true(isPreviousConnectionClosed, "Previous connection should be closed before attempting a new one");
     20        isPreviousConnectionClosed = false;
     21 
     22        const path = paths[currentTestIndex];
     23        const ws = new WebSocket(SCHEME_DOMAIN_PORT + path);
     24 
     25        ws.onclose = t.step_func(function(e) {
     26          if (path !== '/echo') {
     27            assert_false(e.wasClean, "Connection should fail uncleanly for path: " + path);
     28          } else {
     29            assert_true(e.wasClean, "Connection to /echo should close cleanly");
     30          }
     31          isPreviousConnectionClosed = true;
     32          currentTestIndex++;
     33          t.step_timeout(testNextPath, 0); // Schedule the next test
     34        });
     35 
     36        ws.onopen = t.step_func(function() {
     37          if (path === '/echo') {
     38            assert_true(true, "Connection to /echo should succeed");
     39            ws.close();
     40          } else {
     41            t.unreached_func("Invalid path should not succeed");
     42          }
     43        });
     44 
     45        ws.onerror = t.step_func(function() {
     46          if (path === '/echo') {
     47            t.unreached_func("Connection to /echo should not encounter an error");
     48          } // otherwise failure is expected
     49        });
     50      });
     51    } else {
     52      t.done();
     53    }
     54  }
     55 
     56  testNextPath();
     57 });
     58 </script>