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..46f1ab83e7ecc52fa3271288f58ef4973f0938f8 |
--- /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() { |
yhirano
2015/10/14 10:28:49
Can you use promise_test instead of async_test?
Di
domenic
2015/10/14 16:25:30
My intention in importing the tests was to not spe
|
+ 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 theError = []; |
+ 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_throws(new RangeError(), function() { throw error; }, 'enqueue should throw a RangeError for ' + elements[i]); |
yhirano
2015/10/14 10:28:49
assert_equals(error.name, 'RangeError', ...);
domenic
2015/10/14 16:25:30
done
|
+ theError[i] = error; |
+ } |
+ } |
+ }, |
+ { |
+ size: function() { |
+ return elements[i]; |
+ }, |
+ highWaterMark: 5 |
+ }); |
+ |
+ var catchFunction = function(i, e) { |
+ assert_equals(e, theError[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(); |