From 4aee4767d30c556182d998d653993e4b94450e49 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 22 Jul 2019 10:20:41 +0000 Subject: [PATCH] Bug 1556663 [wpt PR 17159] - Add optional test for cloning of error stacks, a=testonly Automatic update from web-platform-tests Add optional test for cloning of error stacks Supplements https://github.com/web-platform-tests/wpt/pull/17095. Follows https://github.com/whatwg/html/pull/4665 and https://github.com/heycam/webidl/pull/732. -- wpt-commits: 1da6bed5d8c4c38200383b86928b7be68bfb87da wpt-pr: 17159 --HG-- rename : testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-iframe.html => testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-iframe.html rename : testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-worker.js => testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-worker.js --- .../safe-passing-of-structured-data/echo.js | 1 - .../resources/echo-iframe.html | 0 .../resources/echo-worker.js | 0 .../identity-not-preserved.html | 20 +++-- .../shared-array-buffers/no-transferring.html | 2 +- ...ured-cloning-error-stack-optional.sub.window.js | 85 ++++++++++++++++++++++ .../structured_clone_bigint.html | 2 +- .../structuredclone_0.html | 2 +- 8 files changed, 100 insertions(+), 12 deletions(-) delete mode 100644 testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/echo.js rename testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/{shared-array-buffers => }/resources/echo-iframe.html (100%) rename testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/{shared-array-buffers => }/resources/echo-worker.js (100%) create mode 100644 testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured-cloning-error-stack-optional.sub.window.js diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/echo.js b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/echo.js deleted file mode 100644 index 02184921cf3b..000000000000 --- a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/echo.js +++ /dev/null @@ -1 +0,0 @@ -onmessage = function (ev) { postMessage(ev.data); } \ No newline at end of file diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-iframe.html b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-iframe.html similarity index 100% rename from testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-iframe.html rename to testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-iframe.html diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-worker.js b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-worker.js similarity index 100% rename from testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/resources/echo-worker.js rename to testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/resources/echo-worker.js diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/identity-not-preserved.html b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/identity-not-preserved.html index 91110867d7b4..869f49043e97 100644 --- a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/identity-not-preserved.html +++ b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/identity-not-preserved.html @@ -5,6 +5,7 @@ +
@@ -13,9 +14,10 @@ "use strict"; async_test(t => { + const testId = token(); const sab = new SharedArrayBuffer(1); window.addEventListener("message", t.step_func(({ data }) => { - if (data.testId !== 1) { + if (data.testId !== testId) { return; } @@ -24,15 +26,16 @@ async_test(t => { t.done(); })); - window.postMessage({ sab, testId: 1 }, "*"); + window.postMessage({ testId, sab }, "*"); }, "postMessaging to this window does not give back the same SharedArrayBuffer (but does use the same backing block)"); async_test(t => { + const testId = token(); const sab = new SharedArrayBuffer(); - const worker = new Worker("resources/echo-worker.js"); + const worker = new Worker("../resources/echo-worker.js"); worker.addEventListener("message", t.step_func(({ data }) => { - if (data.testId !== 2) { + if (data.testId !== testId) { return; } @@ -40,13 +43,14 @@ async_test(t => { t.done(); })); - worker.postMessage({ testId: 2, sab }); + worker.postMessage({ testId, sab }); }, "postMessaging to a worker and back does not give back the same SharedArrayBuffer"); async_test(t => { + const testId = token(); const sab = new SharedArrayBuffer(); window.addEventListener("message", t.step_func(({ data }) => { - if (data.testId !== 3) { + if (data.testId !== testId) { return; } @@ -56,9 +60,9 @@ async_test(t => { const iframe = document.createElement("iframe"); iframe.onload = t.step_func(() => { - iframe.contentWindow.postMessage({ testId: 3, sab }, "*"); + iframe.contentWindow.postMessage({ testId, sab }, "*"); }); - iframe.src = "resources/echo-iframe.html"; + iframe.src = "../resources/echo-iframe.html"; document.body.appendChild(iframe); }, "postMessaging to an iframe and back does not give back the same SharedArrayBuffer"); diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/no-transferring.html b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/no-transferring.html index fa95d8abe5d4..b39e37fd4966 100644 --- a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/no-transferring.html +++ b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/shared-array-buffers/no-transferring.html @@ -17,7 +17,7 @@ test(() => { test(() => { const sab = new SharedArrayBuffer(); - const worker = new Worker("resources/echo-worker.js"); + const worker = new Worker("../resources/echo-worker.js"); assert_throws("DataCloneError", () => worker.postMessage(sab, [sab])); assert_throws("DataCloneError", () => worker.postMessage("test", [sab])); }, "Trying to transfer a SharedArrayBuffer to a worker throws"); diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured-cloning-error-stack-optional.sub.window.js b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured-cloning-error-stack-optional.sub.window.js new file mode 100644 index 000000000000..2fb2f7d26609 --- /dev/null +++ b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured-cloning-error-stack-optional.sub.window.js @@ -0,0 +1,85 @@ +// META: script=/common/utils.js + +// .stack properties on errors are unspecified, but are present in most +// browsers, most of the time. https://github.com/tc39/proposal-error-stacks/ tracks standardizing them. +// Tests will pass automatically if the .stack property isn't present. + +stackTests(() => { + return new Error('some message'); +}, 'page-created Error'); + +stackTests(() => { + return new DOMException('InvalidStateError', 'some message'); +}, 'page-created DOMException'); + +stackTests(() => { + try { + Object.defineProperty(); + } catch (e) { + return e; + } +}, 'JS-engine-created TypeError'); + +stackTests(() => { + try { + HTMLParagraphElement.prototype.align; + } catch (e) { + return e; + } +}, 'web API-created TypeError'); + +stackTests(() => { + try { + document.createElement(''); + } catch (e) { + return e; + } +}, 'web API-created DOMException'); + +function stackTests(errorFactory, description) { + async_test(t => { + const error = errorFactory(); + const originalStack = error.stack; + + if (!originalStack) { + t.done(); + return; + } + + const worker = new Worker('resources/echo-worker.js'); + worker.onmessage = t.step_func_done(e => { + assert_equals(e.data.stack, originalStack); + }); + + worker.postMessage(error); + }, description + ' (worker)'); + + async_test(t => { + const thisTestId = token(); + + const error = errorFactory(); + const originalStack = error.stack; + + if (!originalStack) { + t.done(); + return; + } + + const iframe = document.createElement('iframe'); + window.addEventListener('message', t.step_func(e => { + if (e.data.testId === thisTestId) { + assert_equals(e.data.error.stack, originalStack); + t.done(); + } + })); + + iframe.onload = t.step_func(() => { + iframe.contentWindow.postMessage({ error, testId: thisTestId }, "*"); + }); + + const crossSiteEchoIFrame = new URL('resources/echo-iframe.html', location.href); + crossSiteEchoIFrame.hostname = '{{hosts[alt][www1]}}'; + iframe.src = crossSiteEchoIFrame; + document.body.append(iframe); + }, description + ' (cross-site iframe)'); +} diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_bigint.html b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_bigint.html index e51837b6ffc7..995edac8da9d 100644 --- a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_bigint.html +++ b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structured_clone_bigint.html @@ -23,7 +23,7 @@ //the worker is used for each test in sequence //worker's callback will be set for each test //worker's internal onmessage echoes the data back to this thread through postMessage - worker = new Worker("./echo.js"); + worker = new Worker("./resources/echo-worker.js"); testCollection = [ function() { var t = async_test("Primitive BigInt is cloned"); diff --git a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html index c9631a1fb751..098283106ef8 100644 --- a/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html +++ b/testing/web-platform/tests/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html @@ -18,7 +18,7 @@ //the worker is used for each test in sequence //worker's callback will be set for each test //worker's internal onmessage echoes the data back to this thread through postMessage - worker = new Worker("./echo.js"); + worker = new Worker("./resources/echo-worker.js"); testCollection = [ function() { var t = async_test("Primitive string is cloned"); -- 2.11.4.GIT