Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / extensions / test / data / api_test / hid / get_user_selected_devices / background.js
blobc0a03b00d1f23b9839c7f289a5151dd2a24483d5
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.
5 var device_from_user;
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");
19 });
20 });
21 });
22 });
24 chrome.hid.onDeviceRemoved.addListener(function(deviceId) {
25 chrome.test.assertEq(device_from_user.deviceId, deviceId);
26 chrome.test.sendMessage("removed");
27 });
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");
34 });