1 // Copyright (c) 2013 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 var genericTransfer = {
12 var controlTransfer = {
15 "requestType": "standard",
16 "recipient": "device",
23 "transferInfo": genericTransfer,
26 var errorTransferLength = 'Transfer length must be a ' +
27 'positive number less than 104,857,600.';
28 var errorNumPackets = 'Number of packets must be a ' +
29 'positive number less than 4,194,304.';
30 var errorPacketLength = 'Packet length must be a ' +
31 'positive number less than 65,536.';
32 var errorInsufficientTransferLength = 'Transfer length is insufficient.';
33 var largeSize = 100 * 1024 * 1024 + 1;
34 var maxPackets = 4 * 1024 * 1024;
35 var maxPacketLength = 64 * 1024;
37 function createInvalidTransferTest(usbFunction, transferInfo, transferLength) {
39 genericTransfer["length"] = transferLength;
40 controlTransfer["length"] = transferLength;
41 usb.findDevices({vendorId: 0, productId: 0}, function(devices) {
42 var device = devices[0];
43 usbFunction(device, transferInfo, chrome.test.callbackFail(
44 errorTransferLength, function() {}));
49 function createInvalidPacketLengthTest(
50 transferLength, packets, packetLength, errorMessage) {
52 genericTransfer["length"] = transferLength;
53 isoTransfer["packets"] = packets;
54 isoTransfer["packetLength"] = packetLength;
55 usb.findDevices({vendorId: 0, productId: 0}, function(devices) {
56 var device = devices[0];
57 usb.isochronousTransfer(device, isoTransfer,
58 chrome.test.callbackFail(
59 errorMessage, function() {}));
65 createInvalidTransferTest(usb.bulkTransfer, genericTransfer, -1),
66 createInvalidTransferTest(usb.controlTransfer, controlTransfer, -1),
67 createInvalidTransferTest(usb.interruptTransfer, genericTransfer, -1),
68 createInvalidTransferTest(usb.isochronousTransfer, isoTransfer, -1),
69 createInvalidTransferTest(usb.bulkTransfer, genericTransfer, largeSize),
70 createInvalidTransferTest(usb.controlTransfer, controlTransfer, largeSize),
71 createInvalidTransferTest(usb.interruptTransfer, genericTransfer, largeSize),
72 createInvalidTransferTest(usb.isochronousTransfer, isoTransfer, largeSize),
74 createInvalidPacketLengthTest(1024, -1, 0, errorNumPackets),
75 createInvalidPacketLengthTest(maxPackets, maxPackets, 0, errorNumPackets),
76 createInvalidPacketLengthTest(1024, 100, -1, errorPacketLength),
77 createInvalidPacketLengthTest(1024, 100, maxPacketLength, errorPacketLength),
78 createInvalidPacketLengthTest(1024, 1025, 0, errorInsufficientTransferLength)
81 chrome.test.runTests(tests);