Automatic update from web-platform-tests Remove expected exception messages from WebUSB tests While the exception name is specified, the exact message may depend on implementation-specific behavior. This change removes cases where the WebUSB tests asserted that exceptions contained specific messages. In the process the assertRejectsWithError() and similar helpers have been replaced by the standard promise_rejects_dom() and promise_rejects_js() methods from the testharness.js framework. This change is the first in a series which switches WebUSB to construct DOMExceptions using a blink::ExceptionState object, which will add additional diagnostic information to the exception message which is not compatible with these tests as written. Change-Id: I5780106d2c7335c0e03502e742ca6c97604752d2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3630436 Auto-Submit: Reilly Grant <reillyg@chromium.org> Reviewed-by: Hongchan Choi <hongchan@chromium.org> Commit-Queue: Hongchan Choi <hongchan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1000668} -- wpt-commits: 3d522de930aca526c850660d1a19af5ac0f21509 wpt-pr: 33977
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
// META: script=/resources/test-only-api.js
|
|
// META: script=/webusb/resources/usb-helpers.js
|
|
'use strict';
|
|
|
|
async function runTestForInterfaceClass(t, 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);
|
|
|
|
await promise_rejects_dom(t, 'SecurityError', device.claimInterface(0));
|
|
await device.claimInterface(1);
|
|
|
|
await device.close();
|
|
fakeDevice.disconnect();
|
|
}
|
|
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x01),
|
|
'Protected audio interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x03),
|
|
'Protected HID interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x08),
|
|
'Protected mass storage interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x0B),
|
|
'Protected smart card interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x0E),
|
|
'Protected video interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0x10),
|
|
'Protected audio/video interface cannot be claimed');
|
|
usb_test(
|
|
(t) => runTestForInterfaceClass(t, 0xE0),
|
|
'Protected wireless controller interface cannot be claimed');
|