Revision control

1
<!DOCTYPE html>
2
<script src='../resources/testharness.js'></script>
3
<script src='../resources/testharnessreport.js'></script>
4
<script>
6
7
var test1 = async_test('Reading twice on a stream that gets closed');
8
test1.step(function() {
9
var controller;
10
var rs = new ReadableStream({
11
start: function(c) {
12
controller = c;
13
}
14
});
15
var counter = 0;
16
var reader = rs.getReader();
17
18
reader.read().then(test1.step_func(function(result) {
19
assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
20
assert_equals(++counter, 1);
21
}));
22
reader.read().then(test1.step_func(function(result) {
23
assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
24
assert_equals(++counter, 2);
25
}));
26
reader.closed.then(test1.step_func(function() {
27
assert_equals(++counter, 3);
28
test1.done();
29
}));
30
31
controller.close();
32
});
33
34
var test2 = async_test('Reading twice on a closed stream');
35
test2.step(function() {
36
var controller;
37
var rs = new ReadableStream({
38
start: function(c) {
39
controller = c;
40
}
41
});
42
43
controller.close();
44
45
var counter = 0;
46
var reader = rs.getReader();
47
48
reader.read().then(test2.step_func(function(result) {
49
assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
50
assert_equals(counter, 0);
51
counter++;
52
}));
53
reader.read().then(test2.step_func(function(result) {
54
assert_object_equals(result, { value: undefined, done: true }, 'read() should fulfill with close');
55
assert_equals(counter, 1);
56
counter++;
57
}));
58
reader.closed.then(test2.step_func(function() {
59
assert_equals(counter, 2);
60
counter++;
61
test2.done();
62
}));
63
});
64
65
var test3 = async_test('Reading twice on an errored stream');
66
test3.step(function() {
67
var controller;
68
var rs = new ReadableStream({
69
start: function(c) {
70
controller = c;
71
}
72
});
73
74
var myError = { potato: "mashed" };
75
controller.error(myError);
76
77
var counter = 0;
78
var reader = rs.getReader();
79
80
reader.read().then(test3.step_func(function() {
81
assert_unreached('read() should reject on an errored stream');
82
}), test3.step_func(function(err) {
83
assert_equals(myError, err);
84
assert_equals(counter, 0);
85
counter++;
86
}));
87
reader.read().then(test3.step_func(function() {
88
assert_unreached('read() should reject on an errored stream');
89
}), test3.step_func(function(err) {
90
assert_equals(myError, err);
91
assert_equals(counter, 1);
92
counter++;
93
}));
94
reader.closed.then(test3.step_func(function() {
95
assert_unreached('read() should reject on an errored stream');
96
}), test3.step_func(function(err) {
97
assert_equals(myError, err);
98
assert_equals(counter, 2);
99
counter++;
100
test3.done();
101
}));
102
});
103
104
var test4 = async_test('Reading twice on a stream that gets errored');
105
test4.step(function() {
106
var controller;
107
var rs = new ReadableStream({
108
start: function(c) {
109
controller = c;
110
}
111
});
112
113
var counter = 0;
114
var reader = rs.getReader();
115
116
reader.read().then(test4.step_func(function() {
117
assert_unreached('read() should reject on an errored stream');
118
}), test4.step_func(function(err) {
119
assert_equals(myError, err);
120
assert_equals(++counter, 1);
121
}));
122
reader.read().then(test4.step_func(function() {
123
assert_unreached('read() should reject on an errored stream');
124
}), test4.step_func(function(err) {
125
assert_equals(myError, err);
126
assert_equals(++counter, 2);
127
}));
128
reader.closed.then(test4.step_func(function() {
129
assert_unreached('read() should reject on an errored stream');
130
}), test4.step_func(function(err) {
131
assert_equals(myError, err);
132
assert_equals(++counter, 3);
133
test4.done();
134
}));
135
136
var myError = { potato: 'mashed' };
137
controller.error(myError);
138
});
139
140
var test5 = async_test('ReadableStream: if start rejects with no parameter, it should error the stream with an undefined error');
141
test5.step(function() {
142
var rs = new ReadableStream({
143
start: function(c) {
144
return Promise.reject();
145
}
146
});
147
148
rs.getReader().read().catch(test5.step_func(function(e) {
149
assert_equals(typeof e, "undefined");
150
test5.done();
151
}));
152
});
153
</script>