OLD | NEW |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 // TODO(reillyg): Remove when jyasskin upstreams this to testharness.js: | 3 // TODO(reillyg): Remove when jyasskin upstreams this to testharness.js: |
4 // https://crbug.com/509058. | 4 // https://crbug.com/509058. |
5 function callWithKeyDown(functionCalledOnKeyPress) { | 5 function callWithKeyDown(functionCalledOnKeyPress) { |
6 return new Promise(resolve => { | 6 return new Promise(resolve => { |
7 function onKeyPress() { | 7 function onKeyPress() { |
8 document.removeEventListener('keypress', onKeyPress, false); | 8 document.removeEventListener('keypress', onKeyPress, false); |
9 resolve(functionCalledOnKeyPress()); | 9 resolve(functionCalledOnKeyPress()); |
10 } | 10 } |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 devices_added: this.addedDevices_, | 364 devices_added: this.addedDevices_, |
365 devices_removed: this.removedDevices_ | 365 devices_removed: this.removedDevices_ |
366 } | 366 } |
367 }); | 367 }); |
368 this.addedDevices_ = []; | 368 this.addedDevices_ = []; |
369 this.removedDevices_ = []; | 369 this.removedDevices_ = []; |
370 } | 370 } |
371 | 371 |
372 getDevice(guid, pipe) { | 372 getDevice(guid, pipe) { |
373 let device = this.mockDevices_.get(guid); | 373 let device = this.mockDevices_.get(guid); |
374 if (device !== undefined) { | 374 if (device === undefined) { |
375 // In C++ this happens automatically if the pipe is not bound to a | |
376 // new device but must be explicit in JavaScript to avoid dependency | |
377 // on GC timing. | |
378 mojo.core.close(pipe); | |
Ken Rockot(use gerrit already)
2016/03/02 01:54:19
nit: I'm not sure this comment belongs here. It's
Reilly Grant (use Gerrit)
2016/03/02 19:13:26
Agreed.
| |
379 } else { | |
375 var mock = new MockDevice(device.info, pipe); | 380 var mock = new MockDevice(device.info, pipe); |
376 device.handles.push(mock); | 381 device.handles.push(mock); |
377 } | 382 } |
378 } | 383 } |
379 } | 384 } |
380 | 385 |
381 class MockPermissionBubble | 386 class MockPermissionBubble |
382 extends permissionBubble.WebUsbPermissionBubble.stubClass { | 387 extends permissionBubble.WebUsbPermissionBubble.stubClass { |
383 constructor() { | 388 constructor() { |
384 super(); | 389 super(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 } | 433 } |
429 | 434 |
430 function usb_test(func, name, properties) { | 435 function usb_test(func, name, properties) { |
431 mojo_test(mojo => usbMocks(mojo).then(usb => { | 436 mojo_test(mojo => usbMocks(mojo).then(usb => { |
432 let result = Promise.resolve(func(usb)); | 437 let result = Promise.resolve(func(usb)); |
433 let cleanUp = () => usb.mockDeviceManager.reset(); | 438 let cleanUp = () => usb.mockDeviceManager.reset(); |
434 result.then(cleanUp, cleanUp); | 439 result.then(cleanUp, cleanUp); |
435 return result; | 440 return result; |
436 }), name, properties); | 441 }), name, properties); |
437 } | 442 } |
OLD | NEW |