/* globals testAPI */ (function(){ "use strict"; function byteArrayToHex(arrayBuffer){ const chunks = []; (new Uint32Array(arrayBuffer)).forEach(function(num){ chunks.push(num.toString(16)); }); return chunks.map(function(chunk){ return "0".repeat(8 - chunk.length) + chunk; }).join(""); } function formatNumber(number){ const str = number.toString(); return "" + str.substring(0, str.length - 2) + "" + str.substring(str.length - 2); } const svg = document.getElementById("svg"); const output = document.getElementById("test"); function getElements(){ const doc = svg.contentDocument; return Array.from(doc.querySelectorAll(".testRect")); } const tests = []; function addTest(title, callback){ tests.push({title, callback}); } async function performTests(){ const elements = getElements(); const results = await Promise.all(tests.map(async function(test){ return { name: test.title, data: await Promise.all(elements.map(async function(svgElement){ return await test.callback(svgElement); })) }; })); const data = new Float64Array(elements.length * tests.length); results.forEach(function(svgData, i){ svgData.data.forEach(function(testData, j){ if ((typeof testData) === "number"){ data[i * elements.length + j] = testData; } }); }); const hash = await crypto.subtle.digest("SHA-256", data); output.querySelector(".hash").textContent = byteArrayToHex(hash); const dataNode = output.querySelector(".data"); dataNode.innerHTML = "
" + elements.map(function(svgElement){ return " | " + svgElement.dataset.name + " | "; }).join("") + results.map(function(result){ return "|
---|---|---|
" + result.name + " | " + result.data.map(function(value){ if ((typeof value) === "number"){ return "" + formatNumber(value) + " | "; } else { return "-- | "; } }).join("") + "