OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var usb = chrome.usb; | 5 var usb = chrome.usb; |
6 | 6 |
7 var tests = [ | 7 function getDevices() { |
8 function explicitCloseDevice() { | 8 usb.getDevices({ |
9 usb.findDevices({vendorId: 0, productId: 0}, function(devices) { | 9 vendorId: 0, |
10 usb.closeDevice(devices[0]); | 10 productId: 0 |
| 11 }, function(devices) { |
| 12 usb.openDevice({ |
| 13 device: devices[0].device |
| 14 }, function(handle) { |
| 15 usb.closeDevice({ |
| 16 handle: handle.handle |
| 17 }); |
11 chrome.test.succeed(); | 18 chrome.test.succeed(); |
12 }); | 19 }); |
13 }, | 20 }); |
14 function resetDevice() { | 21 } |
15 usb.findDevices({vendorId: 0, productId: 0}, function(devices) { | |
16 usb.resetDevice(devices[0], function(result) { | |
17 chrome.test.assertEq(result, true); | |
18 // Ensure the device is still open. | |
19 var transfer = { | |
20 direction: "out", | |
21 endpoint: 2, | |
22 data: new ArrayBuffer(1) | |
23 }; | |
24 usb.interruptTransfer(devices[0], transfer, function(result) { | |
25 // This is designed to fail. | |
26 usb.resetDevice(devices[0], function(result) { | |
27 chrome.test.assertEq(result, false); | |
28 usb.interruptTransfer(devices[0], transfer, function(result) { | |
29 chrome.test.assertEq(result, undefined); | |
30 chrome.test.assertEq( | |
31 chrome.runtime.lastError && chrome.runtime.lastError.message, | |
32 'No such device.' | |
33 ); | |
34 chrome.test.succeed(); | |
35 }); | |
36 }); | |
37 }); | |
38 }); | |
39 }); | |
40 }, | |
41 ]; | |
42 | 22 |
43 chrome.test.runTests(tests); | 23 function explicitCloseDevice() { |
| 24 usb.findDevices({ |
| 25 vendorId: 0, |
| 26 productId: 0 |
| 27 }, function(devices) { |
| 28 usb.closeDevice(devices[0]); |
| 29 chrome.test.succeed(); |
| 30 }); |
| 31 } |
| 32 |
| 33 chrome.test.runTests([getDevices, explicitCloseDevice]); |
OLD | NEW |