Skip to content

Commit

Permalink
test: update WPT resources, common, streams, FileAPI, broadcastchannel
Browse files Browse the repository at this point in the history
PR-URL: #46912
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
  • Loading branch information
panva authored and targos committed Mar 14, 2023
1 parent adff278 commit c8d528e
Show file tree
Hide file tree
Showing 108 changed files with 2,076 additions and 5,276 deletions.
26 changes: 11 additions & 15 deletions test/common/wpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,13 @@ class WPTRunner {
this.scriptsModifier = modifier;
}

fullInitScript(hasSubsetScript, locationSearchString) {
fullInitScript(url, metaTitle) {
let { initScript } = this;
if (hasSubsetScript || locationSearchString) {
initScript = `${initScript}\n\n//===\nglobalThis.location ||= {};`;
}

if (locationSearchString) {
initScript = `${initScript}\n\n//===\nglobalThis.location.search = "${locationSearchString}";`;
initScript = `${initScript}\n\n//===\nglobalThis.location = new URL("${url.href}");`;

if (metaTitle) {
initScript = `${initScript}\n\n//===\nglobalThis.META_TITLE = "${metaTitle}";`;
}

if (this.globalThisInitScripts.length === null) {
Expand Down Expand Up @@ -553,13 +552,13 @@ class WPTRunner {
const relativePath = spec.getRelativePath();
const harnessPath = fixtures.path('wpt', 'resources', 'testharness.js');
const scriptsToRun = [];
let hasSubsetScript = false;
let needsGc = false;

// Scripts specified with the `// META: script=` header
if (meta.script) {
for (const script of meta.script) {
if (script === '/common/subset-tests.js' || script === '/common/subset-tests-by-key.js') {
hasSubsetScript = true;
if (script === '/common/gc.js') {
needsGc = true;
}
const obj = {
filename: this.resource.toRealFilePath(relativePath, script),
Expand Down Expand Up @@ -592,12 +591,13 @@ class WPTRunner {
testRelativePath: relativePath,
wptRunner: __filename,
wptPath: this.path,
initScript: this.fullInitScript(hasSubsetScript, variant),
initScript: this.fullInitScript(new URL(`/${relativePath.replace(/\.js$/, '.html')}${variant}`, 'http://wpt'), meta.title),
harness: {
code: fs.readFileSync(harnessPath, 'utf8'),
filename: harnessPath,
},
scriptsToRun,
needsGc,
},
});
this.workers.set(testFileName, worker);
Expand Down Expand Up @@ -749,11 +749,7 @@ class WPTRunner {
*/
resultCallback(filename, test, reportResult) {
const status = this.getTestStatus(test.status);
const title = this.getTestTitle(filename);
if (/^Untitled( \d+)?$/.test(test.name)) {
test.name = `${title}${test.name.slice(8)}`;
}
console.log(`---- ${title} ----`);
console.log(`---- ${test.name} ----`);
if (status !== kPass) {
this.fail(filename, test, status, reportResult);
} else {
Expand Down
17 changes: 12 additions & 5 deletions test/common/wpt/worker.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
'use strict';

const { runInThisContext } = require('vm');
const { runInNewContext, runInThisContext } = require('vm');
const { setFlagsFromString } = require('v8');
const { parentPort, workerData } = require('worker_threads');

const { ResourceLoader } = require(workerData.wptRunner);
const resource = new ResourceLoader(workerData.wptPath);

global.self = global;
global.GLOBAL = {
if (workerData.needsGc) {
// See https://github.com/nodejs/node/issues/16595#issuecomment-340288680
setFlagsFromString('--expose-gc');
globalThis.gc = runInNewContext('gc');
}

globalThis.self = global;
globalThis.GLOBAL = {
isWindow() { return false; },
isShadowRealm() { return false; },
};
global.require = require;
globalThis.require = require;

// This is a mock, because at the moment fetch is not implemented
// in Node.js, but some tests and harness depend on this to pull
// resources.
global.fetch = function fetch(file) {
globalThis.fetch = function fetch(file) {
return resource.read(workerData.testRelativePath, file, true);
};

Expand Down
59 changes: 59 additions & 0 deletions test/fixtures/wpt/FileAPI/Blob-methods-from-detached-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Blob methods from detached frame work as expected</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<iframe id="emptyDocumentIframe" src="../support/empty-document.html"></iframe>

<script>
const BlobPrototypeFromDetachedFramePromise = new Promise(resolve => {
emptyDocumentIframe.onload = () => {
const BlobPrototype = emptyDocumentIframe.contentWindow.Blob.prototype;
emptyDocumentIframe.remove();
resolve(BlobPrototype);
};
});

const charCodeArrayToString = charCodeArray => Array.from(charCodeArray, c => String.fromCharCode(c)).join("");
const charCodeBufferToString = charCodeBuffer => charCodeArrayToString(new Uint8Array(charCodeBuffer));

promise_test(async () => {
const { slice } = await BlobPrototypeFromDetachedFramePromise;
const blob = new Blob(["foobar"]);

const slicedBlob = slice.call(blob, 1, 3);
assert_true(slicedBlob instanceof Blob);

assert_equals(await slicedBlob.text(), "oo");
assert_equals(charCodeBufferToString(await slicedBlob.arrayBuffer()), "oo");

const reader = slicedBlob.stream().getReader();
const { value } = await reader.read();
assert_equals(charCodeArrayToString(value), "oo");
}, "slice()");

promise_test(async () => {
const { text } = await BlobPrototypeFromDetachedFramePromise;
const blob = new Blob(["foo"]);

assert_equals(await text.call(blob), "foo");
}, "text()");

promise_test(async () => {
const { arrayBuffer } = await BlobPrototypeFromDetachedFramePromise;
const blob = new Blob(["bar"]);

const charCodeBuffer = await arrayBuffer.call(blob);
assert_equals(charCodeBufferToString(charCodeBuffer), "bar");
}, "arrayBuffer()");

promise_test(async () => {
const { stream } = await BlobPrototypeFromDetachedFramePromise;
const blob = new Blob(["baz"]);

const reader = stream.call(blob).getReader();
const { value } = await reader.read();
assert_equals(charCodeArrayToString(value), "baz");
}, "stream()");
</script>
Loading

0 comments on commit c8d528e

Please sign in to comment.