// `integrityValue` indicates the 'integrity' attribute value at the time of // #prepare-a-script. // // `integrityValueAfterPrepare` indicates how the 'integrity' attribute value // is modified after #prepare-a-script: // - `undefined` => not modified. // - `null` => 'integrity' attribute is removed. // - others => 'integrity' attribute value is set to that value. // // TODO: Make the arguments a dictionary for readability in the test files. var SRIScriptTest = function(pass, name, src, integrityValue, crossoriginValue, nonce, integrityValueAfterPrepare) { this.pass = pass; this.name = "Script: " + name; this.src = src; this.integrityValue = integrityValue; this.crossoriginValue = crossoriginValue; this.nonce = nonce; this.integrityValueAfterPrepare = integrityValueAfterPrepare;
}
function set_extra_attributes(element, attrs) { // Apply the rest of the attributes, if any. for (const [attr_name, attr_val] of Object.entries(attrs)) {
element[attr_name] = attr_val;
}
}
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);
set_extra_attributes(element, attrs);
element.src = resource_url; break; case"style":
element = document.createElement('link');
set_extra_attributes(element, attrs);
element.rel = 'stylesheet';
element.href = resource_url; break; case"image":
element = document.createElement('img');
set_extra_attributes(element, attrs);
element.src = resource_url; break; default:
assert_unreached("INVALID DESTINATION");
}
return element;
}
// When using SRIPreloadTest, also include /preload/resources/preload_helper.js // |number_of_requests| is used to ensure that preload requests are actually // reused as expected. const SRIPreloadTest = (preload_sri_success, subresource_sri_success, name,
number_of_requests, 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.
}
// <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 // of executing them one at a time, the style tests are implemented as a // queue that builds up a list of tests, and then executes them one at a // time. var SRIStyleTest = function(queue, pass, name, attrs, customCallback, altPassValue) { this.pass = pass; this.name = "Style: " + name; this.customCallback = customCallback || function () {}; this.attrs = attrs || {}; this.passValue = altPassValue || "rgb(255, 255, 0)";
this.test = async_test(this.name);
this.queue = queue; this.queue.push(this);
}
SRIStyleTest.prototype.execute = function() { var that = this; var container = document.getElementById("container"); while (container.hasChildNodes()) {
container.removeChild(container.firstChild);
}
var test = this.test;
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)) {
e.setAttribute(key, this.attrs[key]);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.