From 1245636156509c9f1ef16df320f9f55f5d248d53 Mon Sep 17 00:00:00 2001 From: Adam Rice Date: Sun, 25 Nov 2018 23:06:50 -0800 Subject: [PATCH] Add tests that subclassing {Transform,Writable}Stream works Change-Id: Iba151bf31367c06c94311402a9fc550d7bb87a6d --- streams/transform-streams/general.any.js | 24 ++++++++++++++++++++++++ streams/writable-streams/general.any.js | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/streams/transform-streams/general.any.js b/streams/transform-streams/general.any.js index 533797b9d1ad3a..0b012a91a90f3a 100644 --- a/streams/transform-streams/general.any.js +++ b/streams/transform-streams/general.any.js @@ -437,3 +437,27 @@ test(() => { test(() => { assert_throws(new RangeError(), () => new TransformStream({ writableType: 'bytes' }), 'constructor should throw'); }, 'specifying a defined writableType should throw'); + +test(() => { + class Subclass extends TransformStream { + extraFunction() { + return true; + } + } + assert_equals( + Object.getPrototypeOf(Subclass.prototype), TransformStream.prototype, + 'Subclass.prototype\'s prototype should be TransformStream.prototype'); + assert_equals(Object.getPrototypeOf(Subclass), TransformStream, + 'Subclass\'s prototype should be TransformStream'); + const sub = new Subclass(); + assert_true(sub instanceof TransformStream, + 'Subclass object should be an instance of TransformStream'); + assert_true(sub instanceof Subclass, + 'Subclass object should be an instance of Subclass'); + const readableGetter = Object.getOwnPropertyDescriptor( + TransformStream.prototype, 'readable').get; + assert_equals(readableGetter.call(sub), sub.readable, + 'Subclass object should pass brand check'); + assert_true(sub.extraFunction(), + 'extraFunction() should be present on Subclass object'); +}, 'Subclassing TransformStream should work'); diff --git a/streams/writable-streams/general.any.js b/streams/writable-streams/general.any.js index ddf616ef867226..6ddae1f8a3e9dd 100644 --- a/streams/writable-streams/general.any.js +++ b/streams/writable-streams/general.any.js @@ -244,3 +244,27 @@ promise_test(() => { }); }); }, 'ready promise should fire before closed on releaseLock'); + +test(() => { + class Subclass extends WritableStream { + extraFunction() { + return true; + } + } + assert_equals( + Object.getPrototypeOf(Subclass.prototype), WritableStream.prototype, + 'Subclass.prototype\'s prototype should be WritableStream.prototype'); + assert_equals(Object.getPrototypeOf(Subclass), WritableStream, + 'Subclass\'s prototype should be WritableStream'); + const sub = new Subclass(); + assert_true(sub instanceof WritableStream, + 'Subclass object should be an instance of WritableStream'); + assert_true(sub instanceof Subclass, + 'Subclass object should be an instance of Subclass'); + const lockedGetter = Object.getOwnPropertyDescriptor( + WritableStream.prototype, 'locked').get; + assert_equals(lockedGetter.call(sub), sub.locked, + 'Subclass object should pass brand check'); + assert_true(sub.extraFunction(), + 'extraFunction() should be present on Subclass object'); +}, 'Subclassing WritableStream should work');