MCPcopy Create free account
hub / github.com/nodejs/node / runTests

Function runTests

test/fixtures/wpt/url/percent-encoding.window.js:3–23  ·  view source on GitHub ↗
(testUnits)

Source from the content-addressed store, hash-verified

1promise_test(() => fetch("resources/percent-encoding.json").then(res => res.json()).then(runTests), "Loading data…");
2
3function runTests(testUnits) {
4 for (const testUnit of testUnits) {
5 // Ignore comments
6 if (typeof testUnit === "string") {
7 continue;
8 }
9 for (const encoding of Object.keys(testUnit.output)) {
10 async_test(t => {
11 const frame = document.body.appendChild(document.createElement("iframe"));
12 t.add_cleanup(() => frame.remove());
13 frame.onload = t.step_func_done(() => {
14 const output = frame.contentDocument.querySelector("a");
15 // Test that the fragment is always UTF-8 encoded
16 assert_equals(output.hash, `#${testUnit.output["utf-8"]}`, "fragment");
17 assert_equals(output.search, `?${testUnit.output[encoding]}`, "query");
18 });
19 frame.src = `resources/percent-encoding.py?encoding=${encoding}&value=${toBase64(testUnit.input)}`;
20 }, `Input ${testUnit.input} with encoding ${encoding}`);
21 }
22 }
23}
24
25// Use base64 to avoid relying on the URL parser to get UTF-8 percent-encoding correctly. This does
26// not use btoa directly as that only works with code points in the range U+0000 to U+00FF,

Callers

nothing calls this directly

Calls 6

toBase64Function · 0.85
createElementMethod · 0.80
keysMethod · 0.65
async_testFunction · 0.50
assert_equalsFunction · 0.50
removeMethod · 0.45

Tested by

no test coverage detected