tor-browser

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

test_nestedSyncXHR.html (2368B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for sync XHR into sync XHRs</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10  <script type="application/javascript">
     11 
     12 
     13 let xhr = new XMLHttpRequest();
     14 let testCompleted = false;
     15 
     16 let frame = document.createElement('frame');
     17 frame.src = "data:text/html,";
     18 frame.addEventListener('load', function() {
     19  if (testCompleted) {
     20    return;
     21  }
     22 
     23  try {
     24    xhr.responseType = "blob";
     25    ok(false, "xhr.responseType cannot be settable");
     26  } catch(e) {
     27    ok(true, "xhr.responseType cannot be settable");
     28  }
     29 
     30  try {
     31    xhr.abort();
     32    ok(false, "xhr.abort should throw");
     33  } catch(e) {
     34    ok(true, "xhr.abort should throw");
     35  }
     36 
     37  try {
     38    xhr.getAllResponseHeaders();
     39    ok(false, "xhr.getAllResponseHeaders should throw");
     40  } catch(e) {
     41    ok(true, "xhr.getAllResponseHeaders should throw");
     42  }
     43 
     44  try {
     45    xhr.getResponseHeader("foo");
     46    ok(false, "xhr.getResponseHeader should throw");
     47  } catch(e) {
     48    ok(true, "xhr.getResponseHeader should throw");
     49  }
     50 
     51  try {
     52    xhr.open('POST', location, false);
     53    ok(false, "xhr.open should throw");
     54  } catch(e) {
     55    ok(true, "xhr.open should throw");
     56  }
     57 
     58  try {
     59    xhr.send();
     60    ok(false, "xhr.send should throw");
     61  } catch(e) {
     62    ok(true, "xhr.send should throw");
     63  }
     64 
     65  try {
     66    xhr.timeout = 42;
     67    ok(false, "xhr.timeout cannot be settable");
     68  } catch(e) {
     69    ok(true, "xhr.timeout cannot be settable");
     70  }
     71 
     72  try {
     73    xhr.withCredentials = false;
     74    ok(false, "xhr.withCredentials cannot be settable");
     75  } catch(e) {
     76    ok(true, "xhr.withCredentials cannot be settable");
     77  }
     78 
     79  try {
     80    xhr.overrideMimeType("wow")
     81    ok(false, "xhr.overrideMimeType should throw");
     82  } catch(e) {
     83    ok(true, "xhr.overrideMimeType should throw");
     84  }
     85 }, { once: true });
     86 
     87 // This test is racy because we try to check that the loading of the frame
     88 // happens during a sync XHR. If the loading happens after, we still need to
     89 // consider the test passed.
     90 ok(xhr, "We have an XHR.");
     91 
     92 document.documentElement.appendChild(frame);
     93 xhr.open('POST', location, false);
     94 xhr.send('X');
     95 
     96 // Nothing can guarantee that the frame is loaded during the sync XHR.
     97 testCompleted = true;
     98 
     99 frame.remove();
    100  </script>
    101 </body>
    102 </html>