Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326

This commit is contained in:
Josh Matthews 2017-10-12 09:25:50 -04:00
parent 462c272380
commit 1f531f66ea
5377 changed files with 174916 additions and 84369 deletions

View file

@ -1,9 +0,0 @@
<script>
'use strict';
Promise.resolve().then(() => navigator.usb.getDevices()).then(devices => {
window.parent.postMessage('#OK', '*');
}, error => {
window.parent.postMessage('#' + error.name, '*');
});
</script>

View file

@ -0,0 +1,90 @@
'use strict';
let fakeDeviceInit = {
usbVersionMajor: 2,
usbVersionMinor: 0,
usbVersionSubminor: 0,
deviceClass: 7,
deviceSubclass: 1,
deviceProtocol: 2,
vendorId: 0x18d1,
productId: 0xf00d,
deviceVersionMajor: 1,
deviceVersionMinor: 2,
deviceVersionSubminor: 3,
manufacturerName: 'Google, Inc.',
productName: 'The amazing imaginary printer',
serialNumber: '4',
activeConfigurationValue: 0,
configurations: [{
configurationValue: 1,
configurationName: 'Printer Mode',
interfaces: [{
interfaceNumber: 0,
alternates: [{
alternateSetting: 0,
interfaceClass: 0xff,
interfaceSubclass: 0x01,
interfaceProtocol: 0x01,
interfaceName: 'Control',
endpoints: [{
endpointNumber: 1,
direction: 'in',
type: 'interrupt',
packetSize: 8
}]
}]
}, {
interfaceNumber: 1,
alternates: [{
alternateSetting: 0,
interfaceClass: 0xff,
interfaceSubclass: 0x02,
interfaceProtocol: 0x01,
interfaceName: 'Data',
endpoints: [{
endpointNumber: 2,
direction: 'in',
type: 'bulk',
packetSize: 1024
}, {
endpointNumber: 2,
direction: 'out',
type: 'bulk',
packetSize: 1024
}]
}]
}]
}, {
configurationValue: 2,
configurationName: 'Fighting Robot Mode',
interfaces: [{
interfaceNumber: 0,
alternates: [{
alternateSetting: 0,
interfaceClass: 0xff,
interfaceSubclass: 0x42,
interfaceProtocol: 0x01,
interfaceName: 'Disabled',
endpoints: []
}, {
alternateSetting: 1,
interfaceClass: 0xff,
interfaceSubclass: 0x42,
interfaceProtocol: 0x01,
interfaceName: 'Activate!',
endpoints: [{
endpointNumber: 1,
direction: 'in',
type: 'isochronous',
packetSize: 1024
}, {
endpointNumber: 1,
direction: 'out',
type: 'isochronous',
packetSize: 1024
}]
}]
}]
}]
};

View file

@ -1,14 +0,0 @@
function assert_usb_available_in_iframe(test, origin, expected) {
let frame = document.createElement('iframe');
frame.src = origin + '/webusb/resources/check-availability.html';
window.addEventListener('message', test.step_func(evt => {
if (evt.source == frame.contentWindow) {
assert_equals(evt.data, expected);
document.body.removeChild(frame);
test.done();
}
}));
document.body.appendChild(frame);
}

View file

@ -0,0 +1,16 @@
<!DOCTYPE html>
<script>
'use strict';
window.onmessage = messageEvent => {
if (messageEvent.data === 'Ready') {
navigator.usb.addEventListener('connect', connectEvent => {
connectEvent.device.open().then(() => {
parent.postMessage('Success', '*');
}).catch(error => {
parent.postMessage('FAIL: open rejected ' + error, '*');
});
});
parent.postMessage('Ready', '*');
}
};
</script>

View file

@ -0,0 +1,129 @@
'use strict';
// These tests rely on the User Agent providing an implementation of the
// WebUSB Testing API (https://wicg.github.io/webusb/test/).
//
// In Chromium-based browsers this implementation is provided by a polyfill
// in order to reduce the amount of test-only code shipped to users. To enable
// these tests the browser must be run with these options:
//
// --enable-blink-features=MojoJS,MojoJSTest
let loadChromiumResources = Promise.resolve().then(() => {
if (!MojoInterfaceInterceptor) {
// Do nothing on non-Chromium-based browsers or when the Mojo bindings are
// not present in the global namespace.
return;
}
let chain = Promise.resolve();
[
'/resources/chromium/mojo_bindings.js',
'/resources/chromium/string16.mojom.js',
'/resources/chromium/device.mojom.js',
'/resources/chromium/device_manager.mojom.js',
'/resources/chromium/chooser_service.mojom.js',
'/resources/chromium/webusb-test.js',
].forEach(path => {
let script = document.createElement('script');
script.src = path;
script.async = false;
chain = chain.then(() => new Promise(resolve => {
script.onload = () => resolve();
}));
document.head.appendChild(script);
});
return chain;
});
function usb_test(func, name, properties) {
promise_test(async () => {
if (navigator.usb.test === undefined) {
// Try loading a polyfill for the WebUSB Testing API.
await loadChromiumResources;
}
await navigator.usb.test.initialize();
try {
await func();
} finally {
await navigator.usb.test.reset();
}
}, name, properties);
}
// Returns a promise that is resolved when the next USBConnectionEvent of the
// given type is received.
function connectionEventPromise(eventType) {
return new Promise(resolve => {
let eventHandler = e => {
assert_true(e instanceof USBConnectionEvent);
navigator.usb.removeEventListener(eventType, eventHandler);
resolve(e.device);
};
navigator.usb.addEventListener(eventType, eventHandler);
});
}
// Creates a fake device and returns a promise that resolves once the
// 'connect' event is fired for the fake device. The promise is resolved with
// an object containing the fake USB device and the corresponding USBDevice.
function getFakeDevice() {
let promise = connectionEventPromise('connect');
let fakeDevice = navigator.usb.test.addFakeDevice(fakeDeviceInit);
return promise.then(device => {
return { device: device, fakeDevice: fakeDevice };
});
}
// Disconnects the given device and returns a promise that is resolved when it
// is done.
function waitForDisconnect(fakeDevice) {
let promise = connectionEventPromise('disconnect');
fakeDevice.disconnect();
return promise;
}
function assertRejectsWithError(promise, name, message) {
return promise.then(() => {
assert_unreached('expected promise to reject with ' + name);
}, error => {
assert_equals(error.name, name);
if (message !== undefined)
assert_equals(error.message, message);
});
}
function assertDeviceInfoEquals(usbDevice, deviceInit) {
for (var property in deviceInit) {
if (property == 'activeConfigurationValue') {
if (deviceInit.activeConfigurationValue == 0) {
assert_equals(usbDevice.configuration, null);
} else {
assert_equals(usbDevice.configuration.configurationValue,
deviceInit.activeConfigurationValue);
}
} else if (Array.isArray(deviceInit[property])) {
assert_equals(usbDevice[property].length, deviceInit[property].length);
for (var i = 0; i < usbDevice[property].length; ++i)
assertDeviceInfoEquals(usbDevice[property][i], deviceInit[property][i]);
} else {
assert_equals(usbDevice[property], deviceInit[property], property);
}
}
}
function callWithTrustedClick(callback) {
return new Promise(resolve => {
let button = document.createElement('button');
button.textContent = 'click to continue test';
button.style.display = 'block';
button.style.fontSize = '20px';
button.style.padding = '10px';
button.onclick = () => {
resolve(callback());
document.body.removeChild(button);
};
document.body.appendChild(button);
});
}