| Index: third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
|
| diff --git a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7d0c65a41f7b606c9f580cfe05aa92d43a584688
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
|
| @@ -0,0 +1,148 @@
|
| +'use strict';
|
| +
|
| +function usb_test(func, name, properties) {
|
| + mojo_test(mojo => {
|
| + return new Promise((resolve, reject) => {
|
| + define('USB layout test: ' + name, [
|
| + 'device/devices_app/usb/public/interfaces/device_manager.mojom',
|
| + 'device/devices_app/usb/public/interfaces/device.mojom',
|
| + 'device/devices_app/usb/public/interfaces/permission_provider.mojom'
|
| + ], (deviceManager, device, permissionProvider) => {
|
| + class MockDevice extends device.Device.stubClass {
|
| + constructor(info, pipe) {
|
| + super();
|
| + this.info_ = info;
|
| + this.router_ = new mojo.router.Router(pipe);
|
| + this.router_.setIncomingReceiver(this);
|
| + }
|
| +
|
| + getDeviceInfo() { return { info: this.info_ }; }
|
| + getConfiguration() { throw 'Not implemented!'; }
|
| + open() { throw 'Not implemented!'; }
|
| + close() { throw 'Not implemented!'; }
|
| + setConfiguration(value) { throw 'Not implemented!'; }
|
| + claimInterface(interfaceNumber) { throw 'Not implemented!'; }
|
| + releaseInterface(interfaceNumber) { throw 'Not implemented!'; }
|
| + setInterfaceAlternateSetting(interfaceNumber, alternateSetting) {
|
| + throw 'Not implemented!';
|
| + }
|
| + reset() { throw 'Not implemented!'; }
|
| + clearHalt(endpoint) { throw 'Not implemented!'; }
|
| + controlTransferIn(params, length, timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + controlTransferOut(params, data, timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + genericTransferIn(endpointNumber, length, timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + genericTransferOut(endpointNumber, data, timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + isochronousTransferIn(endpointNumber, numPackets, packetLength,
|
| + timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + isochronousTransferOut(endpointNumber, packets, timeout) {
|
| + throw 'Not implemented!';
|
| + }
|
| + };
|
| +
|
| + class MockDeviceManager extends deviceManager.DeviceManager.stubClass {
|
| + constructor() {
|
| + super();
|
| + this.router_ = null;
|
| + this.lastSeenDevices_ = {};
|
| + this.mockDevices_ = {};
|
| + }
|
| +
|
| + addMockDevice(info) {
|
| + this.mockDevices_[info.guid] = info;
|
| + }
|
| +
|
| + bindToPipe(pipe) {
|
| + assert_equals(this.router_, null);
|
| + this.router_ = new mojo.router.Router(pipe);
|
| + this.router_.setIncomingReceiver(this);
|
| + }
|
| +
|
| + getDevices(options) {
|
| + return Promise.resolve({
|
| + results: Object.keys(this.mockDevices_).map(
|
| + guid => this.mockDevices_[guid]),
|
| + });
|
| + }
|
| +
|
| + getDeviceChanges() {
|
| + let additions = [];
|
| + for (let guid in this.mockDevices_)
|
| + if (!(guid in this.lastSeenDevices_))
|
| + additions.push(this.mockDevices_[guid]);
|
| +
|
| + let removals = [];
|
| + for (let guid in this.lastSeenDevices_)
|
| + if (!(guid in this.mockDevices_))
|
| + removals.push(this.mockDevices_[guid]);
|
| +
|
| + this.lastSeenDevices_ = {};
|
| + for (let guid in this.mockDevices_)
|
| + this.lastSeenDevices_[guid] = this.mockDevices_[guid];
|
| + return Promise.resolve({
|
| + changes: { devices_added: additions, devices_removed: removals }
|
| + });
|
| + }
|
| +
|
| + getDevice(guid, pipe) {
|
| + if (guid in this.mockDevices_)
|
| + new MockDevice(this.mockDevices_[guid], pipe);
|
| + }
|
| + }
|
| +
|
| + let mockDeviceManager = new MockDeviceManager;
|
| +
|
| + mojo.serviceRegistry.addServiceOverrideForTesting(
|
| + deviceManager.DeviceManager.name,
|
| + pipe => {
|
| + mockDeviceManager.bindToPipe(pipe);
|
| + });
|
| +
|
| + mojo.serviceRegistry.addServiceOverrideForTesting(
|
| + permissionProvider.PermissionProvider.name,
|
| + pipe => {
|
| + console.log('Connected to PermissionProvider!');
|
| + });
|
| +
|
| + try {
|
| + resolve(func({
|
| + DeviceManager: deviceManager.DeviceManager,
|
| + Device: device.Device,
|
| + PermissionProvider: permissionProvider.PermissionProvider,
|
| + mockDeviceManager: mockDeviceManager,
|
| + }));
|
| + } catch (e) {
|
| + reject(e);
|
| + }
|
| + });
|
| + });
|
| + }, name, properties);
|
| +}
|
| +
|
| +function assert_device_info_equals(device, info) {
|
| + assert_equals(device.guid, info.guid);
|
| + assert_equals(device.usbVersionMajor, info.usb_version_major);
|
| + assert_equals(device.usbVersionMinor, info.usb_version_minor);
|
| + assert_equals(device.usbVersionSubminor, info.usb_version_subminor);
|
| + assert_equals(device.deviceClass, info.class_code);
|
| + assert_equals(device.deviceSubclass, info.subclass_code);
|
| + assert_equals(device.deviceProtocol, info.protocol_code);
|
| + assert_equals(device.vendorId, info.vendor_id);
|
| + assert_equals(device.productId, info.product_id);
|
| + assert_equals(device.deviceVersionMajor, info.device_version_major);
|
| + assert_equals(device.deviceVersionMinor, info.device_version_minor);
|
| + assert_equals(device.deviceVersionSubminor, info.device_version_subminor);
|
| + assert_equals(device.manufacturerName, info.manufacturer_name);
|
| + assert_equals(device.productName, info.product_name);
|
| + assert_equals(device.serialNumber, info.serial_number);
|
| + assert_equals(device.configurations.length, info.configurations.length);
|
| +};
|
|
|