summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resources/testharness.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/resources/testharness.js')
-rw-r--r--testing/web-platform/tests/resources/testharness.js133
1 files changed, 53 insertions, 80 deletions
diff --git a/testing/web-platform/tests/resources/testharness.js b/testing/web-platform/tests/resources/testharness.js
index 1a6a4bb341..c5c375e172 100644
--- a/testing/web-platform/tests/resources/testharness.js
+++ b/testing/web-platform/tests/resources/testharness.js
@@ -4194,11 +4194,7 @@
status
],
],
- ["button",
- {"onclick": "let evt = new Event('__test_restart'); " +
- "let canceled = !window.dispatchEvent(evt);" +
- "if (!canceled) { location.reload() }"},
- "Rerun"]
+ ["button", {"id":"rerun"}, "Rerun"]
]];
if (harness_status.status === harness_status.ERROR) {
@@ -4230,6 +4226,13 @@
log.appendChild(render(summary_template, {num_tests:tests.length}, output_document));
+ output_document.getElementById("rerun").addEventListener("click",
+ function() {
+ let evt = new Event('__test_restart');
+ let canceled = !window.dispatchEvent(evt);
+ if (!canceled) { location.reload(); }
+ });
+
forEach(output_document.querySelectorAll("section#summary label"),
function(element)
{
@@ -4254,18 +4257,6 @@
});
});
- // This use of innerHTML plus manual escaping is not recommended in
- // general, but is necessary here for performance. Using textContent
- // on each individual <td> adds tens of seconds of execution time for
- // large test suites (tens of thousands of tests).
- function escape_html(s)
- {
- return s.replace(/\&/g, "&amp;")
- .replace(/</g, "&lt;")
- .replace(/"/g, "&quot;")
- .replace(/'/g, "&#39;");
- }
-
function has_assertions()
{
for (var i = 0; i < tests.length; i++) {
@@ -4296,81 +4287,63 @@
});
function get_asserts_output(test) {
+ const asserts_output = render(
+ ["details", {},
+ ["summary", {}, "Asserts run"],
+ ["table", {}, ""] ]);
+
var asserts = asserts_run_by_test.get(test);
if (!asserts) {
- return "No asserts ran";
+ asserts_output.querySelector("summary").insertAdjacentText("afterend", "No asserts ran");
+ return asserts_output;
}
- rv = "<table>";
- rv += asserts.map(assert => {
- var output_fn = "<strong>" + escape_html(assert.assert_name) + "</strong>(";
- var prefix_len = output_fn.length;
- var output_args = assert.args;
- var output_len = output_args.reduce((prev, current) => prev+current, prefix_len);
- if (output_len[output_len.length - 1] > 50) {
- output_args = output_args.map((x, i) =>
- (i > 0 ? " ".repeat(prefix_len) : "" )+ x + (i < output_args.length - 1 ? ",\n" : ""));
- } else {
- output_args = output_args.map((x, i) => x + (i < output_args.length - 1 ? ", " : ""));
- }
- output_fn += escape_html(output_args.join(""));
- output_fn += ')';
- var output_location;
+
+ const table = asserts_output.querySelector("table");
+ for (const assert of asserts) {
+ const status_class_name = status_class(Test.prototype.status_formats[assert.status]);
+ var output_fn = "(" + assert.args.join(", ") + ")";
if (assert.stack) {
- output_location = assert.stack.split("\n", 1)[0].replace(/@?\w+:\/\/[^ "\/]+(?::\d+)?/g, " ");
+ output_fn += "\n";
+ output_fn += assert.stack.split("\n", 1)[0].replace(/@?\w+:\/\/[^ "\/]+(?::\d+)?/g, " ");
}
- return "<tr class='overall-" +
- status_class(Test.prototype.status_formats[assert.status]) + "'>" +
- "<td class='" +
- status_class(Test.prototype.status_formats[assert.status]) + "'>" +
- Test.prototype.status_formats[assert.status] + "</td>" +
- "<td><pre>" +
- output_fn +
- (output_location ? "\n" + escape_html(output_location) : "") +
- "</pre></td></tr>";
+ table.appendChild(render(
+ ["tr", {"class":"overall-" + status_class_name},
+ ["td", {"class":status_class_name}, Test.prototype.status_formats[assert.status]],
+ ["td", {}, ["pre", {}, ["strong", {}, assert.assert_name], output_fn]] ]));
}
- ).join("\n");
- rv += "</table>";
- return rv;
+ return asserts_output;
}
- log.appendChild(document.createElementNS(xhtml_ns, "section"));
var assertions = has_assertions();
- var html = "<h2>Details</h2><table id='results' " + (assertions ? "class='assertions'" : "" ) + ">" +
- "<thead><tr><th>Result</th><th>Test Name</th>" +
- (assertions ? "<th>Assertion</th>" : "") +
- "<th>Message</th></tr></thead>" +
- "<tbody>";
- for (var i = 0; i < tests.length; i++) {
- var test = tests[i];
- html += '<tr class="overall-' +
- status_class(test.format_status()) +
- '">' +
- '<td class="' +
- status_class(test.format_status()) +
- '">' +
- test.format_status() +
- "</td><td>" +
- escape_html(test.name) +
- "</td><td>" +
- (assertions ? escape_html(get_assertion(test)) + "</td><td>" : "") +
- escape_html(test.message ? tests[i].message : " ") +
- (tests[i].stack ? "<pre>" +
- escape_html(tests[i].stack) +
- "</pre>": "");
+ const section = render(
+ ["section", {},
+ ["h2", {}, "Details"],
+ ["table", {"id":"results", "class":(assertions ? "assertions" : "")},
+ ["thead", {},
+ ["tr", {},
+ ["th", {}, "Result"],
+ ["th", {}, "Test Name"],
+ (assertions ? ["th", {}, "Assertion"] : ""),
+ ["th", {}, "Message" ]]],
+ ["tbody", {}]]]);
+
+ const tbody = section.querySelector("tbody");
+ for (const test of tests) {
+ const status = test.format_status();
+ const status_class_name = status_class(status);
+ tbody.appendChild(render(
+ ["tr", {"class":"overall-" + status_class_name},
+ ["td", {"class":status_class_name}, status],
+ ["td", {}, test.name],
+ (assertions ? ["td", {}, get_assertion(test)] : ""),
+ ["td", {},
+ test.message ?? "",
+ ["pre", {}, test.stack ?? ""]]]));
if (!(test instanceof RemoteTest)) {
- html += "<details><summary>Asserts run</summary>" + get_asserts_output(test) + "</details>"
+ tbody.lastChild.lastChild.appendChild(get_asserts_output(test));
}
- html += "</td></tr>";
- }
- html += "</tbody></table>";
- try {
- log.lastChild.innerHTML = html;
- } catch (e) {
- log.appendChild(document.createElementNS(xhtml_ns, "p"))
- .textContent = "Setting innerHTML for the log threw an exception.";
- log.appendChild(document.createElementNS(xhtml_ns, "pre"))
- .textContent = html;
}
+ log.appendChild(section);
};
/*