mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 982726 - Patch 4 - Extensive testing of postMessage. r=baku
--HG-- extra : rebase_source : c2a5b3e61cd314c995cc1935aa928247301cb9c5 extra : amend_source : a970a4e351b2b7064fbccbed6b74dedec609f878
This commit is contained in:
parent
0d65208ed0
commit
0dd8b26de4
@ -42,8 +42,8 @@ class ServiceWorkerClientPostMessageRunnable MOZ_FINAL : public nsRunnable
|
||||
|
||||
public:
|
||||
ServiceWorkerClientPostMessageRunnable(uint64_t aId,
|
||||
JSAutoStructuredCloneBuffer&& aData,
|
||||
nsTArray<nsCOMPtr<nsISupports>>& aClonedObjects)
|
||||
JSAutoStructuredCloneBuffer&& aData,
|
||||
nsTArray<nsCOMPtr<nsISupports>>& aClonedObjects)
|
||||
: mId(aId),
|
||||
mBuffer(Move(aData))
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ support-files =
|
||||
[test_install_event.html]
|
||||
[test_navigator.html]
|
||||
[test_post_message.html]
|
||||
[test_post_message_advanced.html]
|
||||
[test_scopes.html]
|
||||
[test_controller.html]
|
||||
[test_unregister.html]
|
||||
|
@ -0,0 +1,91 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bug 982726 - Test service worker post message advanced </title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test"></pre>
|
||||
<script class="testbody" type="text/javascript">
|
||||
var registration;
|
||||
var base = ["string", true, 42];
|
||||
var blob = new Blob(["blob_content"]);
|
||||
var file = new File(["file_content"], "file");
|
||||
var obj = { body : "object_content" };
|
||||
|
||||
function readBlob(blob) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onloadend = () => resolve(reader.result);
|
||||
reader.readAsText(blob);
|
||||
});
|
||||
}
|
||||
|
||||
function equals(v1, v2) {
|
||||
return Promise.all([v1, v2]).then(function(val) {
|
||||
ok(val[0] === val[1], "Values should match.");
|
||||
});
|
||||
}
|
||||
|
||||
function blob_equals(b1, b2) {
|
||||
return equals(readBlob(b1), readBlob(b2));
|
||||
}
|
||||
|
||||
function file_equals(f1, f2) {
|
||||
return equals(f1.name, f2.name).then(blob_equals(f1, f2));
|
||||
}
|
||||
|
||||
function obj_equals(o1, o2) {
|
||||
return equals(o1.body, o2.body);
|
||||
}
|
||||
|
||||
function start() {
|
||||
return navigator.serviceWorker.register("message_posting_worker.js",
|
||||
{ scope: "./sw_clients/" }).then((swr) => registration = swr);
|
||||
}
|
||||
|
||||
function testPostMessageObject(obj, test) {
|
||||
var p = new Promise(function(res, rej) {
|
||||
window.onmessage = function(e) {
|
||||
if (e.data === "READY") {
|
||||
registration.active.postMessage(obj)
|
||||
} else {
|
||||
test(obj, e.data).then(res);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var w = window.open("sw_clients/service_worker_controlled.html");
|
||||
return p.then(() => w.close());
|
||||
}
|
||||
|
||||
function runTest() {
|
||||
start()
|
||||
.then(testPostMessageObject.bind(this, base[0], equals))
|
||||
.then(testPostMessageObject.bind(this, base[1], equals))
|
||||
.then(testPostMessageObject.bind(this, base[2], equals))
|
||||
.then(testPostMessageObject.bind(this, blob, blob_equals))
|
||||
.then(testPostMessageObject.bind(this, file, file_equals))
|
||||
.then(testPostMessageObject.bind(this, obj, obj_equals))
|
||||
.catch(function(e) {
|
||||
ok(false, "Some test failed with error " + e);
|
||||
}).then(SimpleTest.finish);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({"set": [
|
||||
["dom.serviceWorkers.enabled", true],
|
||||
["dom.serviceWorkers.testing.enabled", true]
|
||||
]}, runTest);
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user