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

serial: Upstream wpt_internal tests to Web Platform Tests

This change upstreams most of the wpt_internal tests for the Web Serial
API to the Web Platform Tests repository. The remaining tests validate
Chromium-specific concerns.

To isolate Chromium-specific implementation details from the tests
fake-serial.js is moved to resources/chromium and exports a generic API
for controlling fake ports which could be provided by any
implementation. automation.js will fail tests early on platforms which
do not provide this service.

Bug: 884928
Change-Id: I86d3ff864bc4d38a923dbd96da464e74533dfba5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2577488
Commit-Queue: Michael Moss <mmoss@chromium.org>
Reviewed-by: default avatarMichael Moss <mmoss@chromium.org>
Reviewed-by: default avatarRobert Ma <robertma@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835257}
parent f7fc44e7
...@@ -489,4 +489,15 @@ FILES = [ ...@@ -489,4 +489,15 @@ FILES = [
'buildtype': ['dev', 'official'], 'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip', 'archive': 'mojojs.zip',
}, },
# MojoJS support data (Web Serial):
{
'filename': 'gen/services/device/public/mojom/serial.mojom.js',
'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip',
},
{
'filename': 'gen/third_party/blink/public/mojom/serial/serial.mojom.js',
'buildtype': ['dev', 'official'],
'archive': 'mojojs.zip',
},
] ]
...@@ -724,6 +724,7 @@ MISSING DEPENDENCY: mediacapture-image/resources/imagecapture-helpers.js ...@@ -724,6 +724,7 @@ MISSING DEPENDENCY: mediacapture-image/resources/imagecapture-helpers.js
MISSING DEPENDENCY: orientation-event/resources/orientation-event-helpers.js MISSING DEPENDENCY: orientation-event/resources/orientation-event-helpers.js
MISSING DEPENDENCY: resources/test-only-api.js MISSING DEPENDENCY: resources/test-only-api.js
MISSING DEPENDENCY: screen_enumeration/resources/screenenumeration-helpers.js MISSING DEPENDENCY: screen_enumeration/resources/screenenumeration-helpers.js
MISSING DEPENDENCY: serial/resources/automation.js
MISSING DEPENDENCY: shape-detection/resources/shapedetection-helpers.js MISSING DEPENDENCY: shape-detection/resources/shapedetection-helpers.js
MISSING DEPENDENCY: web-nfc/resources/nfc-helpers.js MISSING DEPENDENCY: web-nfc/resources/nfc-helpers.js
MISSING DEPENDENCY: webusb/resources/usb-helpers.js MISSING DEPENDENCY: webusb/resources/usb-helpers.js
......
'use strict';
// These tests rely on the User Agent providing an implementation of the
// FakeSerialService interface which replaces the platform-specific
// implementation of the Web Serial API with one that can be automated from
// Javascript for testing purposes.
//
// In Chromium-based browsers this implementation is provided by a polyfill
// in order to reduce the amount of test-only code shipped to users. To enable
// these tests the browser must be run with these options:
//
// --enable-blink-features=MojoJS,MojoJSTest
async function loadChromiumResources() {
const chromiumResources = [
'/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 loadMojoResources(chromiumResources);
}
// Returns a SerialPort instance and associated FakeSerialPort instance. // Returns a SerialPort instance and associated FakeSerialPort instance.
async function getFakeSerialPort(fake) { async function getFakeSerialPort(fake) {
let token = fake.addPort(); let token = fake.addPort();
...@@ -16,14 +38,15 @@ let fakeSerialService = undefined; ...@@ -16,14 +38,15 @@ let fakeSerialService = undefined;
function serial_test(func, name, properties) { function serial_test(func, name, properties) {
promise_test(async (test) => { promise_test(async (test) => {
assert_implements(navigator.serial, 'missing navigator.serial');
if (fakeSerialService === undefined) { if (fakeSerialService === undefined) {
await loadMojoResources([ // Try loading a polyfill for the fake serial service.
'/gen/mojo/public/mojom/base/unguessable_token.mojom.js', if (isChromiumBased) {
'/gen/services/device/public/mojom/serial.mojom.js', await loadChromiumResources();
'/gen/third_party/blink/public/mojom/serial/serial.mojom.js', await loadScript('/resources/chromium/fake-serial.js');
]); }
await loadScript('resources/fake-serial.js');
} }
assert_implements(fakeSerialService, 'missing fakeSerialService after initialization');
fakeSerialService.start(); fakeSerialService.start();
try { try {
......
...@@ -16,8 +16,8 @@ serial_test(async (t, fake) => { ...@@ -16,8 +16,8 @@ serial_test(async (t, fake) => {
}, 'requestPort() rejects if no port has been selected'); }, 'requestPort() rejects if no port has been selected');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let guid = fake.addPort(); let token = fake.addPort();
fake.setSelectedPort(guid); fake.setSelectedPort(token);
await trustedClick(); await trustedClick();
let port = await navigator.serial.requestPort(); let port = await navigator.serial.requestPort();
...@@ -25,8 +25,8 @@ serial_test(async (t, fake) => { ...@@ -25,8 +25,8 @@ serial_test(async (t, fake) => {
}, 'requestPort() returns the selected port'); }, 'requestPort() returns the selected port');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let guid = fake.addPort(); let token = fake.addPort();
fake.setSelectedPort(guid); fake.setSelectedPort(token);
await trustedClick(); await trustedClick();
let firstPort = await navigator.serial.requestPort(); let firstPort = await navigator.serial.requestPort();
...@@ -37,8 +37,8 @@ serial_test(async (t, fake) => { ...@@ -37,8 +37,8 @@ serial_test(async (t, fake) => {
}, 'requestPort() returns the same port object every time'); }, 'requestPort() returns the same port object every time');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let guid = fake.addPort(); let token = fake.addPort();
fake.setSelectedPort(guid); fake.setSelectedPort(token);
await trustedClick(); await trustedClick();
let port = await navigator.serial.requestPort({filters: []}); let port = await navigator.serial.requestPort({filters: []});
...@@ -46,8 +46,8 @@ serial_test(async (t, fake) => { ...@@ -46,8 +46,8 @@ serial_test(async (t, fake) => {
}, 'An empty list of filters is valid'); }, 'An empty list of filters is valid');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let guid = fake.addPort(); let token = fake.addPort();
fake.setSelectedPort(guid); fake.setSelectedPort(token);
await trustedClick(); await trustedClick();
return promise_rejects_js(t, TypeError, navigator.serial.requestPort({ return promise_rejects_js(t, TypeError, navigator.serial.requestPort({
...@@ -56,8 +56,8 @@ serial_test(async (t, fake) => { ...@@ -56,8 +56,8 @@ serial_test(async (t, fake) => {
}, 'An empty filter is not valid'); }, 'An empty filter is not valid');
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let guid = fake.addPort(); let token = fake.addPort();
fake.setSelectedPort(guid); fake.setSelectedPort(token);
await trustedClick(); await trustedClick();
return promise_rejects_js(t, TypeError, navigator.serial.requestPort({ return promise_rejects_js(t, TypeError, navigator.serial.requestPort({
......
// META: script=/resources/test-only-api.js // META: script=/resources/test-only-api.js
// META: script=/serial/resources/common.js // META: script=/serial/resources/common.js
// META: script=resources/automation.js // META: script=/serial/resources/automation.js
serial_test(async (t, fake) => { serial_test(async (t, fake) => {
let fakePort; let fakePort;
......
// META: script=/resources/testdriver.js // META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js // META: script=/resources/testdriver-vendor.js
// META: script=/resources/test-only-api.js // META: script=/resources/test-only-api.js
// META: script=resources/automation.js // META: script=/serial/resources/automation.js
promise_test(async (t) => { promise_test(async (t) => {
await loadMojoResources([ await loadMojoResources([
......
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