Update web-platform-tests to revision c0a3e93389bdcc9e8ad12d3988e4568d48b78c9d

This commit is contained in:
WPT Sync Bot 2019-06-29 10:23:13 +00:00
parent 84786add22
commit 686c6b89ed
826 changed files with 8235 additions and 522 deletions

View file

@ -1,3 +1,5 @@
// TODO(domfarolino): Refactor SRIScriptTest to just be a function instead of a
// constructor, since there is no need to produce another object.
var SRIScriptTest = function(pass, name, src, integrityValue, crossoriginValue, nonce) {
this.pass = pass;
this.name = "Script: " + name;
@ -32,6 +34,100 @@ SRIScriptTest.prototype.execute = function() {
document.body.appendChild(e);
};
function buildElementFromDestination(resource_url, destination, attrs) {
// Assert: |destination| is a valid destination.
let element;
// The below switch is responsible for:
// 1. Creating the correct subresource element
// 2. Setting said element's href, src, or fetch-instigating property
// appropriately.
switch (destination) {
case "script":
element = document.createElement(destination);
element.src = resource_url;
break;
case "style":
element = document.createElement('link');
element.rel = 'stylesheet';
element.href = resource_url;
break;
case "image":
element = document.createElement('img');
element.src = resource_url;
break;
default:
assert_unreached("INVALID DESTINATION");
}
// Apply the rest of the attributes, if any.
for (const [attr_name, attr_val] of Object.entries(attrs)) {
element[attr_name] = attr_val;
}
return element;
}
const SRIPreloadTest = (preload_sri_success, subresource_sri_success, name,
destination, resource_url, link_attrs,
subresource_attrs) => {
const test = async_test(name);
const link = document.createElement('link');
// Early-fail in UAs that do not support `preload` links.
test.step_func(() => {
assert_true(link.relList.supports('preload'),
"This test is automatically failing because the browser does not" +
"support `preload` links.");
})();
// Build up the link.
link.rel = 'preload';
link.as = destination;
link.href = resource_url;
for (const [attr_name, attr_val] of Object.entries(link_attrs)) {
link[attr_name] = attr_val; // This may override `rel` to modulepreload.
}
// Preload + subresource success and failure loading functions.
const valid_preload_failed = test.step_func(() =>
{ assert_unreached("Valid preload fired error handler.") });
const invalid_preload_succeeded = test.step_func(() =>
{ assert_unreached("Invalid preload load succeeded.") });
const valid_subresource_failed = test.step_func(() =>
{ assert_unreached("Valid subresource fired error handler.") });
const invalid_subresource_succeeded = test.step_func(() =>
{ assert_unreached("Invalid subresource load succeeded.") });
const subresource_pass = test.step_func(() => { test.done(); });
const preload_pass = test.step_func(() => {
const subresource_element = buildElementFromDestination(
resource_url,
destination,
subresource_attrs
);
if (subresource_sri_success) {
subresource_element.onload = subresource_pass;
subresource_element.onerror = valid_subresource_failed;
} else {
subresource_element.onload = invalid_subresource_succeeded;
subresource_element.onerror = subresource_pass;
}
document.body.append(subresource_element);
});
if (preload_sri_success) {
link.onload = preload_pass;
link.onerror = valid_preload_failed;
} else {
link.onload = invalid_preload_succeeded;
link.onerror = preload_pass;
}
document.head.append(link);
}
// <link> tests
// Style tests must be done synchronously because they rely on the presence
// and absence of global style, which can affect later tests. Thus, instead
@ -63,6 +159,8 @@ SRIStyleTest.prototype.execute = function() {
var div = document.createElement("div");
div.className = "testdiv";
var e = document.createElement("link");
// The link relation is guaranteed to not be "preload" or "modulepreload".
this.attrs.rel = this.attrs.rel || "stylesheet";
for (var key in this.attrs) {
if (this.attrs.hasOwnProperty(key)) {