summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webusb/usbDevice_reset-manual.https.html
blob: 63a0c356ee4efb34dc3367ba8f1605d995a819f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="/resources/testharness.js"></script>
    <script src="/resources/testharnessreport.js"></script>
    <script src="resources/manual.js"></script>
  </head>
  <body>
    <p>
      These tests require a USB device to be connected.
    </p>
    <script>
      const kGetDescriptorRequest = 0x06;
      const kDeviceDescriptorType = 0x01;
      const kDeviceDescriptorLength = 18;

      manual_usb_test(async (t, device) => {
        await device.open();
        t.add_cleanup(async () => {
          await device.close();
        });

        // This test exercises the behavior that the device remains open when it
        // is reset. If the device changes its properties too drastically when
        // reset it may appear to disconnect instead.
        await device.reset();

        // Read the device descriptor in order to validate that communication
        // with the device is still possible after a reset.
        const result = await device.controlTransferIn({
          requestType: 'standard',
          recipient: 'device',
          request: kGetDescriptorRequest,
          value: kDeviceDescriptorType << 8,
          index: 0,
        }, kDeviceDescriptorLength);

        assert_equals(result.status, 'ok', 'transfer status');
        assert_equals(
            result.data.byteLength, kDeviceDescriptorLength, 'transfer length');
      }, 'reset() does not disconnect the device');
    </script>
  </body>
</html>