Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / test / data / api_test / usb / get_user_selected_devices / background.js
blob1b4e54ba20f0b0b83a086528f4496ff2afe2d881
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 = undefined;
7 chrome.test.runWithUserGesture(function() {
8   chrome.usb.getDevices({}, function(devices) {
9     chrome.test.assertEq(0, devices.length);
10     chrome.usb.getUserSelectedDevices({ multiple: false }, function(devices) {
11       chrome.test.assertEq(1, devices.length);
12       device_from_user = devices[0];
13       chrome.usb.openDevice(device_from_user, function(connection) {
14         chrome.usb.closeDevice(connection);
15         chrome.test.sendMessage("opened_device");
16       });
17     });
18   });
19 });
21 chrome.usb.onDeviceRemoved.addListener(function(device) {
22   if (device.device == device_from_user.device) {
23     chrome.test.sendMessage("success");
24   } else {
25     chrome.test.sendMessage("failure");
26   }
27 });