Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1444)

Unified Diff: third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js

Issue 1951723002: Use the Mojo StubBindings interface correctly in WebUSB LayoutTests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't attempt to signal an error on a closed connection. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index 932f3f6c477b9ddd436ceaef02ebf5ef75e05dd0..0a5e41842afed2f111ce296940e8ce5accccbf56 100644
--- a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
+++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
@@ -34,10 +34,12 @@ function runGarbageCollection() {
function usbMocks(mojo) {
return define('USB Mocks', [
+ 'mojo/public/js/bindings',
+ 'mojo/public/js/connection',
'device/usb/public/interfaces/chooser_service.mojom',
'device/usb/public/interfaces/device_manager.mojom',
'device/usb/public/interfaces/device.mojom',
- ], (chooserService, deviceManager, device) => {
+ ], (bindings, connection, chooserService, deviceManager, device) => {
function assertDeviceInfoEquals(device, info) {
assert_equals(device.guid, info.guid);
assert_equals(device.usbVersionMajor, info.usb_version_major);
@@ -126,21 +128,12 @@ function usbMocks(mojo) {
assert_equals(endpoint.packetSize, info.packet_size);
}
- class MockDevice extends device.Device.stubClass {
- constructor(info, pipe, closeHandler) {
- super();
+ class MockDevice {
+ constructor(info) {
this.info_ = info;
- this.pipe_ = pipe;
- this.router_ = new mojo.router.Router(pipe);
- this.router_.setIncomingReceiver(this);
- this.router_.setErrorHandler(() => {
- if (this.opened_)
- this.close();
- });
this.opened_ = false;
this.currentConfiguration_ = undefined;
this.claimedInterfaces_ = new Map();
- this.closeHandler_ = closeHandler;
}
getDeviceInfo() {
@@ -165,7 +158,6 @@ function usbMocks(mojo) {
close() {
assert_true(this.opened_);
this.opened_ = false;
- this.closeHandler_();
return Promise.resolve({ error: device.OpenDeviceError.OK });
}
@@ -330,10 +322,8 @@ function usbMocks(mojo) {
}
};
- class MockDeviceManager extends deviceManager.DeviceManager.stubClass {
+ class MockDeviceManager {
constructor() {
- super();
- this.router_ = null;
this.mockDevices_ = new Map();
this.addedDevices_ = [];
this.removedDevices_ = [];
@@ -341,10 +331,16 @@ function usbMocks(mojo) {
this.deviceCloseHandler_ = null;
}
+ bindToPipe(pipe) {
+ this.stub_ = connection.bindHandleToStub(
+ pipe, deviceManager.DeviceManager);
+ bindings.StubBindings(this.stub_).delegate = this;
+ }
+
reset() {
this.mockDevices_.forEach(device => {
- for (var handle of device.handles)
- mojo.core.close(handle.pipe_);
+ for (var stub of device.stubs)
+ bindings.StubBindings(stub).close();
this.removedDevices_.push(device.info);
});
this.mockDevices_.clear();
@@ -354,7 +350,7 @@ function usbMocks(mojo) {
addMockDevice(info) {
let device = {
info: info,
- handles: []
+ stubs: []
};
this.mockDevices_.set(info.guid, device);
this.addedDevices_.push(info);
@@ -363,8 +359,8 @@ function usbMocks(mojo) {
removeMockDevice(info) {
let device = this.mockDevices_.get(info.guid);
- for (var handle of device.handles)
- mojo.core.close(handle.pipe_);
+ for (var stub of device.stubs)
+ bindings.StubBindings(stub).close();
this.mockDevices_.delete(info.guid);
this.removedDevices_.push(info);
this.maybeResolveDeviceChangePromise();
@@ -374,12 +370,6 @@ function usbMocks(mojo) {
this.deviceCloseHandler_ = handler;
}
- bindToPipe(pipe) {
- assert_equals(this.router_, null);
- this.router_ = new mojo.router.Router(pipe);
- this.router_.setIncomingReceiver(this);
- }
-
getDevices(options) {
let devices = [];
this.mockDevices_.forEach(device => {
@@ -416,32 +406,31 @@ function usbMocks(mojo) {
this.removedDevices_ = [];
}
- getDevice(guid, pipe) {
+ getDevice(guid, stub) {
let device = this.mockDevices_.get(guid);
if (device === undefined) {
- mojo.core.close(pipe);
+ bindings.StubBindings(stub).close();
} else {
- var mock = new MockDevice(device.info, pipe, () => {
+ var mock = new MockDevice(device.info);
+ bindings.StubBindings(stub).delegate = mock;
+ bindings.StubBindings(stub).connectionErrorHandler = () => {
if (this.deviceCloseHandler_)
this.deviceCloseHandler_(device.info);
- });
- device.handles.push(mock);
+ };
+ device.stubs.push(stub);
}
}
}
- class MockChooserService
- extends chooserService.ChooserService.stubClass {
+ class MockChooserService {
constructor() {
- super();
- this.router_ = null;
this.chosenDevice_ = null;
}
bindToPipe(pipe) {
- assert_equals(this.router_, null);
- this.router_ = new mojo.router.Router(pipe);
- this.router_.setIncomingReceiver(this);
+ this.stub_ = connection.bindHandleToStub(
+ pipe, chooserService.ChooserService);
+ bindings.StubBindings(this.stub_).delegate = this;
}
setChosenDevice(deviceInfo) {

Powered by Google App Engine
This is Rietveld 408576698