tor-browser

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

response-stream-disturbed-6.any.js (2303B)


      1 // META: global=window,worker
      2 // META: title=ReadableStream disturbed tests, via Response's bodyUsed property
      3 
      4 "use strict";
      5 
      6 test(() => {
      7  const stream = new ReadableStream();
      8  const response = new Response(stream);
      9  assert_false(response.bodyUsed, "On construction");
     10 
     11  const reader = stream.getReader();
     12  assert_false(response.bodyUsed, "After getting a reader");
     13 
     14  reader.read();
     15  assert_true(response.bodyUsed, "After calling stream.read()");
     16 }, "A non-closed stream on which read() has been called");
     17 
     18 test(() => {
     19  const stream = new ReadableStream();
     20  const response = new Response(stream);
     21  assert_false(response.bodyUsed, "On construction");
     22 
     23  const reader = stream.getReader();
     24  assert_false(response.bodyUsed, "After getting a reader");
     25 
     26  reader.cancel();
     27  assert_true(response.bodyUsed, "After calling stream.cancel()");
     28 }, "A non-closed stream on which cancel() has been called");
     29 
     30 test(() => {
     31  const stream = new ReadableStream({
     32    start(c) {
     33      c.close();
     34    }
     35  });
     36  const response = new Response(stream);
     37  assert_false(response.bodyUsed, "On construction");
     38 
     39  const reader = stream.getReader();
     40  assert_false(response.bodyUsed, "After getting a reader");
     41 
     42  reader.read();
     43  assert_true(response.bodyUsed, "After calling stream.read()");
     44 }, "A closed stream on which read() has been called");
     45 
     46 test(() => {
     47  const stream = new ReadableStream({
     48    start(c) {
     49      c.error(new Error("some error"));
     50    }
     51  });
     52  const response = new Response(stream);
     53  assert_false(response.bodyUsed, "On construction");
     54 
     55  const reader = stream.getReader();
     56  assert_false(response.bodyUsed, "After getting a reader");
     57 
     58  reader.read().then(() => { }, () => { });
     59  assert_true(response.bodyUsed, "After calling stream.read()");
     60 }, "An errored stream on which read() has been called");
     61 
     62 test(() => {
     63  const stream = new ReadableStream({
     64    start(c) {
     65      c.error(new Error("some error"));
     66    }
     67  });
     68  const response = new Response(stream);
     69  assert_false(response.bodyUsed, "On construction");
     70 
     71  const reader = stream.getReader();
     72  assert_false(response.bodyUsed, "After getting a reader");
     73 
     74  reader.cancel().then(() => { }, () => { });
     75  assert_true(response.bodyUsed, "After calling stream.cancel()");
     76 }, "An errored stream on which cancel() has been called");