Skip to content

Commit

Permalink
test: pass URL's toascii.window.js WPT
Browse files Browse the repository at this point in the history
PR-URL: #39910
Backport-PR-URL: #40383
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Nitzan Uziely <linkgoron@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
  • Loading branch information
XadillaX authored and targos committed Nov 4, 2021
1 parent 0a8c331 commit af4e682
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
24 changes: 19 additions & 5 deletions test/common/wpt.js
Expand Up @@ -301,6 +301,8 @@ class WPTRunner {
this.inProgress = new Set();
this.workers = new Map();
this.unexpectedFailures = [];

this.scriptsModifier = null;
}

/**
Expand All @@ -319,6 +321,14 @@ class WPTRunner {
this.initScript = script;
}

/**
* Set the scripts modifier for each script.
* @param {(meta: { code: string, filename: string }) => void}
*/
setScriptModifier(modifier) {
this.scriptsModifier = modifier;
}

get fullInitScript() {
if (this.initScript === null && this.dummyGlobalThisScript === null) {
return null;
Expand All @@ -330,7 +340,7 @@ class WPTRunner {
return this.initScript;
}

return `${this.fullInitScript}\n\n//===\n${this.initScript}`;
return `${this.dummyGlobalThisScript}\n\n//===\n${this.initScript}`;
}

/**
Expand Down Expand Up @@ -387,17 +397,21 @@ class WPTRunner {
// Scripts specified with the `// META: script=` header
if (meta.script) {
for (const script of meta.script) {
scriptsToRun.push({
const obj = {
filename: this.resource.toRealFilePath(relativePath, script),
code: this.resource.read(relativePath, script, false)
});
};
this.scriptsModifier?.(obj);
scriptsToRun.push(obj);
}
}
// The actual test
scriptsToRun.push({
const obj = {
code: content,
filename: absolutePath
});
};
this.scriptsModifier?.(obj);
scriptsToRun.push(obj);

const workerPath = path.join(__dirname, 'wpt/worker.js');
const worker = new Worker(workerPath, {
Expand Down
3 changes: 1 addition & 2 deletions test/wpt/status/url.json
@@ -1,7 +1,6 @@
{
"toascii.window.js": {
"requires": ["small-icu"],
"skip": "TODO: port from .window.js"
"requires": ["small-icu"]
},
"percent-encoding.window.js": {
"requires": ["small-icu"],
Expand Down
8 changes: 8 additions & 0 deletions test/wpt/test-url.js
Expand Up @@ -15,5 +15,13 @@ runner.setInitScript(`
global.DOMException = DOMException;
`);

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

0 comments on commit af4e682

Please sign in to comment.