| <!DOCTYPE html> |
| <script src="../resources/testharness.js"></script> |
| <script src="../resources/testharnessreport.js"></script> |
| <script src="../external/wpt/resources/chromium/mojo_bindings.js"></script> |
| <script src="../external/wpt/resources/chromium/string16.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/device.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/device_enumeration_options.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/device_manager_client.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/web_usb_service.mojom.js"></script> |
| <script src="../external/wpt/resources/chromium/webusb-test.js"></script> |
| <body> |
| <script> |
| 'use strict'; |
| |
| async function runTestForInterfaceClass(interfaceClass) { |
| await navigator.usb.test.initialize(); |
| |
| const fakeDeviceTemplate = { |
| usbVersionMajor: 2, |
| usbVersionMinor: 0, |
| usbVersionSubminor: 0, |
| deviceClass: 7, |
| deviceSubclass: 1, |
| deviceProtocol: 2, |
| vendorId: 0x18d1, |
| productId: 0xf00d, |
| deviceVersionMajor: 1, |
| deviceVersionMinor: 2, |
| deviceVersionSubminor: 3, |
| manufacturerName: 'Google, Inc.', |
| productName: 'Test Device', |
| serialNumber: '4 (chosen randomly)', |
| activeConfigurationValue: 0, |
| configurations: [{ |
| configurationValue: 1, |
| configurationName: 'Default configuration', |
| interfaces: [{ |
| interfaceNumber: 0, |
| alternates: [{ |
| alternateSetting: 0, |
| interfaceClass: interfaceClass, |
| interfaceSubclass: 0x01, |
| interfaceProtocol: 0x01, |
| interfaceName: 'Protected interface', |
| endpoints: [] |
| }] |
| }, { |
| interfaceNumber: 1, |
| alternates: [{ |
| alternateSetting: 0, |
| interfaceClass: 0xff, |
| interfaceSubclass: 0x01, |
| interfaceProtocol: 0x01, |
| interfaceName: 'Unprotected interface', |
| endpoints: [] |
| }] |
| }] |
| }] |
| }; |
| |
| let fakeDevice; |
| let device = await new Promise((resolve) => { |
| navigator.usb.addEventListener('connect', (e) => { |
| resolve(e.device); |
| }, { once: true }); |
| fakeDevice = navigator.usb.test.addFakeDevice(fakeDeviceTemplate); |
| }); |
| |
| await device.open(); |
| await device.selectConfiguration(1); |
| |
| try { |
| await device.claimInterface(0); |
| assert_unreached('Should not be able to claim a protected interface.'); |
| } catch (e) { |
| assert_equals(e.name, 'SecurityError'); |
| assert_equals(e.message, |
| 'The requested interface implements a protected class.'); |
| } |
| |
| await device.claimInterface(1); |
| await device.close(); |
| fakeDevice.disconnect(); |
| } |
| |
| promise_test(() => runTestForInterfaceClass(0x01), |
| 'Protected audio interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0x03), |
| 'Protected HID interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0x08), |
| 'Protected mass storage interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0x0B), |
| 'Protected smart card interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0x0E), |
| 'Protected video interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0x10), |
| 'Protected audio/video interface cannot be claimed'); |
| promise_test(() => runTestForInterfaceClass(0xE0), |
| 'Protected wireless controller interface cannot be claimed'); |
| </script> |
| </body> |