| Index: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-strategies.js
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-strategies.js b/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-strategies.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0fa63d68eef4cb8442bce1db6b2580fa2910f195
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-strategies.js
|
| @@ -0,0 +1,117 @@
|
| +'use strict';
|
| +
|
| +if (self.importScripts) {
|
| + self.importScripts('/resources/testharness.js');
|
| +}
|
| +
|
| +test(function() {
|
| + var theError = new Error('a unique string');
|
| +
|
| + assert_throws(theError, function() {
|
| + new ReadableStream({}, {
|
| + get size() {
|
| + throw theError;
|
| + },
|
| + highWaterMark: 5
|
| + });
|
| + }, 'construction should re-throw the error');
|
| +}, 'Readable stream: throwing strategy.size getter');
|
| +
|
| +var test1 = async_test('Readable stream: throwing strategy.size method');
|
| +test1.step(function() {
|
| + var theError = new Error('a unique string');
|
| + var rs = new ReadableStream(
|
| + {
|
| + start: function(c) {
|
| + assert_throws(theError, function() { c.enqueue('a'); }, 'enqueue should throw the error');
|
| + }
|
| + },
|
| + {
|
| + size: function() {
|
| + throw theError;
|
| + },
|
| + highWaterMark: 5
|
| + }
|
| + );
|
| +
|
| + rs.getReader().closed.catch(test1.step_func(function(e) {
|
| + assert_equals(e, theError, 'closed should reject with the error');
|
| + test1.done();
|
| + }))
|
| +});
|
| +
|
| +test(function() {
|
| + var theError = new Error('a unique string');
|
| +
|
| + assert_throws(theError, function() {
|
| + new ReadableStream({}, {
|
| + size: function() {
|
| + return 1;
|
| + },
|
| + get highWaterMark() {
|
| + throw theError;
|
| + }
|
| + });
|
| + }, 'construction should re-throw the error');
|
| +}, 'Readable stream: throwing strategy.highWaterMark getter');
|
| +
|
| +test(function() {
|
| + for (var highWaterMark of [-1, -Infinity]) {
|
| + assert_throws(new RangeError(), function() {
|
| + new ReadableStream({}, {
|
| + size: function() {
|
| + return 1;
|
| + },
|
| + highWaterMark
|
| + });
|
| + }, 'construction should throw a RangeError for ' + highWaterMark);
|
| + }
|
| +
|
| + for (var highWaterMark of [NaN, 'foo', {}]) {
|
| + assert_throws(new TypeError(), function() {
|
| + new ReadableStream({}, {
|
| + size: function() {
|
| + return 1;
|
| + },
|
| + highWaterMark
|
| + });
|
| + }, 'construction should throw a TypeError for ' + highWaterMark);
|
| + }
|
| +}, 'Readable stream: invalid strategy.highWaterMark');
|
| +
|
| +var test2 = async_test('Readable stream: invalid strategy.size return value');
|
| +test2.step(function() {
|
| + var numberOfCalls = 0;
|
| + var elements = [NaN, -Infinity, +Infinity, -1];
|
| + var theErrors = [];
|
| + for (var i = 0; i < elements.length; i++) {
|
| + var rs = new ReadableStream({
|
| + start: function(c) {
|
| + try {
|
| + c.enqueue('hi');
|
| + assert_unreached('enqueue didn\'t throw');
|
| + } catch (error) {
|
| + assert_equals(error.name, 'RangeError', 'enqueue should throw a RangeError for ' + elements[i]);
|
| + theErrors[i] = error;
|
| + }
|
| + }
|
| + },
|
| + {
|
| + size: function() {
|
| + return elements[i];
|
| + },
|
| + highWaterMark: 5
|
| + });
|
| +
|
| + var catchFunction = function(i, e) {
|
| + assert_equals(e, theErrors[i], 'closed should reject with the error for ' + elements[i]);
|
| + if (++numberOfCalls === elements.length) {
|
| + test2.done();
|
| + }
|
| + };
|
| +
|
| + rs.getReader().closed.catch(test2.step_func(catchFunction.bind(this, i)));
|
| + }
|
| +});
|
| +
|
| +done();
|
|
|