tor-browser

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

stream-response.any.js (1336B)


      1 // META: global=window,worker
      2 // META: script=../resources/utils.js
      3 
      4 function streamBody(reader, test, count = 0) {
      5  return reader.read().then(function(data) {
      6    if (!data.done && count < 2) {
      7      count += 1;
      8      return streamBody(reader, test, count);
      9    } else {
     10      test.step(function() {
     11        assert_true(count >= 2, "Retrieve body progressively");
     12      });
     13    }
     14  });
     15 }
     16 
     17 //simulate streaming:
     18 //count is large enough to let the UA deliver the body before it is completely retrieved
     19 promise_test(function(test) {
     20  return fetch(RESOURCES_DIR + "trickle.py?ms=30&count=100").then(function(resp) {
     21    if (resp.body)
     22      return streamBody(resp.body.getReader(), test);
     23    else
     24      test.step(function() {
     25        assert_unreached( "Body does not exist in response");
     26      });
     27  });
     28 }, "Stream response's body when content-type is present");
     29 
     30 // This test makes sure that the response body is not buffered if no content type is provided.
     31 promise_test(function(test) {
     32  return fetch(RESOURCES_DIR + "trickle.py?ms=300&count=10&notype=true").then(function(resp) {
     33    if (resp.body)
     34      return streamBody(resp.body.getReader(), test);
     35    else
     36      test.step(function() {
     37        assert_unreached( "Body does not exist in response");
     38      });
     39  });
     40 }, "Stream response's body when content-type is not present");