Commit bb410933 authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

serial: Enable tests in workers

Enable most of the existing internal Web Platform Tests for the Web
Serial API in worker contexts. The easiest way to make them work in the
new context was to migrate to using test-only-api.js to load scripts at
runtime. This will also make it easier to upstream these to the WPT repo
later.

Bug: 884928
Change-Id: If5e4219bfc51c39f50d0188c7281ba325c0ab5e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2572693
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834512}
parent 49120be0
...@@ -12,418 +12,19 @@ async function getFakeSerialPort(fake) { ...@@ -12,418 +12,19 @@ async function getFakeSerialPort(fake) {
return { port, fakePort }; return { port, fakePort };
} }
// Implementation of an UnderlyingSource to create a ReadableStream from a Mojo let fakeSerialService = undefined;
// data pipe consumer handle.
class DataPipeSource {
constructor(consumer) {
this.consumer_ = consumer;
}
async pull(controller) {
let chunk = new ArrayBuffer(64);
let {result, numBytes} = this.consumer_.readData(chunk);
if (result == Mojo.RESULT_OK) {
controller.enqueue(new Uint8Array(chunk, 0, numBytes));
return;
} else if (result == Mojo.RESULT_FAILED_PRECONDITION) {
controller.close();
return;
} else if (result == Mojo.RESULT_SHOULD_WAIT) {
await this.readable();
return this.pull(controller);
}
}
cancel() {
if (this.watcher_)
this.watcher_.cancel();
this.consumer_.close();
}
readable() {
return new Promise((resolve) => {
this.watcher_ =
this.consumer_.watch({ readable: true, peerClosed: true }, () => {
this.watcher_.cancel();
this.watcher_ = undefined;
resolve();
});
});
}
}
// Implementation of an UnderlyingSink to create a WritableStream from a Mojo
// data pipe producer handle.
class DataPipeSink {
constructor(producer) {
this._producer = producer;
}
async write(chunk, controller) {
while (true) {
let {result, numBytes} = this._producer.writeData(chunk);
if (result == Mojo.RESULT_OK) {
if (numBytes == chunk.byteLength) {
return;
}
chunk = chunk.slice(numBytes);
} else if (result == Mojo.RESULT_FAILED_PRECONDITION) {
throw new DOMException('The pipe is closed.', 'InvalidStateError');
} else if (result == Mojo.RESULT_SHOULD_WAIT) {
await this.writable();
}
}
}
close() {
assert_equals(undefined, this._watcher);
this._producer.close();
}
abort(reason) {
if (this._watcher)
this._watcher.cancel();
this._producer.close();
}
writable() {
return new Promise((resolve) => {
this._watcher =
this._producer.watch({ writable: true, peerClosed: true }, () => {
this._watcher.cancel();
this._watcher = undefined;
resolve();
});
});
}
}
// Implementation of blink.mojom.SerialPort.
class FakeSerialPort {
constructor() {
this.inputSignals_ = {
dataCarrierDetect: false,
clearToSend: false,
ringIndicator: false,
dataSetReady: false
};
this.outputSignals_ = {
dataTerminalReady: false,
requestToSend: false,
break: false
};
}
open(options, client) {
if (this.binding_ !== undefined) {
// Port already open.
return null;
}
let portPtr = new device.mojom.SerialPortPtr();
this.binding_ = new mojo.Binding(
device.mojom.SerialPort, this, mojo.makeRequest(portPtr));
this.binding_.setConnectionErrorHandler(() => {
this.close();
});
this.options_ = options;
this.client_ = client;
// OS typically sets DTR on open.
this.outputSignals_.dataTerminalReady = true;
return portPtr;
}
write(data) {
return this.writer_.write(data);
}
read() {
return this.reader_.read();
}
// Reads from the port until at least |targetLength| is read or the stream is
// closed. The data is returned as a combined Uint8Array.
readWithLength(targetLength) {
return readWithLength(this.reader_, targetLength);
}
simulateReadError(error) {
this.writer_.close();
this.writer_.releaseLock();
this.writer_ = undefined;
this.writable_ = undefined;
this.client_.onReadError(error);
}
simulateParityError() {
this.simulateReadError(device.mojom.SerialReceiveError.PARITY_ERROR);
}
simulateDisconnectOnRead() {
this.simulateReadError(device.mojom.SerialReceiveError.DISCONNECTED);
}
simulateWriteError(error) {
this.reader_.cancel();
this.reader_ = undefined;
this.readable_ = undefined;
this.client_.onSendError(error);
}
simulateSystemErrorOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.SYSTEM_ERROR);
}
simulateDisconnectOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.DISCONNECTED);
}
simulateInputSignals(signals) {
this.inputSignals_ = signals;
}
get outputSignals() {
return this.outputSignals_;
}
writable() {
if (this.writable_)
return Promise.resolve();
if (!this.writablePromise_) {
this.writablePromise_ = new Promise((resolve) => {
this.writableResolver_ = resolve;
});
}
return this.writablePromise_;
}
readable() {
if (this.readable_)
return Promise.resolve();
if (!this.readablePromise_) {
this.readablePromise_ = new Promise((resolve) => {
this.readableResolver_ = resolve;
});
}
return this.readablePromise_;
}
async startWriting(in_stream) {
this.readable_ = new ReadableStream(new DataPipeSource(in_stream));
this.reader_ = this.readable_.getReader();
if (this.readableResolver_) {
this.readableResolver_();
this.readableResolver_ = undefined;
this.readablePromise_ = undefined;
}
}
async startReading(out_stream) {
this.writable_ = new WritableStream(new DataPipeSink(out_stream));
this.writer_ = this.writable_.getWriter();
if (this.writableResolver_) {
this.writableResolver_();
this.writableResolver_ = undefined;
this.writablePromise_ = undefined;
}
}
async flush(mode) {
switch (mode) {
case device.mojom.SerialPortFlushMode.kReceive:
this.writer_.abort();
this.writer_.releaseLock();
this.writer_ = undefined;
this.writable_ = undefined;
break;
case device.mojom.SerialPortFlushMode.kTransmit:
this.reader_.cancel();
this.reader_ = undefined;
this.readable_ = undefined;
break;
}
}
async drain() {
await this.reader_.closed;
}
async getControlSignals() {
const signals = {
dcd: this.inputSignals_.dataCarrierDetect,
cts: this.inputSignals_.clearToSend,
ri: this.inputSignals_.ringIndicator,
dsr: this.inputSignals_.dataSetReady
};
return {signals};
}
async setControlSignals(signals) {
if (signals.hasDtr) {
this.outputSignals_.dataTerminalReady = signals.dtr;
}
if (signals.hasRts) {
this.outputSignals_.requestToSend = signals.rts;
}
if (signals.hasBrk) {
this.outputSignals_.break = signals.brk;
}
return { success: true };
}
async configurePort(options) {
this.options_ = options;
return { success: true };
}
async getPortInfo() {
return {
bitrate: this.options_.bitrate,
data_bits: this.options_.data_bits,
parity_bit: this.options_.parity_bit,
stop_bits: this.options_.stop_bits,
cts_flow_control: this.options_.has_cts_flow_control ?
this.options_.cts_flow_control : false
};
}
async close() {
// OS typically clears DTR on close.
this.outputSignals_.dataTerminalReady = false;
if (this.writer_) {
this.writer_.close();
this.writer_.releaseLock();
this.writer_ = undefined;
}
this.writable_ = undefined;
if (this.binding_) {
this.binding_.close();
this.binding_ = undefined;
}
return {};
}
}
// Implementation of blink.mojom.SerialService.
class FakeSerialService {
constructor() {
this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
this.interceptor_.oninterfacerequest = e => this.bind(e.handle);
this.bindingSet_ = new mojo.BindingSet(blink.mojom.SerialService);
this.clients_ = [];
this.nextToken_ = 0;
this.reset();
}
start() {
this.interceptor_.start();
}
stop() {
this.interceptor_.stop();
}
reset() {
this.ports_ = new Map();
this.selectedPort_ = null;
}
addPort(info) {
let portInfo = new blink.mojom.SerialPortInfo();
if (info?.usbVendorId !== undefined) {
portInfo.hasUsbVendorId = true;
portInfo.usbVendorId = info.usbVendorId;
}
if (info?.usbProductId !== undefined) {
portInfo.hasUsbProductId = true;
portInfo.usbProductId = info.usbProductId;
}
let token = ++this.nextToken_;
portInfo.token = new mojoBase.mojom.UnguessableToken();
portInfo.token.high = 0;
portInfo.token.low = token;
let record = {
portInfo: portInfo,
fakePort: new FakeSerialPort(),
};
this.ports_.set(token, record);
for (let client of this.clients_) {
client.onPortAdded(portInfo);
}
return token;
}
removePort(token) {
let record = this.ports_.get(token);
if (record === undefined) {
return;
}
this.ports_.delete(token);
for (let client of this.clients_) {
client.onPortRemoved(record.portInfo);
}
}
setSelectedPort(token) {
this.selectedPort_ = this.ports_.get(token);
}
getFakePort(token) {
let record = this.ports_.get(token);
if (record === undefined)
return undefined;
return record.fakePort;
}
bind(handle) {
this.bindingSet_.addBinding(this, handle);
}
async setClient(client_remote) {
this.clients_.push(client_remote);
}
async getPorts() {
return {
ports: Array.from(this.ports_, ([token, record]) => record.portInfo)
};
}
async requestPort(filters) {
if (this.selectedPort_)
return { port: this.selectedPort_.portInfo };
else
return { port: null };
}
async openPort(token, options, client) {
let record = this.ports_.get(token.low);
if (record !== undefined) {
return {port: record.fakePort.open(options, client)};
} else {
return {port: null};
}
}
}
let fakeSerialService = new FakeSerialService();
function serial_test(func, name, properties) { function serial_test(func, name, properties) {
promise_test(async (test) => { promise_test(async (test) => {
if (fakeSerialService === undefined) {
await loadMojoResources([
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
'/gen/services/device/public/mojom/serial.mojom.js',
'/gen/third_party/blink/public/mojom/serial/serial.mojom.js',
]);
await loadScript('resources/fake-serial.js');
}
fakeSerialService.start(); fakeSerialService.start();
try { try {
await func(test, fakeSerialService); await func(test, fakeSerialService);
......
// Implementation of an UnderlyingSource to create a ReadableStream from a Mojo
// data pipe consumer handle.
class DataPipeSource {
constructor(consumer) {
this.consumer_ = consumer;
}
async pull(controller) {
let chunk = new ArrayBuffer(64);
let {result, numBytes} = this.consumer_.readData(chunk);
if (result == Mojo.RESULT_OK) {
controller.enqueue(new Uint8Array(chunk, 0, numBytes));
return;
} else if (result == Mojo.RESULT_FAILED_PRECONDITION) {
controller.close();
return;
} else if (result == Mojo.RESULT_SHOULD_WAIT) {
await this.readable();
return this.pull(controller);
}
}
cancel() {
if (this.watcher_)
this.watcher_.cancel();
this.consumer_.close();
}
readable() {
return new Promise((resolve) => {
this.watcher_ =
this.consumer_.watch({ readable: true, peerClosed: true }, () => {
this.watcher_.cancel();
this.watcher_ = undefined;
resolve();
});
});
}
}
// Implementation of an UnderlyingSink to create a WritableStream from a Mojo
// data pipe producer handle.
class DataPipeSink {
constructor(producer) {
this._producer = producer;
}
async write(chunk, controller) {
while (true) {
let {result, numBytes} = this._producer.writeData(chunk);
if (result == Mojo.RESULT_OK) {
if (numBytes == chunk.byteLength) {
return;
}
chunk = chunk.slice(numBytes);
} else if (result == Mojo.RESULT_FAILED_PRECONDITION) {
throw new DOMException('The pipe is closed.', 'InvalidStateError');
} else if (result == Mojo.RESULT_SHOULD_WAIT) {
await this.writable();
}
}
}
close() {
assert_equals(undefined, this._watcher);
this._producer.close();
}
abort(reason) {
if (this._watcher)
this._watcher.cancel();
this._producer.close();
}
writable() {
return new Promise((resolve) => {
this._watcher =
this._producer.watch({ writable: true, peerClosed: true }, () => {
this._watcher.cancel();
this._watcher = undefined;
resolve();
});
});
}
}
// Implementation of blink.mojom.SerialPort.
class FakeSerialPort {
constructor() {
this.inputSignals_ = {
dataCarrierDetect: false,
clearToSend: false,
ringIndicator: false,
dataSetReady: false
};
this.outputSignals_ = {
dataTerminalReady: false,
requestToSend: false,
break: false
};
}
open(options, client) {
if (this.binding_ !== undefined) {
// Port already open.
return null;
}
let portPtr = new device.mojom.SerialPortPtr();
this.binding_ = new mojo.Binding(
device.mojom.SerialPort, this, mojo.makeRequest(portPtr));
this.binding_.setConnectionErrorHandler(() => {
this.close();
});
this.options_ = options;
this.client_ = client;
// OS typically sets DTR on open.
this.outputSignals_.dataTerminalReady = true;
return portPtr;
}
write(data) {
return this.writer_.write(data);
}
read() {
return this.reader_.read();
}
// Reads from the port until at least |targetLength| is read or the stream is
// closed. The data is returned as a combined Uint8Array.
readWithLength(targetLength) {
return readWithLength(this.reader_, targetLength);
}
simulateReadError(error) {
this.writer_.close();
this.writer_.releaseLock();
this.writer_ = undefined;
this.writable_ = undefined;
this.client_.onReadError(error);
}
simulateParityError() {
this.simulateReadError(device.mojom.SerialReceiveError.PARITY_ERROR);
}
simulateDisconnectOnRead() {
this.simulateReadError(device.mojom.SerialReceiveError.DISCONNECTED);
}
simulateWriteError(error) {
this.reader_.cancel();
this.reader_ = undefined;
this.readable_ = undefined;
this.client_.onSendError(error);
}
simulateSystemErrorOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.SYSTEM_ERROR);
}
simulateDisconnectOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.DISCONNECTED);
}
simulateInputSignals(signals) {
this.inputSignals_ = signals;
}
get outputSignals() {
return this.outputSignals_;
}
writable() {
if (this.writable_)
return Promise.resolve();
if (!this.writablePromise_) {
this.writablePromise_ = new Promise((resolve) => {
this.writableResolver_ = resolve;
});
}
return this.writablePromise_;
}
readable() {
if (this.readable_)
return Promise.resolve();
if (!this.readablePromise_) {
this.readablePromise_ = new Promise((resolve) => {
this.readableResolver_ = resolve;
});
}
return this.readablePromise_;
}
async startWriting(in_stream) {
this.readable_ = new ReadableStream(new DataPipeSource(in_stream));
this.reader_ = this.readable_.getReader();
if (this.readableResolver_) {
this.readableResolver_();
this.readableResolver_ = undefined;
this.readablePromise_ = undefined;
}
}
async startReading(out_stream) {
this.writable_ = new WritableStream(new DataPipeSink(out_stream));
this.writer_ = this.writable_.getWriter();
if (this.writableResolver_) {
this.writableResolver_();
this.writableResolver_ = undefined;
this.writablePromise_ = undefined;
}
}
async flush(mode) {
switch (mode) {
case device.mojom.SerialPortFlushMode.kReceive:
this.writer_.abort();
this.writer_.releaseLock();
this.writer_ = undefined;
this.writable_ = undefined;
break;
case device.mojom.SerialPortFlushMode.kTransmit:
this.reader_.cancel();
this.reader_ = undefined;
this.readable_ = undefined;
break;
}
}
async drain() {
await this.reader_.closed;
}
async getControlSignals() {
const signals = {
dcd: this.inputSignals_.dataCarrierDetect,
cts: this.inputSignals_.clearToSend,
ri: this.inputSignals_.ringIndicator,
dsr: this.inputSignals_.dataSetReady
};
return {signals};
}
async setControlSignals(signals) {
if (signals.hasDtr) {
this.outputSignals_.dataTerminalReady = signals.dtr;
}
if (signals.hasRts) {
this.outputSignals_.requestToSend = signals.rts;
}
if (signals.hasBrk) {
this.outputSignals_.break = signals.brk;
}
return { success: true };
}
async configurePort(options) {
this.options_ = options;
return { success: true };
}
async getPortInfo() {
return {
bitrate: this.options_.bitrate,
data_bits: this.options_.data_bits,
parity_bit: this.options_.parity_bit,
stop_bits: this.options_.stop_bits,
cts_flow_control: this.options_.has_cts_flow_control ?
this.options_.cts_flow_control : false
};
}
async close() {
// OS typically clears DTR on close.
this.outputSignals_.dataTerminalReady = false;
if (this.writer_) {
this.writer_.close();
this.writer_.releaseLock();
this.writer_ = undefined;
}
this.writable_ = undefined;
if (this.binding_) {
this.binding_.close();
this.binding_ = undefined;
}
return {};
}
}
// Implementation of blink.mojom.SerialService.
class FakeSerialService {
constructor() {
this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
this.interceptor_.oninterfacerequest = e => this.bind(e.handle);
this.bindingSet_ = new mojo.BindingSet(blink.mojom.SerialService);
this.clients_ = [];
this.nextToken_ = 0;
this.reset();
}
start() {
this.interceptor_.start();
}
stop() {
this.interceptor_.stop();
}
reset() {
this.ports_ = new Map();
this.selectedPort_ = null;
}
addPort(info) {
let portInfo = new blink.mojom.SerialPortInfo();
if (info?.usbVendorId !== undefined) {
portInfo.hasUsbVendorId = true;
portInfo.usbVendorId = info.usbVendorId;
}
if (info?.usbProductId !== undefined) {
portInfo.hasUsbProductId = true;
portInfo.usbProductId = info.usbProductId;
}
let token = ++this.nextToken_;
portInfo.token = new mojoBase.mojom.UnguessableToken();
portInfo.token.high = 0;
portInfo.token.low = token;
let record = {
portInfo: portInfo,
fakePort: new FakeSerialPort(),
};
this.ports_.set(token, record);
for (let client of this.clients_) {
client.onPortAdded(portInfo);
}
return token;
}
removePort(token) {
let record = this.ports_.get(token);
if (record === undefined) {
return;
}
this.ports_.delete(token);
for (let client of this.clients_) {
client.onPortRemoved(record.portInfo);
}
}
setSelectedPort(token) {
this.selectedPort_ = this.ports_.get(token);
}
getFakePort(token) {
let record = this.ports_.get(token);
if (record === undefined)
return undefined;
return record.fakePort;
}
bind(handle) {
this.bindingSet_.addBinding(this, handle);
}
async setClient(client_remote) {
this.clients_.push(client_remote);
}
async getPorts() {
return {
ports: Array.from(this.ports_, ([token, record]) => record.portInfo)
};
}
async requestPort(filters) {
if (this.selectedPort_)
return { port: this.selectedPort_.portInfo };
else
return { port: null };
}
async openPort(token, options, client) {
let record = this.ports_.get(token.low);
if (record !== undefined) {
return {port: record.fakePort.open(options, client)};
} else {
return {port: null};
}
}
}
fakeSerialService = new FakeSerialService();
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
This is a testharness.js-based test.
PASS stopPropagation() during capturing
PASS Set cancelBubble during capturing
PASS stopPropagation() during bubbling
PASS Set cancelBubble during bubbling
PASS An event dispatched in an event handler is propagated before continuing
FAIL Capturing and bubbling events delivered to listeners in the expected order assert_array_equals: expected property 1 to be "capturing SerialPort" but got "bubbling SerialPort" (expected array ["capturing Serial", "capturing SerialPort", "bubbling SerialPort", "bubbling Serial"] got ["capturing Serial", "bubbling SerialPort", "capturing SerialPort", "bubbling Serial"])
Harness: the test ran to completion.
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/test-only-api.js
promise_test(async () => {
await loadMojoResources([
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
'/gen/third_party/blink/public/mojom/serial/serial.mojom.js',
]);
let interceptor =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
interceptor.oninterfacerequest = e => e.handle.close();
interceptor.start();
let ports = await navigator.serial.getPorts();
assert_equals(ports.length, 0);
interceptor.stop();
}, 'getPorts() returns empty list if Mojo service connection fails');
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
promise_test(async () => {
let interceptor =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
interceptor.oninterfacerequest = e => e.handle.close();
interceptor.start();
let ports = await navigator.serial.getPorts();
assert_equals(ports.length, 0);
interceptor.stop();
}, 'getPorts() returns empty list if Mojo service connection fails');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
fake.addPort(); fake.addPort();
fake.addPort(); fake.addPort();
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testharness.js // META: script=/resources/test-only-api.js
// META: script=/resources/testharnessreport.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
......
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=/resources/test-only-api.js
// META: script=resources/automation.js
promise_test(async (t) => {
await loadMojoResources([
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js',
'/gen/third_party/blink/public/mojom/serial/serial.mojom.js',
]);
let interceptor =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
interceptor.oninterfacerequest = e => e.handle.close();
interceptor.start();
await trustedClick();
try {
await promise_rejects_dom(
t, 'NotFoundError', navigator.serial.requestPort());
} finally {
interceptor.stop();
}
}, 'requestPort() rejects if Mojo service connection fails');
// META: script=/resources/testharness.js
// META: script=/resources/testharnessreport.js
// META: script=/resources/testdriver.js // META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js // META: script=/resources/testdriver-vendor.js
// META: script=/gen/layout_test_data/mojo/public/js/mojo_bindings.js // META: script=/resources/test-only-api.js
// META: script=/gen/mojo/public/mojom/base/unguessable_token.mojom.js
// META: script=/gen/third_party/blink/public/mojom/serial/serial.mojom.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=resources/automation.js
promise_test((t) => { serial_test((t, fake) => {
return promise_rejects_dom( return promise_rejects_dom(
t, 'SecurityError', navigator.serial.requestPort()); t, 'SecurityError', navigator.serial.requestPort());
}, 'requestPort() rejects without a user gesture'); }, 'requestPort() rejects without a user gesture');
promise_test(async (t) => {
let interceptor =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
interceptor.oninterfacerequest = e => e.handle.close();
interceptor.start();
await trustedClick();
try {
await promise_rejects_dom(
t, 'NotFoundError', navigator.serial.requestPort());
} finally {
interceptor.stop();
}
}, 'requestPort() rejects if Mojo service connection fails');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
await trustedClick(); await trustedClick();
return promise_rejects_dom( return promise_rejects_dom(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment