Skip to content

Commit

Permalink
Reset interface state when USBDevice.close is called.
Browse files Browse the repository at this point in the history
Closing the device releases all interfaces so this state must be reset.

BUG=665592

Review-Url: https://codereview.chromium.org/2535163003
Cr-Commit-Position: refs/heads/master@{#435406}
  • Loading branch information
reillyeon authored and Commit bot committed Nov 30, 2016
1 parent 3094170 commit 49c564f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
28 changes: 26 additions & 2 deletions third_party/WebKit/LayoutTests/usb/usbDevice.html
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,35 @@
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
.then(() => device.releaseInterface(0))
.then(() => device.close());
.then(() => {
assert_true(device.configuration.interfaces[0].claimed);
return device.releaseInterface(0);
})
.then(() => {
assert_false(device.configuration.interfaces[0].claimed);
return device.close();
});
});
}, 'an interface can be claimed and released');

usb_test(usb => {
usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
return navigator.usb.getDevices().then(devices => {
assert_equals(1, devices.length);
let device = devices[0];
return device.open()
.then(() => device.selectConfiguration(1))
.then(() => device.claimInterface(0))
.then(() => {
assert_true(device.configuration.interfaces[0].claimed);
return device.close(0);
})
.then(() => {
assert_false(device.configuration.interfaces[0].claimed);
});
});
}, 'interfaces are released on close');

usb_test(usb => {
usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]);
return navigator.usb.getDevices().then(devices => {
Expand Down
6 changes: 6 additions & 0 deletions third_party/WebKit/Source/modules/webusb/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ void USBDevice::asyncClose(ScriptPromiseResolver* resolver) {

void USBDevice::onDeviceOpenedOrClosed(bool opened) {
m_opened = opened;
if (!m_opened) {
m_claimedInterfaces.clearAll();
m_selectedAlternates.fill(0);
m_inEndpoints.clearAll();
m_outEndpoints.clearAll();
}
m_deviceStateChangeInProgress = false;
}

Expand Down

0 comments on commit 49c564f

Please sign in to comment.