From 4cd823953bbefa92a5548c505bc487cb92877945 Mon Sep 17 00:00:00 2001 From: XadillaX Date: Fri, 27 Aug 2021 16:45:01 +0800 Subject: [PATCH] test: pass URL's toascii.window.js WPT --- test/common/wpt.js | 24 +++++++++++++++++++----- test/wpt/status/url.json | 3 +-- test/wpt/test-url.js | 8 ++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/test/common/wpt.js b/test/common/wpt.js index 52f48685f315e3..bc6e66d75a4278 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -301,6 +301,8 @@ class WPTRunner { this.inProgress = new Set(); this.workers = new Map(); this.unexpectedFailures = []; + + this.scriptsModifier = null; } /** @@ -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; @@ -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}`; } /** @@ -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, { diff --git a/test/wpt/status/url.json b/test/wpt/status/url.json index 2372a367e982a9..fdf562c2c89c99 100644 --- a/test/wpt/status/url.json +++ b/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"], diff --git a/test/wpt/test-url.js b/test/wpt/test-url.js index d2991773cf0d01..cca2184b47720b 100644 --- a/test/wpt/test-url.js +++ b/test/wpt/test-url.js @@ -5,5 +5,13 @@ const { WPTRunner } = require('../common/wpt'); const runner = new WPTRunner('url'); +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();