|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <meta charset=utf-8> |
| 5 | + <title>WebUSB IDL test</title> |
| 6 | + <link rel="help" href="https://wicg.github.io/webusb/"> |
| 7 | + <script src=/resources/testharness.js></script> |
| 8 | + <script src=/resources/testharnessreport.js></script> |
| 9 | + <script src=/resources/WebIDLParser.js></script> |
| 10 | + <script src=/resources/idlharness.js></script> |
| 11 | + </head> |
| 12 | + <body> |
| 13 | + <script type="text/plain" id="untested"> |
| 14 | + interface Event {}; |
| 15 | + dictionary EventInit {}; |
| 16 | + interface EventHandler {}; |
| 17 | + interface EventTarget {}; |
| 18 | + interface Navigator {}; |
| 19 | + </script> |
| 20 | + <script type="text/plain" id="tested"> |
| 21 | + // Copied from https://wicg.github.io/webusb/#idl-index minus the |
| 22 | + // definitions related to Permissions API integration which is unstable. |
| 23 | + |
| 24 | + dictionary USBDeviceFilter { |
| 25 | + unsigned short vendorId; |
| 26 | + unsigned short productId; |
| 27 | + octet classCode; |
| 28 | + octet subclassCode; |
| 29 | + octet protocolCode; |
| 30 | + DOMString serialNumber; |
| 31 | + }; |
| 32 | + |
| 33 | + dictionary USBDeviceRequestOptions { |
| 34 | + required sequence<USBDeviceFilter> filters; |
| 35 | + }; |
| 36 | + |
| 37 | + interface USB : EventTarget { |
| 38 | + attribute EventHandler onconnect; |
| 39 | + attribute EventHandler ondisconnect; |
| 40 | + Promise<sequence<USBDevice>> getDevices(); |
| 41 | + Promise<USBDevice> requestDevice(USBDeviceRequestOptions options); |
| 42 | + }; |
| 43 | + |
| 44 | + [SecureContext] |
| 45 | + partial interface Navigator { |
| 46 | + [SameObject] readonly attribute USB usb; |
| 47 | + }; |
| 48 | + |
| 49 | + dictionary USBConnectionEventInit : EventInit { |
| 50 | + required USBDevice device; |
| 51 | + }; |
| 52 | + |
| 53 | + [Constructor(DOMString type, USBConnectionEventInit eventInitDict)] |
| 54 | + interface USBConnectionEvent : Event { |
| 55 | + [SameObject] readonly attribute USBDevice device; |
| 56 | + }; |
| 57 | + |
| 58 | + interface USBDevice { |
| 59 | + readonly attribute octet usbVersionMajor; |
| 60 | + readonly attribute octet usbVersionMinor; |
| 61 | + readonly attribute octet usbVersionSubminor; |
| 62 | + readonly attribute octet deviceClass; |
| 63 | + readonly attribute octet deviceSubclass; |
| 64 | + readonly attribute octet deviceProtocol; |
| 65 | + readonly attribute unsigned short vendorId; |
| 66 | + readonly attribute unsigned short productId; |
| 67 | + readonly attribute octet deviceVersionMajor; |
| 68 | + readonly attribute octet deviceVersionMinor; |
| 69 | + readonly attribute octet deviceVersionSubminor; |
| 70 | + readonly attribute DOMString? manufacturerName; |
| 71 | + readonly attribute DOMString? productName; |
| 72 | + readonly attribute DOMString? serialNumber; |
| 73 | + readonly attribute USBConfiguration? configuration; |
| 74 | + readonly attribute FrozenArray<USBConfiguration> configurations; |
| 75 | + readonly attribute boolean opened; |
| 76 | + Promise<void> open(); |
| 77 | + Promise<void> close(); |
| 78 | + Promise<void> selectConfiguration(octet configurationValue); |
| 79 | + Promise<void> claimInterface(octet interfaceNumber); |
| 80 | + Promise<void> releaseInterface(octet interfaceNumber); |
| 81 | + Promise<void> selectAlternateInterface(octet interfaceNumber, octet alternateSetting); |
| 82 | + Promise<USBInTransferResult> controlTransferIn(USBControlTransferParameters setup, unsigned short length); |
| 83 | + Promise<USBOutTransferResult> controlTransferOut(USBControlTransferParameters setup, optional BufferSource data); |
| 84 | + Promise<void> clearHalt(USBDirection direction, octet endpointNumber); |
| 85 | + Promise<USBInTransferResult> transferIn(octet endpointNumber, unsigned long length); |
| 86 | + Promise<USBOutTransferResult> transferOut(octet endpointNumber, BufferSource data); |
| 87 | + Promise<USBIsochronousInTransferResult> isochronousTransferIn(octet endpointNumber, sequence<unsigned long> packetLengths); |
| 88 | + Promise<USBIsochronousOutTransferResult> isochronousTransferOut(octet endpointNumber, BufferSource data, sequence<unsigned long> packetLengths); |
| 89 | + Promise<void> reset(); |
| 90 | + }; |
| 91 | + |
| 92 | + enum USBRequestType { |
| 93 | + "standard", |
| 94 | + "class", |
| 95 | + "vendor" |
| 96 | + }; |
| 97 | + |
| 98 | + enum USBRecipient { |
| 99 | + "device", |
| 100 | + "interface", |
| 101 | + "endpoint", |
| 102 | + "other" |
| 103 | + }; |
| 104 | + |
| 105 | + enum USBTransferStatus { |
| 106 | + "ok", |
| 107 | + "stall", |
| 108 | + "babble" |
| 109 | + }; |
| 110 | + |
| 111 | + dictionary USBControlTransferParameters { |
| 112 | + required USBRequestType requestType; |
| 113 | + required USBRecipient recipient; |
| 114 | + required octet request; |
| 115 | + required unsigned short value; |
| 116 | + required unsigned short index; |
| 117 | + }; |
| 118 | + |
| 119 | + [Constructor(USBTransferStatus status, optional DataView? data)] |
| 120 | + interface USBInTransferResult { |
| 121 | + readonly attribute DataView? data; |
| 122 | + readonly attribute USBTransferStatus status; |
| 123 | + }; |
| 124 | + |
| 125 | + [Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)] |
| 126 | + interface USBOutTransferResult { |
| 127 | + readonly attribute unsigned long bytesWritten; |
| 128 | + readonly attribute USBTransferStatus status; |
| 129 | + }; |
| 130 | + |
| 131 | + [Constructor(USBTransferStatus status, optional DataView? data)] |
| 132 | + interface USBIsochronousInTransferPacket { |
| 133 | + readonly attribute DataView? data; |
| 134 | + readonly attribute USBTransferStatus status; |
| 135 | + }; |
| 136 | + |
| 137 | + [Constructor(sequence<USBIsochronousInTransferPacket> packets, optional DataView? data)] |
| 138 | + interface USBIsochronousInTransferResult { |
| 139 | + readonly attribute DataView? data; |
| 140 | + readonly attribute FrozenArray<USBIsochronousInTransferPacket> packets; |
| 141 | + }; |
| 142 | + |
| 143 | + [Constructor(USBTransferStatus status, optional unsigned long bytesWritten = 0)] |
| 144 | + interface USBIsochronousOutTransferPacket { |
| 145 | + readonly attribute unsigned long bytesWritten; |
| 146 | + readonly attribute USBTransferStatus status; |
| 147 | + }; |
| 148 | + |
| 149 | + [Constructor(sequence<USBIsochronousOutTransferPacket> packets)] |
| 150 | + interface USBIsochronousOutTransferResult { |
| 151 | + readonly attribute FrozenArray<USBIsochronousOutTransferPacket> packets; |
| 152 | + }; |
| 153 | + |
| 154 | + [Constructor(USBDevice device, octet configurationValue)] |
| 155 | + interface USBConfiguration { |
| 156 | + readonly attribute octet configurationValue; |
| 157 | + readonly attribute DOMString? configurationName; |
| 158 | + readonly attribute FrozenArray<USBInterface> interfaces; |
| 159 | + }; |
| 160 | + |
| 161 | + [Constructor(USBConfiguration configuration, octet interfaceNumber)] |
| 162 | + interface USBInterface { |
| 163 | + readonly attribute octet interfaceNumber; |
| 164 | + readonly attribute USBAlternateInterface alternate; |
| 165 | + readonly attribute FrozenArray<USBAlternateInterface> alternates; |
| 166 | + readonly attribute boolean claimed; |
| 167 | + }; |
| 168 | + |
| 169 | + [Constructor(USBInterface deviceInterface, octet alternateSetting)] |
| 170 | + interface USBAlternateInterface { |
| 171 | + readonly attribute octet alternateSetting; |
| 172 | + readonly attribute octet interfaceClass; |
| 173 | + readonly attribute octet interfaceSubclass; |
| 174 | + readonly attribute octet interfaceProtocol; |
| 175 | + readonly attribute DOMString? interfaceName; |
| 176 | + readonly attribute FrozenArray<USBEndpoint> endpoints; |
| 177 | + }; |
| 178 | + |
| 179 | + enum USBDirection { |
| 180 | + "in", |
| 181 | + "out" |
| 182 | + }; |
| 183 | + |
| 184 | + enum USBEndpointType { |
| 185 | + "bulk", |
| 186 | + "interrupt", |
| 187 | + "isochronous" |
| 188 | + }; |
| 189 | + |
| 190 | + [Constructor(USBAlternateInterface alternate, octet endpointNumber, USBDirection direction)] |
| 191 | + interface USBEndpoint { |
| 192 | + readonly attribute octet endpointNumber; |
| 193 | + readonly attribute USBDirection direction; |
| 194 | + readonly attribute USBEndpointType type; |
| 195 | + readonly attribute unsigned long packetSize; |
| 196 | + }; |
| 197 | + </script> |
| 198 | + <script> |
| 199 | + 'use strict'; |
| 200 | + |
| 201 | + var idl_array = new IdlArray(); |
| 202 | + idl_array.add_untested_idls(document.querySelector('#untested').textContent); |
| 203 | + idl_array.add_idls(document.querySelector('#tested').textContent); |
| 204 | + idl_array.add_objects({ |
| 205 | + Navigator: ['navigator'], |
| 206 | + USB: ['navigator.usb'], |
| 207 | + USBInTransferResult: ['new USBInTransferResult("ok")'], |
| 208 | + USBOutTransferResult: ['new USBOutTransferResult("ok")'], |
| 209 | + USBIsochronousInTransferResult: ['new USBIsochronousInTransferResult([])'], |
| 210 | + USBIsochronousOutTransferResult: ['new USBIsochronousOutTransferResult([])'], |
| 211 | + USBIsochronousInTransferPacket: ['new USBIsochronousInTransferPacket("ok")'], |
| 212 | + USBIsochronousOutTransferPacket: ['new USBIsochronousOutTransferPacket("ok")'] |
| 213 | + }); |
| 214 | + idl_array.test(); |
| 215 | + </script> |
| 216 | + </body> |
| 217 | +</html> |
0 commit comments