Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update WPT fixtures resources, common, streams, FileAPI #46912

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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