OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="../resources/mojo-helpers.js"></script> | |
5 <script src="resources/fake-devices.js"></script> | 4 <script src="resources/fake-devices.js"></script> |
6 <script src="resources/usb-helpers.js"></script> | 5 <script src="resources/usb-helpers.js"></script> |
| 6 <script src="resources/webusb-test.js"></script> |
7 <script> | 7 <script> |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 usb_test(usb => { | 10 usb_test(() => { |
11 usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); | 11 navigator.usb.test.addFakeDevice(fakeDeviceInit); |
12 | 12 |
13 return navigator.usb.getDevices().then(devices => { | 13 return navigator.usb.getDevices().then(devices => { |
14 assert_equals(devices.length, 1); | 14 assert_equals(devices.length, 1); |
15 let evt = new USBConnectionEvent('connect', { device: devices[0] }); | 15 let evt = new USBConnectionEvent('connect', { device: devices[0] }); |
16 assert_equals(evt.type, 'connect'); | 16 assert_equals(evt.type, 'connect'); |
17 assert_equals(evt.device, devices[0]); | 17 assert_equals(evt.device, devices[0]); |
18 }); | 18 }); |
19 }, 'Can construct a USBConnectionEvent with a device'); | 19 }, 'Can construct a USBConnectionEvent with a device'); |
20 | 20 |
21 test(t => { | 21 test(t => { |
22 try { | 22 try { |
23 new USBConnectionEvent('connect', { device: null }); | 23 new USBConnectionEvent('connect', { device: null }); |
24 assert_unreached('expected TypeError'); | 24 assert_unreached('expected TypeError'); |
25 } catch (err) { | 25 } catch (err) { |
26 assert_true(err instanceof TypeError); | 26 assert_true(err instanceof TypeError); |
27 } | 27 } |
28 | 28 |
29 try { | 29 try { |
30 new USBConnectionEvent('connect', {}) | 30 new USBConnectionEvent('connect', {}) |
31 assert_unreached('expected TypeError'); | 31 assert_unreached('expected TypeError'); |
32 } catch (err) { | 32 } catch (err) { |
33 assert_true(err instanceof TypeError); | 33 assert_true(err instanceof TypeError); |
34 } | 34 } |
35 }, 'Cannot construct a USBConnectionEvent without a device'); | 35 }, 'Cannot construct a USBConnectionEvent without a device'); |
36 </script> | 36 </script> |
OLD | NEW |