Revision 8ba8d81fc0a97e9f5332a23d532ee9b40cf3104b authored by moz-wptsync-bot on 11 January 2018, 16:11:49 UTC, committed by moz-wptsync-bot on 11 January 2018, 16:11:49 UTC
bugzilla-url: https://bugzilla-dev.allizom.org/show_bug.cgi?id=1420672 gecko-commit: 976d54360e53438f9f7029b636b4585ee974f891 gecko-integration-branch: central gecko-reviewers: bkelly
1 parent b5b0297
usb.https.html
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script src="resources/fake-devices.js"></script>
<script src="resources/usb-helpers.js"></script>
<script>
'use strict';
usb_test(() => {
return getFakeDevice().then(({ device }) => {
return navigator.usb.getDevices().then(devices => {
assert_equals(devices.length, 1);
assert_equals(device, devices[0]);
assertDeviceInfoEquals(devices[0], fakeDeviceInit);
});
});
}, 'getDevices returns devices that are connected');
usb_test(() => {
return getFakeDevice().then(() => {
return navigator.usb.getDevices().then(devicesFirstTime => {
assert_equals(devicesFirstTime.length, 1);
return navigator.usb.getDevices().then(devicesSecondTime => {
assert_array_equals(devicesSecondTime, devicesFirstTime);
});
});
});
}, 'getDevices returns the same objects for each USB device');
usb_test(() => {
return navigator.usb.requestDevice({ filters: [] })
.then(device => {
assert_unreachable('requestDevice should reject without a user gesture');
})
.catch(error => {
assert_equals(error.code, DOMException.SECURITY_ERR);
});
}, 'requestDevice rejects when called without a user gesture');
usb_test(() => {
return callWithTrustedClick(() => navigator.usb.requestDevice({ filters: [] })
.then(device => {
assert_unreachable('requestDevice should reject when no device selected');
})
.catch(error => {
assert_equals(error.code, DOMException.NOT_FOUND_ERR);
})
);
}, 'requestDevice rejects when no device is chosen');
usb_test(() => {
return getFakeDevice().then(({ device, fakeDevice }) => {
navigator.usb.test.onrequestdevice = event => {
navigator.usb.test.onrequestdevice = undefined;
event.respondWith(fakeDevice);
}
return callWithTrustedClick(() => {
return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => {
assert_equals(chosenDevice, device);
});
});
});
}, 'requestDevice returns the device chosen by the user');
usb_test(() => {
return getFakeDevice().then(({ device, fakeDevice }) => {
navigator.usb.test.onrequestdevice = event => {
navigator.usb.test.onrequestdevice = undefined;
event.respondWith(fakeDevice);
}
return callWithTrustedClick(() => {
return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => {
assert_equals(chosenDevice, device);
return navigator.usb.getDevices().then(devices => {
assert_equals(devices.length, 1);
assert_equals(devices[0], chosenDevice);
});
});
});
});
}, 'getDevices returns the same object as requestDevice');
usb_test(() => {
const expectedFilters = [
{ vendorId: 1234, classCode: 0xFF, serialNumber: "123ABC" },
{ vendorId: 5678, productId: 0xF00F }
];
navigator.usb.test.onrequestdevice = event => {
navigator.usb.test.onrequestdevice = undefined;
assert_equals(event.filters.length, expectedFilters.length);
for (var i = 0; i < event.filters.length; ++i) {
assert_object_equals(event.filters[i], expectedFilters[i]);
}
event.respondWith(null);
}
return callWithTrustedClick(() => {
return navigator.usb.requestDevice({ filters: expectedFilters })
.then(device => {
assert_unreachable('requestDevice should reject because no device selected');
})
.catch(error => {
assert_equals(error.code, DOMException.NOT_FOUND_ERR);
});
});
}, 'filters are sent correctly');
usb_test(() => {
return getFakeDevice().then(({ device }) => {
assertDeviceInfoEquals(device, fakeDeviceInit);
return device.open().then(() => device.close());
});
}, 'onconnect event is trigged by adding a device');
usb_test(usb => {
return getFakeDevice().then(({ device, fakeDevice }) => {
return waitForDisconnect(fakeDevice).then(removedDevice => {
assertDeviceInfoEquals(removedDevice, fakeDeviceInit);
assert_equals(removedDevice, device);
return removedDevice.open().then(() => {
assert_unreachable('should not be able to open a disconnected device');
}, error => {
assert_equals(error.code, DOMException.NOT_FOUND_ERR);
});
});
});
}, 'ondisconnect event is triggered by removing a device');
</script>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...