Chromium Code Reviews| 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 0ec82916bf90d4e1709cd26e63e628d8271c8895..e09689176419a9eb55bef72671bf342733348c92 100644 |
| --- a/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js |
| +++ b/third_party/WebKit/LayoutTests/usb/resources/usb-helpers.js |
| @@ -13,6 +13,25 @@ function usb_test(func, name, properties) { |
| }, name, properties); |
| } |
| +// Returns a promise that is resolved when the next USBConnectionEvent of the |
| +// given type is received. |
| +function connectionEventPromise(eventType) { |
| + return new Promise(resolve => { |
| + let eventHandler = e => { |
| + assert_true(e instanceof USBConnectionEvent); |
| + navigator.usb.removeEventListener(eventType, eventHandler); |
| + resolve(e.device); |
| + }; |
| + navigator.usb.addEventListener(eventType, eventHandler); |
| + }); |
| +} |
| + |
| +function getConnectedDevice(deviceInit) { |
|
ortuno
2017/04/12 03:31:07
Comment what the function does.
Optional: You mig
Reilly Grant (use Gerrit)
2017/04/12 22:47:07
Done.
|
| + let promise = connectionEventPromise('connect'); |
| + navigator.usb.test.addFakeDevice(deviceInit); |
| + return promise; |
| +} |
| + |
| function assertRejectsWithError(promise, name, message) { |
| return promise.then(() => { |
| assert_unreached('expected promise to reject with ' + name); |