tor-browser

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

access-control-basic-allow-preflight-cache.any.js (1421B)


      1 // META: title=Preflight cache should allow second request without preflight OPTIONS request
      2 // META: script=/common/get-host-info.sub.js
      3 // META: script=/common/utils.js
      4 
      5    const uuid = token();
      6 
      7    async_test(function(test) {
      8      const xhr = new XMLHttpRequest;
      9      xhr.onerror = test.unreached_func("FAIL: Network error.");
     10      xhr.onload = test.step_func(function() {
     11        // Token reset.  We can start the test now.
     12        assert_equals(xhr.responseText, "PASS");
     13        firstRequest();
     14      });
     15 
     16      xhr.open("GET", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/reset-token.py?token=" + uuid, true);
     17      xhr.send();
     18 
     19      function firstRequest() {
     20        xhr.onload = test.step_func(function() {
     21          assert_equals(xhr.responseText, "PASS: First PUT request.");
     22          secondRequest();
     23        });
     24        xhr.open("PUT", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/access-control-basic-preflight-cache.py?token=" + uuid, true);
     25        xhr.send();
     26      }
     27 
     28      function secondRequest() {
     29        xhr.onload = test.step_func_done(function() {
     30          assert_equals(xhr.responseText, "PASS: Second PUT request. Preflight worked.");
     31        });
     32        xhr.open("PUT", get_host_info().HTTP_REMOTE_ORIGIN + "/xhr/resources/access-control-basic-preflight-cache.py?token=" + uuid, true);
     33        xhr.send();
     34      }
     35    }, "Preflight cache should allow second request");