1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 chrome.test.runWithUserGesture(function() {
8 chrome.hid.getDevices({}, function(devices) {
9 chrome.test.assertNoLastError();
10 chrome.test.assertEq(0, devices.length);
11 chrome.hid.getUserSelectedDevices({ multiple: false }, function(devices) {
12 chrome.test.assertNoLastError();
13 chrome.test.assertEq(1, devices.length);
14 device_from_user = devices[0];
15 chrome.hid.connect(device_from_user.deviceId, function(connection) {
16 chrome.test.assertNoLastError();
17 chrome.hid.disconnect(connection.connectionId);
18 chrome.test.sendMessage("opened_device");
24 chrome.hid.onDeviceRemoved.addListener(function(deviceId) {
25 chrome.test.assertEq(device_from_user.deviceId, deviceId);
26 chrome.test.sendMessage("removed");
29 chrome.hid.onDeviceAdded.addListener(function(device) {
30 chrome.test.assertTrue(device_from_user.deviceId != device.deviceId);
31 chrome.test.assertEq(device_from_user.vendorId, device.vendorId);
32 chrome.test.assertEq(device_from_user.productId, device.productId);
33 chrome.test.sendMessage("added");