protected-interface-classes.https.any.js (2619B)
1 // META: script=/resources/test-only-api.js 2 // META: script=/webusb/resources/usb-helpers.js 3 'use strict'; 4 5 async function runTestForInterfaceClass(t, interfaceClass) { 6 await navigator.usb.test.initialize(); 7 8 const fakeDeviceTemplate = { 9 usbVersionMajor: 2, 10 usbVersionMinor: 0, 11 usbVersionSubminor: 0, 12 deviceClass: 7, 13 deviceSubclass: 1, 14 deviceProtocol: 2, 15 vendorId: 0x18d1, 16 productId: 0xf00d, 17 deviceVersionMajor: 1, 18 deviceVersionMinor: 2, 19 deviceVersionSubminor: 3, 20 manufacturerName: 'Google, Inc.', 21 productName: 'Test Device', 22 serialNumber: '4 (chosen randomly)', 23 activeConfigurationValue: 0, 24 configurations: [{ 25 configurationValue: 1, 26 configurationName: 'Default configuration', 27 interfaces: [{ 28 interfaceNumber: 0, 29 alternates: [{ 30 alternateSetting: 0, 31 interfaceClass: interfaceClass, 32 interfaceSubclass: 0x01, 33 interfaceProtocol: 0x01, 34 interfaceName: 'Protected interface', 35 endpoints: [] 36 }] 37 }, { 38 interfaceNumber: 1, 39 alternates: [{ 40 alternateSetting: 0, 41 interfaceClass: 0xff, 42 interfaceSubclass: 0x01, 43 interfaceProtocol: 0x01, 44 interfaceName: 'Unprotected interface', 45 endpoints: [] 46 }] 47 }] 48 }] 49 }; 50 51 let fakeDevice; 52 let device = await new Promise((resolve) => { 53 navigator.usb.addEventListener('connect', (e) => { 54 resolve(e.device); 55 }, { once: true }); 56 fakeDevice = navigator.usb.test.addFakeDevice(fakeDeviceTemplate); 57 }); 58 59 await device.open(); 60 await device.selectConfiguration(1); 61 62 await promise_rejects_dom(t, 'SecurityError', device.claimInterface(0)); 63 await device.claimInterface(1); 64 65 await device.close(); 66 fakeDevice.disconnect(); 67 } 68 69 usb_test( 70 (t) => runTestForInterfaceClass(t, 0x01), 71 'Protected audio interface cannot be claimed'); 72 usb_test( 73 (t) => runTestForInterfaceClass(t, 0x03), 74 'Protected HID interface cannot be claimed'); 75 usb_test( 76 (t) => runTestForInterfaceClass(t, 0x08), 77 'Protected mass storage interface cannot be claimed'); 78 usb_test( 79 (t) => runTestForInterfaceClass(t, 0x0B), 80 'Protected smart card interface cannot be claimed'); 81 usb_test( 82 (t) => runTestForInterfaceClass(t, 0x0E), 83 'Protected video interface cannot be claimed'); 84 usb_test( 85 (t) => runTestForInterfaceClass(t, 0x10), 86 'Protected audio/video interface cannot be claimed'); 87 usb_test( 88 (t) => runTestForInterfaceClass(t, 0xE0), 89 'Protected wireless controller interface cannot be claimed');