• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: global=window,worker
2'use strict';
3
4const sinkMethods = {
5  start: {
6    length: 1,
7    trigger: () => Promise.resolve()
8  },
9  write: {
10    length: 2,
11    trigger: writer => writer.write()
12  },
13  close: {
14    length: 0,
15    trigger: writer => writer.close()
16  },
17  abort: {
18    length: 1,
19    trigger: writer => writer.abort()
20  }
21};
22
23for (const method in sinkMethods) {
24  const { length, trigger } = sinkMethods[method];
25
26  // Some semantic tests of how sink methods are called can be found in general.js, as well as in the test files
27  // specific to each method.
28  promise_test(() => {
29    let argCount;
30    const ws = new WritableStream({
31      [method](...args) {
32        argCount = args.length;
33      }
34    });
35    return Promise.resolve(trigger(ws.getWriter())).then(() => {
36      assert_equals(argCount, length, `${method} should be called with ${length} arguments`);
37    });
38  }, `sink method ${method} should be called with the right number of arguments`);
39
40  promise_test(() => {
41    let methodWasCalled = false;
42    function Sink() {}
43    Sink.prototype = {
44      [method]() {
45        methodWasCalled = true;
46      }
47    };
48    const ws = new WritableStream(new Sink());
49    return Promise.resolve(trigger(ws.getWriter())).then(() => {
50      assert_true(methodWasCalled, `${method} should be called`);
51    });
52  }, `sink method ${method} should be called even when it's located on the prototype chain`);
53}
54