Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

3.4 KB
Raw Blame
<!doctype html>
<meta charset="utf-8">
<script src="/wpt/resources/testharness.js"></script>
<script src="/wpt/resources/testharnessreport.js"></script>
<script src="/wpt/resources/moli-wpt-adapter.js"></script>
<script src="/wpt/resources/WebIDLParser.js"></script>
<script src="/wpt/resources/idlharness.js"></script>
<script>
idl_test([`
interface ReadableStream {
  constructor(optional object underlyingSource, optional object strategy);
  readonly attribute boolean locked;
  Promise<undefined> cancel(optional any reason);
  object getReader();
  ReadableStream pipeThrough(object transform, optional object options);
  Promise<undefined> pipeTo(WritableStream destination, optional object options);
};

interface WritableStream {
  constructor(optional object underlyingSink, optional object strategy);
  readonly attribute boolean locked;
  object getWriter();
};

interface TransformStream {
  constructor(optional object transformer, optional object writableStrategy, optional object readableStrategy);
  readonly attribute ReadableStream readable;
  readonly attribute WritableStream writable;
};

interface TextEncoderStream {
  constructor();
  readonly attribute DOMString encoding;
  readonly attribute ReadableStream readable;
  readonly attribute WritableStream writable;
};

interface TextDecoderStream {
  constructor(optional DOMString label = "utf-8", optional object options);
  readonly attribute DOMString encoding;
  readonly attribute boolean fatal;
  readonly attribute boolean ignoreBOM;
  readonly attribute ReadableStream readable;
  readonly attribute WritableStream writable;
};
`], [], function (idlArray) {
  idlArray.enable_function_length_assertions();
  idlArray.enable_interface_descriptor_assertions();
  idlArray.enable_operation_descriptor_assertions();
  idlArray.enable_object_brand_assertions();
  idlArray.add_objects({
    ReadableStream: ["new ReadableStream()"],
    WritableStream: ["new WritableStream()"],
    TransformStream: ["new TransformStream()"],
    TextEncoderStream: ["new TextEncoderStream()"],
    TextDecoderStream: ["new TextDecoderStream()"]
  });
});

promise_test(async function () {
  const input = new ReadableStream({
    start(controller) {
      controller.enqueue("x");
      controller.close();
    }
  });
  const transform = new TransformStream({
    transform(chunk, controller) {
      controller.enqueue(chunk + "y");
    }
  });
  const transformed = input.pipeThrough(transform);
  const read = await transformed.getReader().read();

  assert_equals(read.value, "xy");
  assert_false(read.done);
  assert_equals(Object.prototype.toString.call(input), "[object ReadableStream]");
  assert_equals(Object.prototype.toString.call(new WritableStream()), "[object WritableStream]");
  assert_equals(Object.prototype.toString.call(transform), "[object TransformStream]");
  assert_equals(Object.prototype.toString.call(new TextEncoderStream()), "[object TextEncoderStream]");
  assert_equals(Object.prototype.toString.call(new TextDecoderStream()), "[object TextDecoderStream]");
}, "Streams idlharness sample pipes chunks and exposes object brands");

promise_test(async function () {
  let cancelReason = null;
  const stream = new ReadableStream({
    cancel(reason) {
      cancelReason = reason;
    }
  });

  await stream.cancel("stop");
  assert_equals(cancelReason, "stop");
}, "ReadableStream.cancel() forwards the reason to the underlying source");
</script>