1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:08:10 +00:00

Base+LibWeb: Add test case for Workers on welcome homepage

This commit is contained in:
serenitydev 2022-02-14 16:45:55 -05:00 committed by Andreas Kling
parent ae346cff6b
commit b5d891ed6a
3 changed files with 44 additions and 0 deletions

View file

@ -152,6 +152,7 @@
<li><a href="location.html">window.location property</a></li>
<li><a href="script-preparation-test.html">Test for the early return steps 6-8 of the "prepare a script" algorithm</a></li>
<li><a href="async-js.html">Basic test for async functions and their integration with the LibWeb event loop</a></li>
<li><a href="worker_parent.html">Workers</a></li>
<li><h3>Canvas</h3></li>
<li><a href="canvas.html">canvas 2D test</a></li>
<li><a href="canvas-rotate.html">canvas rotate()</a></li>

View file

@ -0,0 +1,10 @@
onmessage = evt => {
console.log("In Worker - Got message:", JSON.stringify(evt.data));
postMessage(JSON.stringify(evt.data));
};
console.log("In Worker - Loaded", this);
console.log("Keys: ", JSON.stringify(Object.keys(this)));
postMessage("loaded");

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Worker</title>
</head>
<body>
<h2>Worker Test</h2>
<div id="output"></div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
console.log("Page Loaded. Sending message");
console.log("Parent Keys: ", JSON.stringify(Object.keys(this)));
var work = new Worker("worker.js");
work.onmessage = (evt) => {
console.log("Got message from worker:", evt.data);
};
document
.getElementById("btn_hello")
.addEventListener("click", function() {
console.log("Sending Message");
work.postMessage("Hey buddy!");
});
});
</script>
<button id="btn_hello">
Say Hello!
</button>
</body>
</html>