Revision control

1
<!DOCTYPE html>
2
<script src='../resources/testharness.js'></script>
3
<script src='../resources/testharnessreport.js'></script>
4
<script src='reference-implementation/resources/streams-utils.js'></script>
5
<script>
7
8
let ReadableStreamDefaultReader = (new ReadableStream()).getReader().constructor;
9
10
function fakeWritableStream() {
11
return {
12
get closed() { return Promise.resolve(); },
13
get ready() { return Promise.resolve(); },
14
get state() { return 'closed' },
15
abort(reason) { return Promise.resolve(); },
16
close() { return Promise.resolve(); },
17
write(chunk) { return Promise.resolve(); }
18
};
19
}
20
21
function realReadableStream() {
22
return new ReadableStream();
23
}
24
25
function fakeReadableStream() {
26
return {
27
cancel: function(reason) { return Promise.resolve(); },
28
getReader: function() { return new ReadableStreamDefaultReader(new ReadableStream()); },
29
pipeThrough: function(obj, options) { return obj.readable; },
30
pipeTo: function() { return Promise.resolve(); },
31
tee: function() { return [realReadableStream(), realReadableStream()]; }
32
};
33
}
34
35
test(function() {
36
var pipeToArguments;
37
var thisValue = {
38
pipeTo: function() {
39
pipeToArguments = arguments;
40
}
41
};
42
43
var input = { readable: {}, writable: {} };
44
var options = {};
45
var result = ReadableStream.prototype.pipeThrough.call(thisValue, input, options);
46
47
assert_array_equals(pipeToArguments, [input.writable, options], 'correct arguments should be passed to thisValue.pipeTo');
48
assert_equals(result, input.readable, 'return value should be the passed readable property');
49
}, 'ReadableStream.prototype.pipeThrough works generically on its this and its arguments');
50
51
test(function() {
52
ReadableStream.prototype.pipeTo.call(fakeReadableStream(), fakeWritableStream()); // Check it does not throw.
53
}, 'ReadableStream.prototype.pipeTo works generically on its this and its arguments');
54
55
test(function() {
56
var thisValue = null;
57
var returnValue = { 'returned from': 'byteLength getter' };
58
var chunk = {
59
get byteLength() {
60
return returnValue;
61
}
62
};
63
64
assert_equals(ByteLengthQueuingStrategy.prototype.size.call(thisValue, chunk), returnValue);
65
}, 'ByteLengthQueuingStrategy.prototype.size should work generically on its this and its arguments');
66
67
test(function() {
68
var thisValue = null;
69
var chunk = {
70
get byteLength() {
71
throw new TypeError('shouldn\'t be called');
72
}
73
};
74
75
assert_equals(CountQueuingStrategy.prototype.size.call(thisValue, chunk), 1);
76
}, 'CountQueuingStrategy.prototype.size should work generically on its this and its arguments');
77
</script>