mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1189543 - pushManager.getSubscription()
should return null
for nonexistent push subscriptions in workers. r=nsm
This commit is contained in:
parent
9a9491f4cd
commit
4503d0abcf
@ -464,9 +464,13 @@ public:
|
|||||||
nsRefPtr<PromiseWorkerProxy> proxy = mProxy.forget();
|
nsRefPtr<PromiseWorkerProxy> proxy = mProxy.forget();
|
||||||
nsRefPtr<Promise> promise = proxy->GetWorkerPromise();
|
nsRefPtr<Promise> promise = proxy->GetWorkerPromise();
|
||||||
if (NS_SUCCEEDED(mStatus)) {
|
if (NS_SUCCEEDED(mStatus)) {
|
||||||
nsRefPtr<WorkerPushSubscription> sub =
|
if (mEndpoint.IsEmpty()) {
|
||||||
new WorkerPushSubscription(mEndpoint, mScope);
|
promise->MaybeResolve(JS::NullHandleValue);
|
||||||
promise->MaybeResolve(sub);
|
} else {
|
||||||
|
nsRefPtr<WorkerPushSubscription> sub =
|
||||||
|
new WorkerPushSubscription(mEndpoint, mScope);
|
||||||
|
promise->MaybeResolve(sub);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
||||||
}
|
}
|
||||||
|
@ -21,3 +21,5 @@ skip-if = os == "android" || toolkit == "gonk"
|
|||||||
skip-if = os == "android" || toolkit == "gonk"
|
skip-if = os == "android" || toolkit == "gonk"
|
||||||
[test_try_registering_offline_disabled.html]
|
[test_try_registering_offline_disabled.html]
|
||||||
skip-if = os == "android" || toolkit == "gonk"
|
skip-if = os == "android" || toolkit == "gonk"
|
||||||
|
[test_push_manager_worker.html]
|
||||||
|
skip-if = os == "android" || toolkit == "gonk"
|
||||||
|
101
dom/push/test/test_push_manager_worker.html
Normal file
101
dom/push/test/test_push_manager_worker.html
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
Bug 1184574: Expose PushManager to workers.
|
||||||
|
|
||||||
|
Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/licenses/publicdomain/
|
||||||
|
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 1184574</title>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||||
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
||||||
|
</head>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1184574">Mozilla Bug 1184574</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
|
||||||
|
var registration;
|
||||||
|
|
||||||
|
function start() {
|
||||||
|
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."})
|
||||||
|
.then(swr => { registration = swr; return swr; });
|
||||||
|
}
|
||||||
|
|
||||||
|
function unregisterSW() {
|
||||||
|
return registration.unregister().then(function(result) {
|
||||||
|
ok(result, "Unregister should return true.");
|
||||||
|
}, function(e) {
|
||||||
|
dump("Unregistering the SW failed with " + e + "\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupPushNotification(swr) {
|
||||||
|
return swr.pushManager.subscribe().then(
|
||||||
|
pushSubscription => {
|
||||||
|
ok(true, "successful registered for push notification");
|
||||||
|
return pushSubscription;
|
||||||
|
}, error => {
|
||||||
|
ok(false, "could not register for push notification");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNewEndpointFromWorker(pushSubscription) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
var channel = new MessageChannel();
|
||||||
|
channel.port1.onmessage = e => {
|
||||||
|
(e.data.error ? reject : resolve)(e.data);
|
||||||
|
};
|
||||||
|
registration.active.postMessage({
|
||||||
|
endpoint: pushSubscription.endpoint,
|
||||||
|
}, [channel.port2]);
|
||||||
|
}).then(data => {
|
||||||
|
return registration.pushManager.getSubscription().then(
|
||||||
|
pushSubscription => {
|
||||||
|
is(data.endpoint, pushSubscription.endpoint,
|
||||||
|
"Wrong push endpoint in parent");
|
||||||
|
return pushSubscription;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function unregisterPushNotification(pushSubscription) {
|
||||||
|
return pushSubscription.unsubscribe().then(
|
||||||
|
result => {
|
||||||
|
ok(result, "unsubscribe() on existing subscription should return true.");
|
||||||
|
return pushSubscription;
|
||||||
|
}, error => {
|
||||||
|
ok(false, "unsubscribe() should never fail.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function runTest() {
|
||||||
|
start()
|
||||||
|
.then(setupPushNotification)
|
||||||
|
.then(getNewEndpointFromWorker)
|
||||||
|
.then(unregisterPushNotification)
|
||||||
|
.then(unregisterSW)
|
||||||
|
.catch(function(e) {
|
||||||
|
ok(false, "Some test failed with error " + e);
|
||||||
|
}).then(SimpleTest.finish);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpecialPowers.pushPrefEnv({"set": [
|
||||||
|
["dom.push.enabled", true],
|
||||||
|
["dom.serviceWorkers.exemptFromPerDomainMax", true],
|
||||||
|
["dom.serviceWorkers.enabled", true],
|
||||||
|
["dom.serviceWorkers.testing.enabled", true]
|
||||||
|
]}, runTest);
|
||||||
|
SpecialPowers.addPermission('push', true, document);
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,7 +1,14 @@
|
|||||||
// Any copyright is dedicated to the Public Domain.
|
// Any copyright is dedicated to the Public Domain.
|
||||||
// http://creativecommons.org/licenses/publicdomain/
|
// http://creativecommons.org/licenses/publicdomain/
|
||||||
|
|
||||||
|
// This worker is used for two types of tests. `handlePush` sends messages to
|
||||||
|
// `frame.html`, which verifies that the worker can receive push messages.
|
||||||
|
|
||||||
|
// `handleMessage` receives a message from `test_push_manager_worker.html`, and
|
||||||
|
// verifies that `PushManager` can be used from the worker.
|
||||||
|
|
||||||
this.onpush = handlePush;
|
this.onpush = handlePush;
|
||||||
|
this.onmessage = handleMessage;
|
||||||
|
|
||||||
function handlePush(event) {
|
function handlePush(event) {
|
||||||
|
|
||||||
@ -19,3 +26,26 @@ function handlePush(event) {
|
|||||||
result[0].postMessage({type: "finished", okay: "no"});
|
result[0].postMessage({type: "finished", okay: "no"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleMessage(event) {
|
||||||
|
self.registration.pushManager.getSubscription().then(subscription => {
|
||||||
|
if (subscription.endpoint != event.data.endpoint) {
|
||||||
|
throw new Error("Wrong push endpoint in worker");
|
||||||
|
}
|
||||||
|
return subscription.unsubscribe();
|
||||||
|
}).then(result => {
|
||||||
|
if (!result) {
|
||||||
|
throw new Error("Error dropping subscription in worker");
|
||||||
|
}
|
||||||
|
return self.registration.pushManager.getSubscription();
|
||||||
|
}).then(subscription => {
|
||||||
|
if (subscription) {
|
||||||
|
throw new Error("Subscription not dropped in worker");
|
||||||
|
}
|
||||||
|
return self.registration.pushManager.subscribe();
|
||||||
|
}).then(subscription => {
|
||||||
|
event.ports[0].postMessage({endpoint: subscription.endpoint});
|
||||||
|
}).catch(error => {
|
||||||
|
event.ports[0].postMessage({error: error});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user