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

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

Issue 2594213002: Mojo JS bindings: change usb layout tests to use the new "bindings" module. (Closed)
Patch Set: . Created 4 years 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/usb/usbDevice-iframe.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 455601e96c951e9cab2aa41ee419ac2bf7f49748..9bd8ac054c897a96abf4dae3ff8076edaef7b853 100644
--- a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
+++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js
@@ -35,11 +35,10 @@ 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',
- ], (bindings, connection, chooserService, deviceManager, device) => {
+ ], (bindings, chooserService, deviceManager, device) => {
function assertDeviceInfoEquals(device, info) {
assert_equals(device.usbVersionMajor, info.usb_version_major);
assert_equals(device.usbVersionMinor, info.usb_version_minor);
@@ -323,21 +322,17 @@ function usbMocks(mojo) {
class MockDeviceManager {
constructor() {
+ this.bindingSet = new bindings.BindingSet(deviceManager.DeviceManager);
+
this.mockDevices_ = new Map();
this.deviceCloseHandler_ = null;
this.client_ = null;
}
- bindToPipe(pipe) {
- this.stub_ = connection.bindHandleToStub(
- pipe, deviceManager.DeviceManager);
- bindings.StubBindings(this.stub_).delegate = this;
- }
-
reset() {
this.mockDevices_.forEach(device => {
- for (var stub of device.stubs)
- bindings.StubBindings(stub).close();
+ for (var binding of device.bindingArray)
+ binding.close();
this.client_.onDeviceRemoved(device.info);
});
this.mockDevices_.clear();
@@ -346,7 +341,7 @@ function usbMocks(mojo) {
addMockDevice(info) {
let device = {
info: info,
- stubs: []
+ bindingArray: []
};
this.mockDevices_.set(info.guid, device);
if (this.client_)
@@ -355,8 +350,8 @@ function usbMocks(mojo) {
removeMockDevice(info) {
let device = this.mockDevices_.get(info.guid);
- for (var stub of device.stubs)
- bindings.StubBindings(stub).close();
+ for (var binding of device.bindingArray)
+ binding.close();
this.mockDevices_.delete(info.guid);
if (this.client_)
this.client_.onDeviceRemoved(info);
@@ -379,14 +374,13 @@ function usbMocks(mojo) {
if (deviceData === undefined) {
request.close();
} else {
- var stub = connection.bindHandleToStub(request.handle, device.Device);
- var mock = new MockDevice(deviceData.info);
- bindings.StubBindings(stub).delegate = mock;
- bindings.StubBindings(stub).connectionErrorHandler = () => {
+ var binding = new bindings.Binding(
+ device.Device, new MockDevice(deviceData.info), request);
+ binding.setConnectionErrorHandler(() => {
if (this.deviceCloseHandler_)
this.deviceCloseHandler_(deviceData.info);
- };
- deviceData.stubs.push(stub);
+ });
+ deviceData.bindingArray.push(binding);
}
}
@@ -397,13 +391,10 @@ function usbMocks(mojo) {
class MockChooserService {
constructor() {
- this.chosenDevice_ = null;
- }
+ this.bindingSet = new bindings.BindingSet(
+ chooserService.ChooserService);
- bindToPipe(pipe) {
- this.stub_ = connection.bindHandleToStub(
- pipe, chooserService.ChooserService);
- bindings.StubBindings(this.stub_).delegate = this;
+ this.chosenDevice_ = null;
}
setChosenDevice(deviceInfo) {
@@ -418,15 +409,15 @@ function usbMocks(mojo) {
let mockDeviceManager = new MockDeviceManager;
mojo.frameInterfaces.addInterfaceOverrideForTesting(
deviceManager.DeviceManager.name,
- pipe => {
- mockDeviceManager.bindToPipe(pipe);
+ handle => {
+ mockDeviceManager.bindingSet.addBinding(mockDeviceManager, handle);
});
let mockChooserService = new MockChooserService;
mojo.frameInterfaces.addInterfaceOverrideForTesting(
chooserService.ChooserService.name,
- pipe => {
- mockChooserService.bindToPipe(pipe);
+ handle => {
+ mockChooserService.bindingSet.addBinding(mockChooserService, handle);
});
return fakeUsbDevices().then(fakeDevices => Promise.resolve({
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/usb/usbDevice-iframe.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698