Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Unified Diff: third_party/WebKit/LayoutTests/usb/usbDevice.html

Issue 2816663002: Ensure tests don't depend on fake devices being added synchronously (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/usb/usbDevice.html
diff --git a/third_party/WebKit/LayoutTests/usb/usbDevice.html b/third_party/WebKit/LayoutTests/usb/usbDevice.html
index 5746c7e6781f90710c7eb2105d9cb8dbd0204b60..24270ee38a739717afc137a0e590c440bbecf116 100644
--- a/third_party/WebKit/LayoutTests/usb/usbDevice.html
+++ b/third_party/WebKit/LayoutTests/usb/usbDevice.html
@@ -23,33 +23,40 @@ function assertRejectsWithNotConfiguredError(promise) {
}
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
+ return addPromise.then(device => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(devices[0].open());
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.open());
+ });
});
}, 'open rejects when called on a disconnected device');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let promise = devices[0].open();
+ return addPromise.then(device => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(promise)
- .then(() => runGarbageCollection());
+ return device.open().then(() => {
+ // If the open wins then after the device has been removed it should be
+ // closed.
+ return removePromise.then(() => {
+ assert_false(device.opened);
+ });
+ }, error => {
+ // If the disconnection wins then the open should fail.
+ assert_equals(error.name, 'NotFoundError');
+ });
ortuno 2017/04/12 03:31:07 Seems like a the test that should be split into tw
Reilly Grant (use Gerrit) 2017/04/12 22:47:07 The test API doesn't guarantee a way to inject a d
});
-}, 'open rejects when device disconnected during call');
+}, 'race open against disconnection');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
assert_false(device.opened);
return device.open().then(() => {
assert_true(device.opened);
@@ -57,15 +64,11 @@ usb_test(() => {
assert_false(device.opened);
});
});
- }).then(() => runGarbageCollection());
+ });
}, 'a device can be opened and closed');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.open())
.then(() => device.open())
@@ -78,11 +81,7 @@ usb_test(() => {
}, 'open and close can be called multiple times');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
const message =
'An operation that changes the device state is in progress.';
return Promise.all([
@@ -98,75 +97,68 @@ usb_test(() => {
}, 'open and close cannot be called again while open or close are in progress');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
ortuno 2017/04/12 03:31:08 Why not getConnectedDevice()?
Reilly Grant (use Gerrit) 2017/04/12 22:47:07 I've added getFakeDeviceAndGuid() which handles th
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open().then(() => {
+ let removePromise = connectionEventPromise('disconnect');
ortuno 2017/04/12 03:31:08 Seems like something you could abstract as well.
Reilly Grant (use Gerrit) 2017/04/12 22:47:07 Done.
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.close());
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.close());
+ });
});
});
}, 'close rejects when called on a disconnected device');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
- return device.open()
- .then(() => {
- navigator.usb.test.removeFakeDevice(guid);
+ return addPromise.then(device => {
+ return device.open().then(() => {
+ let removePromise = connectionEventPromise('disconnect');
+ navigator.usb.test.removeFakeDevice(guid);
+ return removePromise.then(() => {
return assertRejectsWithNotFoundError(device.selectConfiguration(1));
});
+ });
});
}, 'selectConfiguration rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
- return Promise.all([
- assertRejectsWithNotOpenError(device.selectConfiguration(1)),
- assertRejectsWithNotOpenError(device.claimInterface(0)),
- assertRejectsWithNotOpenError(device.releaseInterface(0)),
- assertRejectsWithNotOpenError(device.selectAlternateInterface(0, 1)),
- assertRejectsWithNotOpenError(device.controlTransferIn({
- requestType: 'vendor',
- recipient: 'device',
- request: 0x42,
- value: 0x1234,
- index: 0x5678
- }, 7)),
- assertRejectsWithNotOpenError(device.controlTransferOut({
- requestType: 'vendor',
- recipient: 'device',
- request: 0x42,
- value: 0x1234,
- index: 0x5678
- }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))),
- assertRejectsWithNotOpenError(device.clearHalt('in', 1)),
- assertRejectsWithNotOpenError(device.transferIn(1, 8)),
- assertRejectsWithNotOpenError(
- device.transferOut(1, new ArrayBuffer(8))),
- assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])),
- assertRejectsWithNotOpenError(
- device.isochronousTransferOut(1, new ArrayBuffer(8), [8])),
- assertRejectsWithNotOpenError(device.reset())
- ]);
- });
+ return getConnectedDevice(fakeDeviceInit).then(device => Promise.all([
+ assertRejectsWithNotOpenError(device.selectConfiguration(1)),
+ assertRejectsWithNotOpenError(device.claimInterface(0)),
+ assertRejectsWithNotOpenError(device.releaseInterface(0)),
+ assertRejectsWithNotOpenError(device.selectAlternateInterface(0, 1)),
+ assertRejectsWithNotOpenError(device.controlTransferIn({
+ requestType: 'vendor',
+ recipient: 'device',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5678
+ }, 7)),
+ assertRejectsWithNotOpenError(device.controlTransferOut({
+ requestType: 'vendor',
+ recipient: 'device',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5678
+ }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]))),
+ assertRejectsWithNotOpenError(device.clearHalt('in', 1)),
+ assertRejectsWithNotOpenError(device.transferIn(1, 8)),
+ assertRejectsWithNotOpenError(
+ device.transferOut(1, new ArrayBuffer(8))),
+ assertRejectsWithNotOpenError(device.isochronousTransferIn(1, [8])),
+ assertRejectsWithNotOpenError(
+ device.isochronousTransferOut(1, new ArrayBuffer(8), [8])),
+ assertRejectsWithNotOpenError(device.reset())
+ ]));
}, 'methods requiring it reject when the device is not open');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
assert_equals(device.configuration, null);
return device.open()
.then(() => {
@@ -182,11 +174,7 @@ usb_test(() => {
}, 'device configuration can be set and queried');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
assert_equals(device.configuration, null);
return device.open()
.then(() => assertRejectsWithError(
@@ -197,11 +185,7 @@ usb_test(() => {
}, 'selectConfiguration rejects on invalid configurations');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
assert_equals(device.configuration, null);
return device.open().then(() => Promise.all([
assertRejectsWithNotConfiguredError(device.claimInterface(0)),
@@ -234,11 +218,7 @@ usb_test(() => {
}, 'methods requiring it reject when the device is unconfigured');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
@@ -254,11 +234,7 @@ usb_test(() => {
}, 'an interface can be claimed and released');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
@@ -273,11 +249,7 @@ usb_test(() => {
}, 'interfaces are released on close');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
const message = 'The interface number provided is not supported by the ' +
'device in its current configuration.';
return device.open()
@@ -293,42 +265,42 @@ usb_test(() => {
}, 'a non-existent interface cannot be claimed or released');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- var device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.claimInterface(0));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.claimInterface(0));
+ });
});
});
}, 'claimInterface rejects when called on a disconnected device');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- var device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.releaseInterface(0));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.releaseInterface(0));
+ });
});
});
}, 'releaseInterface rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
@@ -338,11 +310,7 @@ usb_test(() => {
}, 'can select an alternate interface');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
@@ -355,27 +323,25 @@ usb_test(() => {
}, 'cannot select a non-existent alternate interface');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- var device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.selectAlternateInterface(0, 1));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.selectAlternateInterface(0, 1));
+ });
});
});
}, 'selectAlternateInterface rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.controlTransferIn({
@@ -399,32 +365,30 @@ usb_test(() => {
}, 'can issue IN control transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.controlTransferIn({
- requestType: 'vendor',
- recipient: 'device',
- request: 0x42,
- value: 0x1234,
- index: 0x5678
- }, 7));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.controlTransferIn({
+ requestType: 'vendor',
+ recipient: 'device',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5678
+ }, 7));
+ });
});
});
}, 'controlTransferIn rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.controlTransferOut({
@@ -444,32 +408,30 @@ usb_test(() => {
}, 'can issue OUT control transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.controlTransferOut({
- requestType: 'vendor',
- recipient: 'device',
- request: 0x42,
- value: 0x1234,
- index: 0x5678
- }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.controlTransferOut({
+ requestType: 'vendor',
+ recipient: 'device',
+ request: 0x42,
+ value: 0x1234,
+ index: 0x5678
+ }, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])));
+ });
});
});
}, 'controlTransferOut rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
let interfaceRequest = {
requestType: 'vendor',
recipient: 'interface',
@@ -529,11 +491,7 @@ usb_test(() => {
}, 'requests to interfaces and endpoint require an interface claim');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
@@ -543,27 +501,25 @@ usb_test(() => {
}, 'can clear a halt condition');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.clearHalt('in', 1));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.clearHalt('in', 1));
+ });
});
});
}, 'clearHalt rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
let data = new DataView(new ArrayBuffer(1024));
for (let i = 0; i < 1024; ++i)
data.setUint8(i, i & 0xff);
@@ -591,11 +547,7 @@ usb_test(() => {
}, 'transfers to unavailable endpoints are rejected');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
@@ -612,11 +564,7 @@ usb_test(() => {
}, 'can issue IN interrupt transfer');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(1))
@@ -634,27 +582,25 @@ usb_test(() => {
}, 'can issue IN bulk transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(1))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.transferIn(2, 1024));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.transferIn(2, 1024));
+ });
});
});
}, 'transferIn rejects if called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(1))
@@ -674,11 +620,10 @@ usb_test(() => {
}, 'can issue OUT bulk transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(1))
@@ -686,18 +631,17 @@ usb_test(() => {
let data = new DataView(new ArrayBuffer(1024));
for (let i = 0; i < 1024; ++i)
data.setUint8(i, i & 0xff);
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.transferOut(2, data));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.transferOut(2, data));
+ });
});
});
}, 'transferOut rejects if called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
@@ -727,29 +671,27 @@ usb_test(() => {
}, 'can issue IN isochronous transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
.then(() => device.selectAlternateInterface(0, 1))
.then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.isochronousTransferIn(
- 1, [64, 64, 64, 64, 64, 64, 64, 64]));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.isochronousTransferIn(
+ 1, [64, 64, 64, 64, 64, 64, 64, 64]));
+ });
});
});
}, 'isochronousTransferIn rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
@@ -779,11 +721,10 @@ usb_test(() => {
}, 'can issue OUT isochronous transfer');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(devices.length, 1);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open()
.then(() => device.selectConfiguration(2))
.then(() => device.claimInterface(0))
@@ -794,32 +735,33 @@ usb_test(() => {
for (let j = 0; j < 64; ++j)
data.setUint8(i * j, j & 0xff);
}
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.isochronousTransferOut(
- 1, data, [64, 64, 64, 64, 64, 64, 64, 64]));
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.isochronousTransferOut(
+ 1, data, [64, 64, 64, 64, 64, 64, 64, 64]));
+ });
});
});
}, 'isochronousTransferOut rejects when called on a disconnected device');
usb_test(() => {
- navigator.usb.test.addFakeDevice(fakeDeviceInit);
-
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return getConnectedDevice(fakeDeviceInit).then(device => {
return device.open().then(() => device.reset()).then(() => device.close());
});
}, 'can reset the device');
usb_test(() => {
+ let addPromise = connectionEventPromise('connect');
let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit);
- return navigator.usb.getDevices().then(devices => {
- assert_equals(1, devices.length);
- let device = devices[0];
+ return addPromise.then(device => {
return device.open().then(() => {
+ let removePromise = connectionEventPromise('disconnect');
navigator.usb.test.removeFakeDevice(guid);
- return assertRejectsWithNotFoundError(device.reset());
+ return removePromise.then(() => {
+ return assertRejectsWithNotFoundError(device.reset());
+ });
});
});
}, 'resetDevice rejects when called on a disconnected device');

Powered by Google App Engine
This is Rietveld 408576698