-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1646972 [wpt PR 24250] - Test entry/incumbent globals for WebAsse…
…mbly host functions., a=testonly Automatic update from web-platform-tests Test entry/incumbent globals for WebAssembly host functions. Substantially based on #21206. Ref: WebAssembly/spec#1184. -- wpt-commits: 7fd07ecb9e031cc499962ecc61d8a3e8c32650e3 wpt-pr: 24250
- Loading branch information
1 parent
ca0d50c
commit ed98480
Showing
15 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
testing/web-platform/tests/wasm/jsapi/functions/entry-different-function-realm.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Entry settings object for host functions when the function realm is different from the test realm</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/wasm/jsapi/wasm-module-builder.js"></script> | ||
<script src="/wasm/jsapi/functions/helper.js"></script> | ||
|
||
<!-- This is what would normally be considered the entry page. However, we use functions from the | ||
resources/function/function.html realm. So window.open() should resolve relative to that realm | ||
inside host functions. --> | ||
|
||
<iframe src="resources/entry-incumbent.html"></iframe> | ||
<iframe src="resources/function/function.html" id="function-frame"></iframe> | ||
|
||
<script> | ||
setup({ explicit_done: true }); | ||
|
||
const relativeURL = "resources/window-to-open.html"; | ||
const expectedURL = (new URL(relativeURL, document.querySelector("#function-frame").src)).href; | ||
|
||
const incumbentWindow = frames[0]; | ||
const functionWindow = frames[1]; | ||
const FunctionFromAnotherWindow = functionWindow.Function; | ||
|
||
window.onload = () => { | ||
async_test(t => { | ||
t.add_cleanup(() => { delete functionWindow.args; }); | ||
functionWindow.args = [incumbentWindow, relativeURL, t, assert_equals, expectedURL]; | ||
|
||
const func = FunctionFromAnotherWindow(` | ||
const [incumbentWindow, relativeURL, t, assert_equals, expectedURL] = window.args; | ||
const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); | ||
w.onload = t.step_func_done(() => { | ||
t.add_cleanup(() => w.close()); | ||
assert_equals(w.location.href, expectedURL); | ||
}); | ||
`); | ||
call_later(func); | ||
}, "Start function"); | ||
|
||
done(); | ||
}; | ||
</script> |
43 changes: 43 additions & 0 deletions
43
testing/web-platform/tests/wasm/jsapi/functions/entry.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Entry settings object for host functions</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/wasm/jsapi/wasm-module-builder.js"></script> | ||
<script src="/wasm/jsapi/functions/helper.js"></script> | ||
|
||
<!-- This is the entry page, so window.open() should resolve relative to it, even inside host functions. --> | ||
|
||
<iframe src="resources/entry-incumbent.html"></iframe> | ||
|
||
<script> | ||
setup({ explicit_done: true }); | ||
|
||
const relativeURL = "resources/window-to-open.html"; | ||
const expectedURL = (new URL(relativeURL, location.href)).href; | ||
|
||
const incumbentWindow = frames[0]; | ||
|
||
window.onload = () => { | ||
async_test(t => { | ||
const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); | ||
w.onload = t.step_func_done(() => { | ||
t.add_cleanup(() => w.close()); | ||
assert_equals(w.location.href, expectedURL); | ||
}); | ||
}, "Sanity check: this all works as expected synchronously"); | ||
|
||
async_test(t => { | ||
// No t.step_func because that could change the realms | ||
call_later(() => { | ||
const w = incumbentWindow.runWindowOpenVeryIndirectly(relativeURL); | ||
w.onload = t.step_func_done(() => { | ||
t.add_cleanup(() => w.close()); | ||
assert_equals(w.location.href, expectedURL); | ||
}); | ||
}); | ||
}, "Start function"); | ||
|
||
done(); | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function call_later(f) { | ||
const builder = new WasmModuleBuilder(); | ||
const functionIndex = builder.addImport("module", "imported", kSig_v_v); | ||
builder.addStart(functionIndex); | ||
const buffer = builder.toBuffer(); | ||
|
||
WebAssembly.instantiate(buffer, { | ||
"module": { | ||
"imported": f, | ||
} | ||
}); | ||
} |
54 changes: 54 additions & 0 deletions
54
testing/web-platform/tests/wasm/jsapi/functions/incumbent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Incumbent settings object for host functions</title> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<!-- This is the entry page. --> | ||
|
||
<iframe src="resources/incumbent-incumbent.html"></iframe> | ||
|
||
<script> | ||
setup({ explicit_done: true }); | ||
|
||
// postMessage should pick the incumbent page as its .source value to set on the MessageEvent, even | ||
// inside host functions. | ||
const expectedURL = (new URL("resources/incumbent-incumbent.html", location.href)).href; | ||
|
||
let testId = 0; | ||
|
||
window.onload = () => { | ||
const relevantWindow = frames[0].document.querySelector("#r").contentWindow; | ||
|
||
function setupTest(t) { | ||
++testId; | ||
const thisTestId = testId; | ||
|
||
relevantWindow.addEventListener("messagereceived", t.step_func(e => { | ||
const [receivedTestId, receivedSourceURL] = e.detail; | ||
|
||
if (receivedTestId !== thisTestId) { | ||
return; | ||
} | ||
|
||
assert_equals(receivedSourceURL, expectedURL); | ||
t.done(); | ||
})); | ||
|
||
return thisTestId; | ||
} | ||
|
||
async_test(t => { | ||
const thisTestId = setupTest(t); | ||
|
||
frames[0].runWindowPostMessageVeryIndirectly(thisTestId, "*"); | ||
}, "Sanity check: this all works as expected synchronously"); | ||
|
||
async_test(t => { | ||
const thisTestId = setupTest(t); | ||
frames[0].runWindowPostMessageVeryIndirectlyWithNoUserCode(thisTestId, "*"); | ||
}, "Start function"); | ||
|
||
done(); | ||
}; | ||
</script> |
5 changes: 5 additions & 0 deletions
5
testing/web-platform/tests/wasm/jsapi/functions/resources/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
A couple notes about the files scattered in this `resources/` directory: | ||
|
||
* The nested directory structure is necessary here so that relative URL resolution can be tested; we need different sub-paths for each document. | ||
|
||
* The semi-duplicate `window-to-open.html`s scattered throughout are present because Firefox, at least, does not fire `Window` `load` events for 404s, so we want to ensure that no matter which global is used, `window`'s `load` event is hit and our tests can proceed. |
4 changes: 4 additions & 0 deletions
4
testing/web-platform/tests/wasm/jsapi/functions/resources/current/current.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Current page used as a test helper</title> | ||
|
3 changes: 3 additions & 0 deletions
3
...g/web-platform/tests/wasm/jsapi/functions/resources/current/resources/window-to-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>If the current settings object is used this page will be opened</title> |
15 changes: 15 additions & 0 deletions
15
testing/web-platform/tests/wasm/jsapi/functions/resources/entry-incumbent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Incumbent page used as a test helper</title> | ||
|
||
<iframe src="relevant/relevant.html" id="r"></iframe> | ||
<iframe src="current/current.html" id="c"></iframe> | ||
|
||
<script> | ||
const relevant = document.querySelector("#r"); | ||
const current = document.querySelector("#c"); | ||
|
||
window.runWindowOpenVeryIndirectly = (...args) => { | ||
return current.contentWindow.open.call(relevant.contentWindow, ...args); | ||
}; | ||
</script> |
3 changes: 3 additions & 0 deletions
3
testing/web-platform/tests/wasm/jsapi/functions/resources/function/function.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Realm for a host function used as a test helper</title> |
3 changes: 3 additions & 0 deletions
3
.../web-platform/tests/wasm/jsapi/functions/resources/function/resources/window-to-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>If the function's settings object is used this page will be opened</title> |
24 changes: 24 additions & 0 deletions
24
testing/web-platform/tests/wasm/jsapi/functions/resources/incumbent-incumbent.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Incumbent page used as a test helper</title> | ||
|
||
<script src="/wasm/jsapi/wasm-module-builder.js"></script> | ||
<script src="/wasm/jsapi/functions/helper.js"></script> | ||
|
||
<iframe src="relevant/relevant.html" id="r"></iframe> | ||
<iframe src="current/current.html" id="c"></iframe> | ||
|
||
<script> | ||
const relevant = document.querySelector("#r"); | ||
const current = document.querySelector("#c"); | ||
|
||
window.runWindowPostMessageVeryIndirectly = (...args) => { | ||
return current.contentWindow.postMessage.call(relevant.contentWindow, ...args); | ||
}; | ||
|
||
// This tests the backup incumbent settings object stack scenario, by avoiding putting user code on the stack. | ||
window.runWindowPostMessageVeryIndirectlyWithNoUserCode = (...args) => { | ||
const runWindowPostMessage = current.contentWindow.postMessage.bind(relevant.contentWindow, ...args); | ||
call_later(runWindowPostMessage); | ||
}; | ||
</script> |
14 changes: 14 additions & 0 deletions
14
testing/web-platform/tests/wasm/jsapi/functions/resources/relevant/relevant.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Relevant page used as a test helper</title> | ||
|
||
<script> | ||
// incumbent.html will end up posting a message to here. We need to signal back the "source". | ||
|
||
window.onmessage = e => { | ||
const testId = e.data; | ||
const sourceURL = e.source.document.URL; | ||
|
||
window.dispatchEvent(new CustomEvent("messagereceived", { detail: [testId, sourceURL] })); | ||
}; | ||
</script> |
3 changes: 3 additions & 0 deletions
3
.../web-platform/tests/wasm/jsapi/functions/resources/relevant/resources/window-to-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>If the relevant settings object is used this page will be opened</title> |
3 changes: 3 additions & 0 deletions
3
testing/web-platform/tests/wasm/jsapi/functions/resources/resources/window-to-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>If the incumbent settings object is used this page will be opened</title> |
3 changes: 3 additions & 0 deletions
3
testing/web-platform/tests/wasm/jsapi/functions/resources/window-to-open.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>If the entry settings object is used this page will be opened</title> |