Skip to content

Commit

Permalink
Initial Merge of WritableStreams Tests w/Upstream W3C (#6499)
Browse files Browse the repository at this point in the history
Clean ups of WritableStream general tests.
  • Loading branch information
Brandr0id authored and ricea committed May 23, 2018
1 parent 347a797 commit a695026
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
46 changes: 22 additions & 24 deletions streams/writable-streams/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,56 +111,54 @@ promise_test(() => {
);
}, 'closed and ready on a released writer');

promise_test(() => {
const promises = {};
const resolvers = {};
for (const methodName of ['start', 'write', 'close', 'abort']) {
promises[methodName] = new Promise(resolve => {
resolvers[methodName] = resolve;
});
}

promise_test(t => {
let thisObject = null;
// Calls to Sink methods after the first are implicitly ignored. Only the first value that is passed to the resolver
// is used.
class Sink {
start() {
// Called twice
resolvers.start(this);
t.step(() => {
assert_equals(this, thisObject, 'start should be called as a method');
});
}

write() {
resolvers.write(this);
t.step(() => {
assert_equals(this, thisObject, 'write should be called as a method');
});
}

close() {
resolvers.close(this);
t.step(() => {
assert_equals(this, thisObject, 'close should be called as a method');
});
}

abort() {
resolvers.abort(this);
t.step(() => {
assert_equals(this, thisObject, 'abort should be called as a method');
});
}
}

const theSink = new Sink();
thisObject = theSink;
const ws = new WritableStream(theSink);

const writer = ws.getWriter();

writer.write('a');
writer.close();
const closePromise = writer.close();

const ws2 = new WritableStream(theSink);
const writer2 = ws2.getWriter();
writer2.abort();

return promises.start
.then(thisValue => assert_equals(thisValue, theSink, 'start should be called as a method'))
.then(() => promises.write)
.then(thisValue => assert_equals(thisValue, theSink, 'write should be called as a method'))
.then(() => promises.close)
.then(thisValue => assert_equals(thisValue, theSink, 'close should be called as a method'))
.then(() => promises.abort)
.then(thisValue => assert_equals(thisValue, theSink, 'abort should be called as a method'));
const abortPromise = writer2.abort();

return Promise.all([
closePromise,
abortPromise
]);
}, 'WritableStream should call underlying sink methods as methods');

promise_test(t => {
Expand Down
2 changes: 1 addition & 1 deletion streams/writable-streams/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ promise_test(t => {
start() {
return Promise.reject();
}
}, new CountQueuingStrategy({ highWaterMark: 0 }));
}, { highWaterMark: 0 });
const writer = ws.getWriter();
catchAndRecord(writer.ready, 'ready');
catchAndRecord(writer.closed, 'closed');
Expand Down

0 comments on commit a695026

Please sign in to comment.