https://github.com/web-platform-tests/wpt
Revision f941f71d5aae723c2204aa8c1024280b9ecab055 authored by Sam Goto on 18 December 2018, 20:56:38 UTC, committed by Philip Jägenstedt on 19 December 2018, 15:35:45 UTC
https://github.com/inexorabletash/idle-detection

Just a webification of the chrome.idle.* APIs.

Does not yet include:

- permission checks
- android integration
- final API

Bug: 878979
Change-Id: Ie45b34d5c29e04dfe65f8ff5127c6be34850d68f
1 parent 712c9f2
Raw File
Tip revision: f941f71d5aae723c2204aa8c1024280b9ecab055 authored by Sam Goto on 18 December 2018, 20:56:38 UTC
Idle Detection API: Prototype
Tip revision: f941f71
usbInterface.https.any.js
// META: script=/webusb/resources/fake-devices.js
// META: script=/webusb/resources/usb-helpers.js
'use strict';

usb_test(async () => {
  let { device } =  await getFakeDevice();
  let configuration = new USBConfiguration(
      device, device.configurations[1].configurationValue);
  let usbInterface = new USBInterface(
      configuration, configuration.interfaces[0].interfaceNumber);
  assertDeviceInfoEquals(
      usbInterface, fakeDeviceInit.configurations[1].interfaces[0]);
}, 'Can construct a USBInterface.');

usb_test(async () => {
  let { device } =  await getFakeDevice();
  let configuration = new USBConfiguration(
      device, device.configurations[1].configurationValue);
  try {
    let usbInterface = new USBInterface(
        configuration, configuration.interfaces.length);
    assert_unreached('USBInterface should reject an invalid interface number');
  } catch (error) {
    assert_equals(error.name, 'RangeError');
  }
}, 'Constructing a USBInterface with an invalid interface number ' +
    'throws a range error.');

usb_test(async () => {
  let { device } =  await getFakeDevice();
  await device.open();
  await device.selectConfiguration(2);
  let configuration = new USBConfiguration(
      device, device.configurations[1].configurationValue);
  let usbInterface = new USBInterface(
      configuration, configuration.interfaces[0].interfaceNumber);
  assert_equals(usbInterface.alternate, null);
}, 'The alternate attribute of USBInterface returns null if the interface' +
    'has not been claimed.');

usb_test(async () => {
  let { device } =  await getFakeDevice();
  await device.open();
  await device.selectConfiguration(2);
  await device.claimInterface(0);
  await device.selectAlternateInterface(0, 1);
  let configuration = new USBConfiguration(
      device, device.configurations[1].configurationValue);
  let usbInterface = new USBInterface(
      configuration, configuration.interfaces[0].interfaceNumber);
  assert_equals(usbInterface.alternate.alternateSetting, 1);
}, 'The alternate attribute of USBInterface returns the active alternate ' +
    'interface.');
back to top