Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-underlying-sources.js

Issue 1404523005: Implement author-constructible ReadableStream using V8 extras (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-underlying-sources.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-underlying-sources.js b/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-underlying-sources.js
new file mode 100644
index 0000000000000000000000000000000000000000..3f2de70b63119a7d58c5ae056b2e17799470caf6
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/streams/readable-streams/bad-underlying-sources.js
@@ -0,0 +1,379 @@
+'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 start() {
+ throw theError;
+ }
+ });
+ }, 'constructing the stream should re-throw the error');
+}, 'Underlying source start: throwing getter');
+
+test(function() {
+ var theError = new Error('a unique string');
+
+ assert_throws(theError, function() {
+ new ReadableStream({
+ start: function() {
+ throw theError;
+ }
+ });
+ }, 'constructing the stream should re-throw the error');
+}, 'Underlying source start: throwing method');
+
+var test1 = async_test('Underlying source: throwing pull getter (initial pull)');
+test1.step(function() {
+ var theError = new Error('a unique string');
+ var rs = new ReadableStream({
+ get pull() {
+ throw theError;
+ }
+ });
+
+ rs.getReader().closed.then(
+ test1.step_func(function() { assert_unreached('closed should not fulfill'); }),
+ test1.step_func(function(r) {
+ assert_equals(r, theError, 'closed should reject with the thrown error');
+ test1.done();
+ }));
+});
+
+var test2 = async_test('Underlying source: throwing pull method (initial pull)');
+test2.step(function() {
+ var theError = new Error('a unique string');
+ var rs = new ReadableStream({
+ pull: function() {
+ throw theError;
+ }
+ });
+
+ rs.getReader().closed.then(
+ test2.step_func(function() { assert_unreached('closed should not fulfill'); }),
+ test2.step_func(function(r) {
+ assert_equals(r, theError, 'closed should reject with the thrown error');
+ test2.done();
+ }));
+});
+
+var test3 = async_test('Underlying source: throwing pull getter (second pull)');
+test3.step(function() {
+ var theError = new Error('a unique string');
+ var counter = 0;
+ var rs = new ReadableStream({
+ get pull() {
+ ++counter;
+ if (counter === 1) {
+ return test3.step_func(function(c) { c.enqueue('a'); })
+ }
+
+ throw theError;
+ }
+ });
+ var reader = rs.getReader();
+
+ reader.read().then(test3.step_func(function(r) {
+ assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct');
+ }));
+
+ reader.closed.then(
+ test3.step_func(function() { assert_unreached('closed should not fulfill'); }),
+ test3.step_func(function(r) {
+ assert_equals(r, theError, 'closed should reject with the thrown error');
+ test3.done();
+ }));
+});
+
+var test4 = async_test('Underlying source: throwing pull method (second pull)');
+test4.step(function() {
+ var theError = new Error('a unique string');
+ var counter = 0;
+ var rs = new ReadableStream({
+ pull: function(c) {
+ ++counter;
+ if (counter === 1) {
+ c.enqueue('a');
+ } else {
+ throw theError;
+ }
+ }
+ });
+ var reader = rs.getReader();
+
+ reader.read().then(test4.step_func(function(r) { assert_object_equals(r, { value: 'a', done: false }, 'the chunk read should be correct'); }));
+
+ reader.closed.then(
+ test4.step_func(function() { assert_unreached('closed should not fulfill'); }),
+ test4.step_func(function(r) {
+ assert_equals(r, theError, 'closed should reject with the thrown error');
+ test4.done();
+ }));
+});
+
+var test5 = async_test('Underlying source: throwing cancel getter');
+test5.step(function() {
+ var theError = new Error('a unique string');
+ var rs = new ReadableStream({
+ get cancel() {
+ throw theError;
+ }
+ });
+
+ rs.cancel().then(
+ test5.step_func(function() { assert_unreached('cancel should not fulfill'); }),
+ test5.step_func(function(r) {
+ assert_equals(r, theError, 'cancel should reject with the thrown error');
+ test5.done();
+ }));
+});
+
+var test6 = async_test('Underlying source: throwing cancel method');
+test6.step(function() {
+ var theError = new Error('a unique string');
+ var rs = new ReadableStream({
+ cancel: function() {
+ throw theError;
+ }
+ });
+
+ rs.cancel().then(
+ test6.step_func(function() { assert_unreached('cancel should not fulfill'); }),
+ test6.step_func(function(r) {
+ assert_equals(r, theError, 'cancel should reject with the thrown error');
+ test6.done();
+ }));
+});
+
+var test7 = async_test('Underlying source: calling enqueue on an empty canceled stream should not throw');
+test7.step(function() {
+ var controller;
+ var rs = new ReadableStream({
+ start: function(c) {
+ controller = c;
+ }
+ });
+
+ rs.cancel();
+ controller.enqueue('a') // Calling enqueue after canceling should not throw anything.
+
+ rs.getReader().closed.then(test7.step_func(function() {
+ test7.done('closed should fulfill');
+ }));
+});
+
+var test8 = async_test('Underlying source: calling enqueue on a non-empty canceled stream should not throw');
+test8.step(function() {
+ var controller;
+ var rs = new ReadableStream({
+ start: function(c) {
+ c.enqueue('a');
+ c.enqueue('b');
+ controller = c;
+ }
+ });
+
+ rs.cancel();
+ controller.enqueue('c') // Calling enqueue after canceling should not throw anything.
+
+ rs.getReader().closed.then(test8.step_func(function() {
+ test8.done('closed should fulfill');
+ }));
+});
+
+var test9 = async_test('Underlying source: calling enqueue on a closed stream should throw');
+test9.step(function() {
+ new ReadableStream({
+ start: function(c) {
+ c.close();
+ assert_throws(new TypeError(), function() { c.enqueue('a') }, 'call to enqueue should throw a TypeError');
+ }
+ }).getReader().closed.then(test9.step_func(function() {
+ test9.done('closed should fulfill');
+ }));
+});
+
+var test10 = async_test('Underlying source: calling enqueue on an errored stream should throw');
+test10.step(function() {
+ var theError = new Error('boo');
+ new ReadableStream({
+ start: function(c) {
+ c.error(theError);
+ assert_throws(theError, function() { c.enqueue('a') }, 'call to enqueue should throw the error');
+ }
+ }).getReader().closed.catch(test10.step_func(function(e) {
+ assert_equals(e, theError, 'closed should reject with the error');
+ test10.done();
+ }));
+});
+
+var test11 = async_test('Underlying source: calling close twice on an empty stream should throw the second time');
+test11.step(function() {
+ new ReadableStream({
+ start: function(c) {
+ c.close();
+ assert_throws(new TypeError(), c.close, 'second call to close should throw a TypeError');
+ }
+ }).getReader().closed.then(test11.step_func(function() { test11.done('closed should fulfill'); }));
+});
+
+var test12 = async_test('Underlying source: calling close twice on a non-empty stream should throw the second time');
+test12.step(function() {
+ var startCalled = false;
+ var readCalled = false;
+ var reader = new ReadableStream({
+ start: function(c) {
+ c.enqueue('a');
+ c.close();
+ assert_throws(new TypeError(), c.close, 'second call to close should throw a TypeError');
+ startCalled = true;
+ }
+ }).getReader();
+
+ reader.read().then(test12.step_func(function(r) {
+ assert_object_equals(r, { value: 'a', done: false }, 'read() should read the enqueued chunk');
+ readCalled = true;
+ }));
+ reader.closed.then(test12.step_func(function() {
+ assert_true(startCalled);
+ assert_true(readCalled);
+ test12.done('closed should fulfill');
+ }));
+});
+
+var test13 = async_test('Underlying source: calling close on an empty canceled stream should not throw');
+test13.step(function() {
+ var controller;
+ var startCalled = false;
+ var rs = new ReadableStream({
+ start: function(c) {
+ controller = c;
+ startCalled = true;
+ }
+ });
+
+ rs.cancel();
+ controller.close(); // Calling close after canceling should not throw anything.
+
+ rs.getReader().closed.then(test13.step_func(function() {
+ assert_true(startCalled);
+ test13.done('closed should fulfill');
+ }));
+});
+
+var test14 = async_test('Underlying source: calling close on a non-empty canceled stream should not throw');
+test14.step(function() {
+ var controller;
+ var startCalled = false;
+ var rs = new ReadableStream({
+ start: function(c) {
+ controller = c;
+ c.enqueue('a');
+ startCalled = true;
+ }
+ });
+
+ rs.cancel();
+ controller.close(); // Calling close after canceling should not throw anything.
+
+ rs.getReader().closed.then(test14.step_func(function() {
+ assert_true(startCalled);
+ test14.done('closed should fulfill');
+ }));
+});
+
+var test15 = async_test('Underlying source: calling close after error should throw');
+test15.step(function() {
+ var theError = new Error('boo');
+ var startCalled = false;
+ new ReadableStream({
+ start: function(c) {
+ c.error(theError);
+ assert_throws(new TypeError(), c.close, 'call to close should throw a TypeError');
+ startCalled = true;
+ }
+ }).getReader().closed.catch(test15.step_func(function(e) {
+ assert_true(startCalled);
+ assert_equals(e, theError, 'closed should reject with the error')
+ test15.done();
+ }));
+});
+
+var test16 = async_test('Underlying source: calling error twice should throw the second time');
+test16.step(function() {
+ var theError = new Error('boo');
+ var startCalled = false;
+ new ReadableStream({
+ start: function(c) {
+ c.error(theError);
+ assert_throws(new TypeError(), c.error, 'second call to error should throw a TypeError');
+ startCalled = true;
+ }
+ }).getReader().closed.catch(test16.step_func(function(e) {
+ assert_true(startCalled);
+ assert_equals(e, theError, 'closed should reject with the error');
+ test16.done();
+ }));
+});
+
+var test17 = async_test('Underlying source: calling error after close should throw');
+test17.step(function() {
+ var startCalled = false;
+ new ReadableStream({
+ start: function(c) {
+ c.close();
+ assert_throws(new TypeError(), c.error, 'call to error should throw a TypeError');
+ startCalled = true;
+ }
+ }).getReader().closed.then(test17.step_func(function() {
+ assert_true(startCalled);
+ test17.done('closed should fulfill');
+ }));
+});
+
+var test18 = async_test('Underlying source: calling error and returning a rejected promise from start should cause the stream to error with the first error');
+test18.step(function() {
+ var startCalled = false;
+ var firstError = new Error('1');
+ var secondError = new Error('2');
+ new ReadableStream({
+ start: function(c) {
+ c.error(firstError);
+
+ startCalled = true;
+
+ return Promise.reject(secondError);
+ }
+ }).getReader().closed.catch(test18.step_func(function(e) {
+ assert_true(startCalled);
+ assert_equals(e, firstError, 'stream should error with the first error');
+ test18.done();
+ }));
+});
+
+var test19 = async_test('Underlying source: calling error and returning a rejected promise from pull should cause the stream to error with the first error');
+test19.step(function() {
+ var startCalled = false;
+ var firstError = new Error('1');
+ var secondError = new Error('2');
+ new ReadableStream({
+ pull: function(c) {
+ c.error(firstError);
+
+ startCalled = true;
+
+ return Promise.reject(secondError);
+ }
+ }).getReader().closed.catch(test19.step_func(function(e) {
+ assert_true(startCalled);
+ assert_equals(e, firstError, 'stream should error with the first error');
+ test19.done();
+ }));
+});
+
+done();

Powered by Google App Engine
This is Rietveld 408576698