| Index: third_party/WebKit/LayoutTests/usb/resources/webusb-test.js
|
| diff --git a/third_party/WebKit/LayoutTests/usb/resources/webusb-test.js b/third_party/WebKit/LayoutTests/usb/resources/webusb-test.js
|
| index 2af2182cb3debc780fad8e2dfbd0aeeb8dcbc626..cc0a64db0caf92076ece9ad30c78101b8f8ea95b 100644
|
| --- a/third_party/WebKit/LayoutTests/usb/resources/webusb-test.js
|
| +++ b/third_party/WebKit/LayoutTests/usb/resources/webusb-test.js
|
| @@ -76,6 +76,7 @@ let g_initializePromise = null;
|
| let g_chooserService = null;
|
| let g_deviceManager = null;
|
| let g_closeListener = null;
|
| +let g_nextGuid = 0;
|
|
|
| function fakeDeviceInitToDeviceInfo(guid, init) {
|
| let deviceInfo = {
|
| @@ -358,20 +359,22 @@ class FakeDeviceManager {
|
| this.bindingSet_.addBinding(this, handle);
|
| }
|
|
|
| - addDevice(info) {
|
| + addDevice(guid, info) {
|
| let device = {
|
| - guid: this.nextGuid_++ + "",
|
| + guid: guid,
|
| info: info,
|
| bindingArray: []
|
| };
|
| this.devices_.set(device.guid, device);
|
| if (this.client_)
|
| this.client_.onDeviceAdded(fakeDeviceInitToDeviceInfo(device.guid, info));
|
| - return device.guid;
|
| }
|
|
|
| removeDevice(guid) {
|
| let device = this.devices_.get(guid);
|
| + if (!device)
|
| + throw new Error('Cannot remove unknown device "' + guid + '"');
|
| +
|
| for (var binding of device.bindingArray)
|
| binding.close();
|
| this.devices_.delete(guid);
|
| @@ -526,14 +529,19 @@ class USBTest {
|
| if (!g_deviceManager)
|
| throw new Error('Call initialize() before addFakeDevice().');
|
|
|
| - return g_deviceManager.addDevice(deviceInit);
|
| + // |addDevice| and |removeDevice| are called in a setTimeout callback so
|
| + // that tests do not rely on the device being immediately available which
|
| + // may not be true for all implementations of this test API.
|
| + let guid = (g_nextGuid++).toString();
|
| + setTimeout(() => g_deviceManager.addDevice(guid, deviceInit), 0);
|
| + return guid;
|
| }
|
|
|
| removeFakeDevice(guid) {
|
| if (!g_deviceManager)
|
| throw new Error('Call initialize() before removeFakeDevice().');
|
|
|
| - return g_deviceManager.removeDevice(guid);
|
| + setTimeout(() => g_deviceManager.removeDevice(guid), 0);
|
| }
|
|
|
| set ondeviceclose(func) {
|
|
|