Source code
Revision control
Copy as Markdown
Other Tools
<!--
Any copyright is dedicated to the Public Domain.
-->
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function ok(aCondition, aMessage) {
parent.postMessage({status: "callback", data: "ok", condition: aCondition, message: aMessage}, "*");
}
function doUnregister() {
navigator.serviceWorker.getRegistration().then(swr => {
swr.unregister().then(function(result) {
ok(result, "Unregister should return true.");
parent.postMessage({status: "callback", data: "done"}, "*");
}, function(e) {
ok(false, "Unregistering the SW failed with " + e);
});
});
}
function doEventSource() {
var source = new EventSource(prefix + "eventsource.resource");
source.onmessage = function(e) {
source.onmessage = null;
source.close();
ok(true, "EventSource should work with synthetic responses");
doUnregister();
};
source.onerror = function(error) {
source.onmessage = null;
source.close();
ok(false, "Something went wrong");
};
}
function onLoad() {
if (!parent) {
dump("eventsource/eventsource_synthetic_response.html shouldn't be launched directly!");
}
window.addEventListener("message", function onMessage(e) {
if (e.data.status === "callback") {
switch(e.data.data) {
case "eventsource":
doEventSource();
window.removeEventListener("message", onMessage);
break;
default:
ok(false, "Something went wrong")
break
}
}
});
navigator.serviceWorker.ready.then(function() {
parent.postMessage({status: "callback", data: "ready"}, "*");
});
navigator.serviceWorker.addEventListener("message", function(event) {
parent.postMessage(event.data, "*");
});
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>