Skip to content

Commit

Permalink
Migrate remaining WPT to Mojo JS modules
Browse files Browse the repository at this point in the history
All remaining WPT using Mojo bindings are migrated to newer module-based
bindings here. Support for loading older bindings variants in WPT is
removed.

Bug: 1004256
Change-Id: I630a6ddb0e5b89f5b7e6c538a273c3725a485aae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2664907
Commit-Queue: Ken Rockot <[email protected]>
Reviewed-by: Stephen McGruer <[email protected]>
Reviewed-by: Michael Moss <[email protected]>
Reviewed-by: Alexander Cooper <[email protected]>
Cr-Commit-Position: refs/heads/master@{#849713}
  • Loading branch information
krockot authored and chromium-wpt-export-bot committed Feb 2, 2021
1 parent d47b8fb commit e3b2fa5
Show file tree
Hide file tree
Showing 25 changed files with 494 additions and 645 deletions.
9 changes: 1 addition & 8 deletions contacts/resources/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
//
// --enable-blink-features=MojoJS,MojoJSTest
async function loadChromiumResources() {

const chromiumResources = [
'/gen/third_party/blink/public/mojom/contacts/contacts_manager.mojom.js',
'/gen/components/payments/mojom/payment_request_data.mojom.js',
];

await loadMojoResources(chromiumResources);
await loadScript('/resources/chromium/contacts_manager_mock.js');
await import('/resources/chromium/contacts_manager_mock.js');
}

// User Agents must provide their own implementation of `WebContacts`,
Expand Down
8 changes: 1 addition & 7 deletions generic-sensor/resources/generic-sensor-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@
//
// --enable-blink-features=MojoJS,MojoJSTest
async function loadChromiumResources() {
const chromiumResources = [
'/gen/mojo/public/mojom/base/string16.mojom.js',
'/gen/services/device/public/mojom/sensor.mojom.js',
'/gen/services/device/public/mojom/sensor_provider.mojom.js',
];
await loadMojoResources(chromiumResources);
await loadScript('/resources/testdriver.js');
await loadScript('/resources/testdriver-vendor.js');
await loadScript('/resources/chromium/generic_sensor_mocks.js');
await import('/resources/chromium/generic_sensor_mocks.js');
}

async function initialize_generic_sensor_tests() {
Expand Down
9 changes: 1 addition & 8 deletions idle-detection/resources/idle-detection-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,5 @@
// --enable-blink-features=MojoJS,MojoJSTest

async function loadChromiumResources() {
const chromiumResources = [
'/gen/mojo/public/mojom/base/string16.mojom.js',
'/gen/mojo/public/mojom/base/time.mojom.js',
'/gen/third_party/blink/public/mojom/idle/idle_manager.mojom.js'
];

await loadMojoResources(chromiumResources);
await loadScript('/resources/chromium/mock-idle-detection.js');
await import('/resources/chromium/mock-idle-detection.js');
}
22 changes: 11 additions & 11 deletions lint.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -727,20 +727,20 @@ WEB-PLATFORM.TEST:web-bundle/subresource-loading/*.html
# Tests that depend on resources in /gen/ in Chromium:
# https://github.com/web-platform-tests/wpt/issues/16455
# Please consult with [email protected] before adding more.
MISSING DEPENDENCY: contacts/resources/helpers.js
MISSING DEPENDENCY: credential-management/support/otpcredential-helper.js
MISSING DEPENDENCY: generic-sensor/resources/generic-sensor-helpers.js
MISSING DEPENDENCY: idle-detection/resources/idle-detection-helper.js
MISSING DEPENDENCY: mediacapture-image/resources/imagecapture-helpers.js
MISSING DEPENDENCY: orientation-event/resources/orientation-event-helpers.js
MISSING DEPENDENCY: resources/chromium/contacts_manager_mock.js
MISSING DEPENDENCY: resources/chromium/web-bluetooth-test.js
MISSING DEPENDENCY: resources/chromium/webusb-test.js
MISSING DEPENDENCY: resources/test-only-api.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: web-nfc/resources/nfc-helpers.js
MISSING DEPENDENCY: webxr/resources/webxr_util.js
MISSING DEPENDENCY: resources/chromium/fake-serial.js
MISSING DEPENDENCY: resources/chromium/generic_sensor_mocks.js
MISSING DEPENDENCY: resources/chromium/mock-barcodedetection.js
MISSING DEPENDENCY: resources/chromium/mock-facedetection.js
MISSING DEPENDENCY: resources/chromium/mock-idle-detection.js
MISSING DEPENDENCY: resources/chromium/mock-imagecapture.js
MISSING DEPENDENCY: resources/chromium/mock-screenenumeration.js
MISSING DEPENDENCY: resources/chromium/mock-textdetection.js
MISSING DEPENDENCY: resources/chromium/nfc-mock.js
MISSING DEPENDENCY: resources/chromium/webxr-test.js

# Tests that are false positives for using Ahem as a system font
AHEM SYSTEM FONT: acid/acid3/test.html
Expand Down
6 changes: 1 addition & 5 deletions mediacapture-image/resources/imagecapture-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
// --enable-blink-features=MojoJS,MojoJSTest

async function loadChromiumResources() {
const chromiumResources = [
'/gen/media/capture/mojom/image_capture.mojom.js'
];
await loadMojoResources(chromiumResources);
await loadScript('/resources/chromium/mock-imagecapture.js');
await import('/resources/chromium/mock-imagecapture.js');
}

async function initialize_image_capture_tests() {
Expand Down
8 changes: 1 addition & 7 deletions orientation-event/resources/orientation-event-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
//
// --enable-blink-features=MojoJS,MojoJSTest
async function loadChromiumResources() {
const chromiumResources = [
'/gen/mojo/public/mojom/base/string16.mojom.js',
'/gen/services/device/public/mojom/sensor.mojom.js',
'/gen/services/device/public/mojom/sensor_provider.mojom.js',
];
await loadMojoResources(chromiumResources);
await loadScript('/resources/chromium/generic_sensor_mocks.js');
await import('/resources/chromium/generic_sensor_mocks.js');
}

async function initialize_generic_sensor_tests() {
Expand Down
2 changes: 1 addition & 1 deletion resources/chromium/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ This directory contains Chromium-specific test resources, including mocks for
test-only APIs implemented with
[MojoJS](https://chromium.googlesource.com/chromium/src/+/master/mojo/public/js/README.md).

Please do **not** copy `*.mojom.js` into this directory. Follow this doc if you
Please do **not** copy `*.mojom.m.js` into this directory. Follow this doc if you
want to add new MojoJS-backed mocks:
https://chromium.googlesource.com/chromium/src/+/master/docs/testing/web_platform_tests.md#mojojs
14 changes: 7 additions & 7 deletions resources/chromium/contacts_manager_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

'use strict';
import {ContactsManager, ContactsManagerReceiver} from '/gen/third_party/blink/public/mojom/contacts/contacts_manager.mojom.m.js';

const WebContactsTest = (() => {
self.WebContactsTest = (() => {
class MockContacts {
constructor() {
this.bindingSet_ = new mojo.BindingSet(blink.mojom.ContactsManager);
this.receiver_ = new ContactsManagerReceiver(this);

this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.ContactsManager.name);
new MojoInterfaceInterceptor(ContactsManager.$interfaceName);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
e => this.receiver_.$.bindHandle(e.handle);
this.interceptor_.start();

this.selectedContacts_ = [];
Expand All @@ -39,7 +39,7 @@ const WebContactsTest = (() => {
return {contacts: null};

const contactInfos = await Promise.all(this.selectedContacts_.map(async contact => {
const contactInfo = new blink.mojom.ContactInfo();
const contactInfo = {};
if (includeNames)
contactInfo.name = contact.name || [];
if (includeEmails)
Expand Down Expand Up @@ -69,7 +69,7 @@ const WebContactsTest = (() => {
}

reset() {
this.bindingSet_.closeAllBindings();
this.receiver_.$.close();
this.interceptor_.stop();
}
}
Expand Down
62 changes: 30 additions & 32 deletions resources/chromium/fake-serial.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {SerialPortFlushMode, SerialPortRemote, SerialReceiveError, SerialPortReceiver, SerialSendError} from '/gen/services/device/public/mojom/serial.mojom.m.js';
import {SerialService, SerialServiceReceiver} from '/gen/third_party/blink/public/mojom/serial/serial.mojom.m.js';

// Implementation of an UnderlyingSource to create a ReadableStream from a Mojo
// data pipe consumer handle.
class DataPipeSource {
Expand Down Expand Up @@ -84,7 +87,7 @@ class DataPipeSink {
}
}

// Implementation of blink.mojom.SerialPort.
// Implementation of device.mojom.SerialPort.
class FakeSerialPort {
constructor() {
this.inputSignals_ = {
Expand All @@ -103,24 +106,21 @@ class FakeSerialPort {
}

open(options, client) {
if (this.binding_ !== undefined) {
if (this.receiver_ !== 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();
});
let port = new SerialPortRemote();
this.receiver_ = new SerialPortReceiver(this);
this.receiver_.$.bindHandle(port.$.bindNewPipeAndPassReceiver().handle);

this.options_ = options;
this.client_ = client;
// OS typically sets DTR on open.
this.outputSignals_.dataTerminalReady = true;

return portPtr;
return port;
}

write(data) {
Expand All @@ -146,11 +146,11 @@ class FakeSerialPort {
}

simulateParityError() {
this.simulateReadError(device.mojom.SerialReceiveError.PARITY_ERROR);
this.simulateReadError(SerialReceiveError.PARITY_ERROR);
}

simulateDisconnectOnRead() {
this.simulateReadError(device.mojom.SerialReceiveError.DISCONNECTED);
this.simulateReadError(SerialReceiveError.DISCONNECTED);
}

simulateWriteError(error) {
Expand All @@ -161,11 +161,11 @@ class FakeSerialPort {
}

simulateSystemErrorOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.SYSTEM_ERROR);
this.simulateWriteError(SerialSendError.SYSTEM_ERROR);
}

simulateDisconnectOnWrite() {
this.simulateWriteError(device.mojom.SerialSendError.DISCONNECTED);
this.simulateWriteError(SerialSendError.DISCONNECTED);
}

simulateInputSignals(signals) {
Expand Down Expand Up @@ -232,13 +232,13 @@ class FakeSerialPort {

async flush(mode) {
switch (mode) {
case device.mojom.SerialPortFlushMode.kReceive:
case SerialPortFlushMode.kReceive:
this.writer_.abort();
this.writer_.releaseLock();
this.writer_ = undefined;
this.writable_ = undefined;
break;
case device.mojom.SerialPortFlushMode.kTransmit:
case SerialPortFlushMode.kTransmit:
this.reader_.cancel();
this.reader_ = undefined;
this.readable_ = undefined;
Expand Down Expand Up @@ -289,11 +289,11 @@ class FakeSerialPort {
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
dataBits: this.options_.datBits,
parityBit: this.options_.parityBit,
stopBits: this.options_.stopBits,
ctsFlowControl:
this.options_.hasCtsFlowControl && this.options_.ctsFlowControl,
};
}

Expand All @@ -307,9 +307,9 @@ class FakeSerialPort {
}
this.writable_ = undefined;

if (this.binding_) {
this.binding_.close();
this.binding_ = undefined;
if (this.receiver_) {
this.receiver_.$.close();
this.receiver_ = undefined;
}
return {};
}
Expand All @@ -319,9 +319,9 @@ class FakeSerialPort {
class FakeSerialService {
constructor() {
this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.SerialService.name);
new MojoInterfaceInterceptor(SerialService.$interfaceName);
this.interceptor_.oninterfacerequest = e => this.bind(e.handle);
this.bindingSet_ = new mojo.BindingSet(blink.mojom.SerialService);
this.receiver_ = new SerialServiceReceiver(this);
this.clients_ = [];
this.nextToken_ = 0;
this.reset();
Expand All @@ -341,7 +341,7 @@ class FakeSerialService {
}

addPort(info) {
let portInfo = new blink.mojom.SerialPortInfo();
let portInfo = {};
if (info?.usbVendorId !== undefined) {
portInfo.hasUsbVendorId = true;
portInfo.usbVendorId = info.usbVendorId;
Expand All @@ -352,9 +352,7 @@ class FakeSerialService {
}

let token = ++this.nextToken_;
portInfo.token = new mojoBase.mojom.UnguessableToken();
portInfo.token.high = 0;
portInfo.token.low = token;
portInfo.token = {high: 0n, low: BigInt(token)};

let record = {
portInfo: portInfo,
Expand Down Expand Up @@ -394,7 +392,7 @@ class FakeSerialService {
}

bind(handle) {
this.bindingSet_.addBinding(this, handle);
this.receiver_.$.bindHandle(handle);
}

async setClient(client_remote) {
Expand All @@ -415,7 +413,7 @@ class FakeSerialService {
}

async openPort(token, options, client) {
let record = this.ports_.get(token.low);
let record = this.ports_.get(Number(token.low));
if (record !== undefined) {
return {port: record.fakePort.open(options, client)};
} else {
Expand All @@ -424,4 +422,4 @@ class FakeSerialService {
}
}

fakeSerialService = new FakeSerialService();
export const fakeSerialService = new FakeSerialService();
Loading

0 comments on commit e3b2fa5

Please sign in to comment.