| <!DOCTYPE html> |
| <script src='../../resources/testharness.js'></script> |
| <script src='../../resources/testharnessreport.js'></script> |
| <script src='resources/streams-utils.js'></script> |
| <script> |
| // This is updated till https://github.com/whatwg/streams/commit/4ba861e6f60c248060811830e11271c84b439cc3 |
| |
| function fakeWritableStream() { |
| return { |
| get closed() { return Promise.resolve(); }, |
| get ready() { return Promise.resolve(); }, |
| get state() { return 'closed' }, |
| abort(reason) { return Promise.resolve(); }, |
| close() { return Promise.resolve(); }, |
| write(chunk) { return Promise.resolve(); } |
| }; |
| } |
| |
| function realReadableStream() { |
| return new ReadableStream(); |
| } |
| |
| function getterRejects(test, obj, getterName, target, endTest) { |
| var getter = Object.getOwnPropertyDescriptor(obj, getterName).get; |
| |
| getter.call(target).then( |
| test.step_func(function() { assert_unreached(getterName + ' should not fulfill'); }), |
| test.step_func(function(e) { |
| assert_throws(new TypeError(), function() { throw e; }, getterName + ' should reject with a TypeError'); |
| if (endTest === true) { |
| test.done(); |
| } |
| })); |
| } |
| |
| function methodRejects(test, obj, methodName, target, endTest) { |
| var method = obj[methodName]; |
| |
| method.call(target).then( |
| test.step_func(function() { assert_unreached(methodName + ' should not fulfill'); }), |
| test.step_func(function(e) { |
| assert_throws(new TypeError(), function() { throw e; }, methodName + ' should reject with a TypeError'); |
| if (endTest === true) { |
| test.done(); |
| } |
| })); |
| } |
| |
| function getterThrows(obj, getterName, target) { |
| var getter = Object.getOwnPropertyDescriptor(obj, getterName).get; |
| |
| assert_throws(new TypeError(), function() { getter.call(target); }, getterName + ' should throw a TypeError'); |
| } |
| |
| var test1 = async_test('WritableStream.prototype.closed enforces a brand check'); |
| test1.step(function() { |
| getterRejects(test1, WritableStream.prototype, 'closed', fakeWritableStream()); |
| getterRejects(test1, WritableStream.prototype, 'closed', realReadableStream(), true); |
| }); |
| |
| var test2 = async_test('WritableStream.prototype.ready enforces a brand check'); |
| test2.step(function() { |
| getterRejects(test2, WritableStream.prototype, 'ready', fakeWritableStream()); |
| getterRejects(test2, WritableStream.prototype, 'ready', realReadableStream(), true); |
| }); |
| |
| test(function() { |
| getterThrows(WritableStream.prototype, 'state', fakeWritableStream()); |
| getterThrows(WritableStream.prototype, 'state', realReadableStream()); |
| }, 'WritableStream.prototype.state enforces a brand check'); |
| |
| var test3 = async_test('WritableStream.prototype.abort enforces a brand check'); |
| test3.step(function() { |
| methodRejects(test3, WritableStream.prototype, 'abort', fakeWritableStream()); |
| methodRejects(test3, WritableStream.prototype, 'abort', realReadableStream(), true); |
| }); |
| |
| var test4 = async_test('WritableStream.prototype.write enforces a brand check'); |
| test4.step(function() { |
| methodRejects(test4, WritableStream.prototype, 'write', fakeWritableStream()); |
| methodRejects(test4, WritableStream.prototype, 'write', realReadableStream(), true); |
| }); |
| |
| var test5 = async_test('WritableStream.prototype.close enforces a brand check'); |
| test5.step(function() { |
| methodRejects(test5, WritableStream.prototype, 'close', fakeWritableStream()); |
| methodRejects(test5, WritableStream.prototype, 'close', realReadableStream(), true); |
| }); |
| </script> |