services/device/usb
abstracts Universal Serial Bus concepts across multiple platforms.
Clients should use the public Mojo interface.
/third_party/usb_ids/usb.ids
is imported regularly to provide human-readable descriptions of USB devices.
libusb
UsbService
is implemented by UsbServiceImpl
based on third_party/libusb
.
Work is ongoing to implement each platform directly, without using libusb
.
UsbServiceAndroid
done.UsbServiceLinux
done.UsbServiceWin
in progress. Enable via chrome://flags/#new-usb-backend
Standard use of *_unittest.cc
files for must code coverage.
libFuzzer tests are in *_fuzzer.cc
files. They test for bad input from devices, e.g. when parsing device descriptors during device enumeration.
USB/HID API Testing with Gadgets describes a framework for testing the Chrome USB, HID and serial device APIs with real devices on generally accessible hardware.
Unit tests using the gadget can be run manually with a hardware “gadget”. These unit tests all call UsbTestGadget::Claim.
When making changes to platform-specific code the following manual test steps should be run to augment automated testing, which is mostly limited to platform-independent logic. These tests require an Android phone with USB debugging enabled and support for USB tethering. When USB debugging is enabled the device creates a vendor-specific interface for the ADB protocol. On Windows, with the OEM USB drivers installed this interface will have the WinUSB.sys driver loaded. When USB tethering is enabled the device creates an RNDIS interface for which most operating systems have a built-in driver. With both of these features enabled the device will have two interfaces and thus be a “composite” device. This is important for testing on Windows as composite and non-composite devices must be handled differently.
chrome://usb-internals
.chrome://inspect
and ensure that the Discover USB devices option is checked.