OLD | NEW |
| (Empty) |
1 'use strict'; | |
2 | |
3 function usb_test(func, name, properties) { | |
4 promise_test(() => { | |
5 return navigator.usb.test.initialize().then(() => { | |
6 let testResult = func(); | |
7 let cleanup = () => { | |
8 navigator.usb.test.reset(); | |
9 }; | |
10 testResult.then(cleanup, cleanup); | |
11 return testResult; | |
12 }); | |
13 }, name, properties); | |
14 } | |
15 | |
16 function assertRejectsWithError(promise, name, message) { | |
17 return promise.then(() => { | |
18 assert_unreached('expected promise to reject with ' + name); | |
19 }, error => { | |
20 assert_equals(error.name, name); | |
21 if (message !== undefined) | |
22 assert_equals(error.message, message); | |
23 }); | |
24 } | |
25 | |
26 function assertDeviceInfoEquals(usbDevice, deviceInit) { | |
27 for (var property in deviceInit) { | |
28 if (property == 'activeConfigurationValue') { | |
29 if (deviceInit.activeConfigurationValue == 0) { | |
30 assert_equals(usbDevice.configuration, null); | |
31 } else { | |
32 assert_equals(usbDevice.configuration.configurationValue, | |
33 deviceInit.activeConfigurationValue); | |
34 } | |
35 } else if (Array.isArray(deviceInit[property])) { | |
36 assert_equals(usbDevice[property].length, deviceInit[property].length); | |
37 for (var i = 0; i < usbDevice[property].length; ++i) | |
38 assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]); | |
39 } else { | |
40 assert_equals(usbDevice[property], deviceInit[property], property); | |
41 } | |
42 } | |
43 } | |
44 | |
45 // TODO(reillyg): Remove when jyasskin upstreams this to testharness.js: | |
46 // https://crbug.com/509058. | |
47 function callWithKeyDown(functionCalledOnKeyPress) { | |
48 return new Promise(resolve => { | |
49 function onKeyPress() { | |
50 document.removeEventListener('keypress', onKeyPress, false); | |
51 resolve(functionCalledOnKeyPress()); | |
52 } | |
53 document.addEventListener('keypress', onKeyPress, false); | |
54 | |
55 eventSender.keyDown(' ', []); | |
56 }); | |
57 } | |
58 | |
59 function runGarbageCollection() { | |
60 // Run gc() as a promise. | |
61 return new Promise((resolve, reject) => { | |
62 GCController.collect(); | |
63 setTimeout(resolve, 0); | |
64 }); | |
65 } | |
OLD | NEW |