| 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 var tests = [ |
| 8 function explicitCloseDevice() { | 8 function explicitCloseDevice() { |
| 9 usb.findDevices({vendorId: 0, productId: 0}, function(devices) { | 9 usb.getDevices({vendorId: 0, productId: 0}, function(devices) { |
| 10 usb.closeDevice(devices[0]); | 10 usb.openDevice(devices[0], function(device) { |
| 11 chrome.test.succeed(); | 11 usb.closeDevice(device, function() { |
| 12 chrome.test.assertEq(undefined, chrome.runtime.lastError); |
| 13 chrome.test.succeed(); |
| 14 }); |
| 15 }); |
| 12 }); | 16 }); |
| 13 }, | 17 }, |
| 14 function resetDevice() { | 18 function resetDevice() { |
| 15 usb.findDevices({vendorId: 0, productId: 0}, function(devices) { | 19 usb.getDevices({vendorId: 0, productId: 0}, function(devices) { |
| 16 usb.resetDevice(devices[0], function(result) { | 20 usb.openDevice(devices[0], function(device) { |
| 17 chrome.test.assertEq(result, true); | 21 usb.resetDevice(device, function(result) { |
| 18 // Ensure the device is still open. | 22 chrome.test.assertEq(result, true); |
| 19 var transfer = { | 23 // Ensure the device is still open. |
| 20 direction: "out", | 24 var transfer = {direction: "out", endpoint: 2, |
| 21 endpoint: 2, | 25 data: new ArrayBuffer(1)}; |
| 22 data: new ArrayBuffer(1) | 26 usb.interruptTransfer(device, transfer, function(result) { |
| 23 }; | 27 // This is designed to fail. |
| 24 usb.interruptTransfer(devices[0], transfer, function(result) { | 28 usb.resetDevice(device, function(result) { |
| 25 // This is designed to fail. | 29 chrome.test.assertEq(result, false); |
| 26 usb.resetDevice(devices[0], function(result) { | 30 usb.interruptTransfer(device, transfer, function(result) { |
| 27 chrome.test.assertEq(result, false); | 31 chrome.test.assertEq(result, undefined); |
| 28 usb.interruptTransfer(devices[0], transfer, function(result) { | 32 chrome.test.assertEq( |
| 29 chrome.test.assertEq(result, undefined); | 33 chrome.runtime.lastError && |
| 30 chrome.test.assertEq( | 34 chrome.runtime.lastError.message, |
| 31 chrome.runtime.lastError && chrome.runtime.lastError.message, | 35 'No such device.'); |
| 32 'No such device.' | 36 chrome.test.succeed(); |
| 33 ); | 37 }); |
| 34 chrome.test.succeed(); | |
| 35 }); | 38 }); |
| 36 }); | 39 }); |
| 37 }); | 40 }); |
| 38 }); | 41 }); |
| 39 }); | 42 }); |
| 40 }, | 43 }, |
| 41 ]; | 44 ]; |
| 42 | 45 |
| 43 chrome.test.runTests(tests); | 46 chrome.test.runTests(tests); |
| OLD | NEW |