Skip to content

Commit af4e682

Browse files
XadillaXtargos
authored andcommitted
test: pass URL's toascii.window.js WPT
PR-URL: #39910 Backport-PR-URL: #40383 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Nitzan Uziely <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]>
1 parent 0a8c331 commit af4e682

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

test/common/wpt.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ class WPTRunner {
301301
this.inProgress = new Set();
302302
this.workers = new Map();
303303
this.unexpectedFailures = [];
304+
305+
this.scriptsModifier = null;
304306
}
305307

306308
/**
@@ -319,6 +321,14 @@ class WPTRunner {
319321
this.initScript = script;
320322
}
321323

324+
/**
325+
* Set the scripts modifier for each script.
326+
* @param {(meta: { code: string, filename: string }) => void}
327+
*/
328+
setScriptModifier(modifier) {
329+
this.scriptsModifier = modifier;
330+
}
331+
322332
get fullInitScript() {
323333
if (this.initScript === null && this.dummyGlobalThisScript === null) {
324334
return null;
@@ -330,7 +340,7 @@ class WPTRunner {
330340
return this.initScript;
331341
}
332342

333-
return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
343+
return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
334344
}
335345

336346
/**
@@ -387,17 +397,21 @@ class WPTRunner {
387397
// Scripts specified with the `// META: script=` header
388398
if (meta.script) {
389399
for (const script of meta.script) {
390-
scriptsToRun.push({
400+
const obj = {
391401
filename: this.resource.toRealFilePath(relativePath, script),
392402
code: this.resource.read(relativePath, script, false)
393-
});
403+
};
404+
this.scriptsModifier?.(obj);
405+
scriptsToRun.push(obj);
394406
}
395407
}
396408
// The actual test
397-
scriptsToRun.push({
409+
const obj = {
398410
code: content,
399411
filename: absolutePath
400-
});
412+
};
413+
this.scriptsModifier?.(obj);
414+
scriptsToRun.push(obj);
401415

402416
const workerPath = path.join(__dirname, 'wpt/worker.js');
403417
const worker = new Worker(workerPath, {

test/wpt/status/url.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"toascii.window.js": {
3-
"requires": ["small-icu"],
4-
"skip": "TODO: port from .window.js"
3+
"requires": ["small-icu"]
54
},
65
"percent-encoding.window.js": {
76
"requires": ["small-icu"],

test/wpt/test-url.js

+8
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,13 @@ runner.setInitScript(`
1515
global.DOMException = DOMException;
1616
`);
1717

18+
runner.setScriptModifier((obj) => {
19+
if (obj.filename.includes('toascii.window.js')) {
20+
// `a` and `area` in `toascii.window.js` is for testing `Element` that
21+
// created via `document.createElement`. So we need to ignore them and just
22+
// test `URL`.
23+
obj.code = obj.code.replace(/\["url", "a", "area"\]/, '[ "url" ]');
24+
}
25+
});
1826
runner.pretendGlobalThisAs('Window');
1927
runner.runJsTests();

0 commit comments

Comments
 (0)