summaryrefslogtreecommitdiffstats
path: root/test/wpt/tests/fetch/api/response/response-stream-disturbed-6.any.js
blob: 61d8544f0786c803f2793d463390537ff7d78fca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// META: global=window,worker
// META: title=ReadableStream disturbed tests, via Response's bodyUsed property

"use strict";

test(() => {
  const stream = new ReadableStream();
  const response = new Response(stream);
  assert_false(response.bodyUsed, "On construction");

  const reader = stream.getReader();
  assert_false(response.bodyUsed, "After getting a reader");

  reader.read();
  assert_true(response.bodyUsed, "After calling stream.read()");
}, "A non-closed stream on which read() has been called");

test(() => {
  const stream = new ReadableStream();
  const response = new Response(stream);
  assert_false(response.bodyUsed, "On construction");

  const reader = stream.getReader();
  assert_false(response.bodyUsed, "After getting a reader");

  reader.cancel();
  assert_true(response.bodyUsed, "After calling stream.cancel()");
}, "A non-closed stream on which cancel() has been called");

test(() => {
  const stream = new ReadableStream({
    start(c) {
      c.close();
    }
  });
  const response = new Response(stream);
  assert_false(response.bodyUsed, "On construction");

  const reader = stream.getReader();
  assert_false(response.bodyUsed, "After getting a reader");

  reader.read();
  assert_true(response.bodyUsed, "After calling stream.read()");
}, "A closed stream on which read() has been called");

test(() => {
  const stream = new ReadableStream({
    start(c) {
      c.error(new Error("some error"));
    }
  });
  const response = new Response(stream);
  assert_false(response.bodyUsed, "On construction");

  const reader = stream.getReader();
  assert_false(response.bodyUsed, "After getting a reader");

  reader.read().then(() => { }, () => { });
  assert_true(response.bodyUsed, "After calling stream.read()");
}, "An errored stream on which read() has been called");

test(() => {
  const stream = new ReadableStream({
    start(c) {
      c.error(new Error("some error"));
    }
  });
  const response = new Response(stream);
  assert_false(response.bodyUsed, "On construction");

  const reader = stream.getReader();
  assert_false(response.bodyUsed, "After getting a reader");

  reader.cancel().then(() => { }, () => { });
  assert_true(response.bodyUsed, "After calling stream.cancel()");
}, "An errored stream on which cancel() has been called");