blob: 08c9c5e49625231fda0f75051a5aeb578eedda85 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/mojo/public/mojom/base/unguessable_token.mojom.js"></script>
<script src="file:///gen/third_party/blink/public/mojom/serial/serial.mojom.js"></script>
<script src="resources/serial-test-utils.js"></script>
<script>
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 (fake) => {
fake.addPort();
fake.addPort();
let ports = await navigator.serial.getPorts();
assert_equals(ports.length, 2);
assert_true(ports[0] instanceof SerialPort);
assert_true(ports[1] instanceof SerialPort);
// TODO: Assert that product IDs (if provided) are passed through.
}, 'getPorts() returns the set of configured fake ports');
serial_test(async (fake) => {
fake.addPort();
let portsFirst = await navigator.serial.getPorts();
assert_equals(portsFirst.length, 1, 'first call returns one port');
assert_true(portsFirst[0] instanceof SerialPort);
let portsSecond = await navigator.serial.getPorts();
assert_equals(portsSecond.length, 1, 'second call returns one port');
assert_true(portsSecond[0] instanceof SerialPort);
assert_true(portsFirst[0] === portsSecond[0]);
}, 'getPorts() returns the same port objects every time');
</script>