mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1246341 - Add a test for push event error reporting. r=dragana
MozReview-Commit-ID: LABOJnYtpD5 --HG-- extra : rebase_source : 86c27b8a2deb388cdb34a82aebd12b042477acb5
This commit is contained in:
parent
d97d284c24
commit
18c5c296ef
@ -65,9 +65,6 @@ NS_IMETHODIMP
|
|||||||
PushNotifier::NotifySubscriptionChange(const nsACString& aScope,
|
PushNotifier::NotifySubscriptionChange(const nsACString& aScope,
|
||||||
nsIPrincipal* aPrincipal)
|
nsIPrincipal* aPrincipal)
|
||||||
{
|
{
|
||||||
if (XRE_IsContentProcess()) {
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (ShouldNotifyObservers(aPrincipal)) {
|
if (ShouldNotifyObservers(aPrincipal)) {
|
||||||
rv = NotifySubscriptionChangeObservers(aScope);
|
rv = NotifySubscriptionChangeObservers(aScope);
|
||||||
@ -89,9 +86,6 @@ PushNotifier::NotifyPush(const nsACString& aScope, nsIPrincipal* aPrincipal,
|
|||||||
const nsAString& aMessageId,
|
const nsAString& aMessageId,
|
||||||
const Maybe<nsTArray<uint8_t>>& aData)
|
const Maybe<nsTArray<uint8_t>>& aData)
|
||||||
{
|
{
|
||||||
if (XRE_IsContentProcess()) {
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (ShouldNotifyObservers(aPrincipal)) {
|
if (ShouldNotifyObservers(aPrincipal)) {
|
||||||
rv = NotifyPushObservers(aScope, aData);
|
rv = NotifyPushObservers(aScope, aData);
|
||||||
|
@ -29,9 +29,8 @@ namespace dom {
|
|||||||
* forwards incoming push messages to service workers running in the content
|
* forwards incoming push messages to service workers running in the content
|
||||||
* process, and emits XPCOM observer notifications for system subscriptions.
|
* process, and emits XPCOM observer notifications for system subscriptions.
|
||||||
*
|
*
|
||||||
* The XPCOM service can only be used from the main process. Callers running
|
* This service exists solely to support `PushService.jsm`. Other callers
|
||||||
* in the content process should use
|
* should use `ServiceWorkerManager` directly.
|
||||||
* `ServiceWorkerManager::SendPush{SubscriptionChange}Event` directly.
|
|
||||||
*/
|
*/
|
||||||
class PushNotifier final : public nsIPushNotifier
|
class PushNotifier final : public nsIPushNotifier
|
||||||
{
|
{
|
||||||
|
10
dom/push/test/error_worker.js
Normal file
10
dom/push/test/error_worker.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
this.onpush = function(event) {
|
||||||
|
var request = event.data.json();
|
||||||
|
if (request.type == "exception") {
|
||||||
|
throw new Error("Uncaught exception");
|
||||||
|
}
|
||||||
|
if (request.type == "rejection") {
|
||||||
|
event.waitUntil(Promise.reject(
|
||||||
|
new Error("Unhandled rejection")));
|
||||||
|
}
|
||||||
|
};
|
@ -7,6 +7,7 @@ support-files =
|
|||||||
lifetime_worker.js
|
lifetime_worker.js
|
||||||
test_utils.js
|
test_utils.js
|
||||||
mockpushserviceparent.js
|
mockpushserviceparent.js
|
||||||
|
error_worker.js
|
||||||
|
|
||||||
[test_has_permissions.html]
|
[test_has_permissions.html]
|
||||||
[test_permissions.html]
|
[test_permissions.html]
|
||||||
@ -19,3 +20,4 @@ support-files =
|
|||||||
[test_data.html]
|
[test_data.html]
|
||||||
[test_try_registering_offline_disabled.html]
|
[test_try_registering_offline_disabled.html]
|
||||||
[test_serviceworker_lifetime.html]
|
[test_serviceworker_lifetime.html]
|
||||||
|
[test_error_reporting.html]
|
||||||
|
@ -157,6 +157,13 @@ var MockService = {
|
|||||||
unregister(pageRecord) {
|
unregister(pageRecord) {
|
||||||
return this.sendRequest("unregister", pageRecord);
|
return this.sendRequest("unregister", pageRecord);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reportDeliveryError(messageId, reason) {
|
||||||
|
sendAsyncMessage("service-delivery-error", {
|
||||||
|
messageId: messageId,
|
||||||
|
reason: reason,
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
addMessageListener("service-replace", function () {
|
addMessageListener("service-replace", function () {
|
||||||
|
89
dom/push/test/test_error_reporting.html
Normal file
89
dom/push/test/test_error_reporting.html
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
Bug 1246341: Report message delivery failures to the Push server.
|
||||||
|
|
||||||
|
Any copyright is dedicated to the Public Domain.
|
||||||
|
http://creativecommons.org/licenses/publicdomain/
|
||||||
|
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<title>Test for Bug 1246341</title>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/dom/push/test/test_utils.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=1246341">Mozilla Bug 1246341</a>
|
||||||
|
<p id="display"></p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
<script class="testbody" type="text/javascript">
|
||||||
|
|
||||||
|
var pushNotifier = SpecialPowers.Cc["@mozilla.org/push/Notifier;1"]
|
||||||
|
.getService(SpecialPowers.Ci.nsIPushNotifier);
|
||||||
|
|
||||||
|
var reporters = new Map();
|
||||||
|
|
||||||
|
var registration;
|
||||||
|
add_task(function* start() {
|
||||||
|
yield setupPrefsAndReplaceService({
|
||||||
|
reportDeliveryError(messageId, reason) {
|
||||||
|
ok(reporters.has(messageId),
|
||||||
|
'Unexpected error reported for message ' + messageId);
|
||||||
|
var resolve = reporters.get(messageId);
|
||||||
|
reporters.delete(messageId);
|
||||||
|
resolve(reason);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
yield setPushPermission(true);
|
||||||
|
|
||||||
|
var url = "error_worker.js" + "?" + (Math.random());
|
||||||
|
registration = yield navigator.serviceWorker.register(url, {scope: "."});
|
||||||
|
});
|
||||||
|
|
||||||
|
var controlledFrame;
|
||||||
|
add_task(function* createControlledIFrame() {
|
||||||
|
controlledFrame = yield injectControlledFrame();
|
||||||
|
});
|
||||||
|
|
||||||
|
var idCounter = 1;
|
||||||
|
function waitForDeliveryError(request) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
var data = new TextEncoder("utf-8").encode(JSON.stringify(request));
|
||||||
|
var principal = SpecialPowers.wrap(document).nodePrincipal;
|
||||||
|
|
||||||
|
let messageId = "message-" + (idCounter++);
|
||||||
|
reporters.set(messageId, resolve);
|
||||||
|
pushNotifier.notifyPushWithData(registration.scope, principal, messageId,
|
||||||
|
data.length, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(function* reportErrors() {
|
||||||
|
var reason = yield waitForDeliveryError({ type: "exception" });
|
||||||
|
is(reason, SpecialPowers.Ci.nsIPushErrorReporter.DELIVERY_UNCAUGHT_EXCEPTION,
|
||||||
|
"Should report uncaught exceptions");
|
||||||
|
|
||||||
|
reason = yield waitForDeliveryError({ type: "rejection" });
|
||||||
|
is(reason, SpecialPowers.Ci.nsIPushErrorReporter.DELIVERY_UNHANDLED_REJECTION,
|
||||||
|
"Should report unhandled rejections");
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* unsubscribe() {
|
||||||
|
controlledFrame.remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
add_task(function* unregister() {
|
||||||
|
yield registration.unregister();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -11,6 +11,9 @@
|
|||||||
*/
|
*/
|
||||||
function replacePushService(mockService) {
|
function replacePushService(mockService) {
|
||||||
chromeScript.sendSyncMessage("service-replace");
|
chromeScript.sendSyncMessage("service-replace");
|
||||||
|
chromeScript.addMessageListener("service-delivery-error", function(msg) {
|
||||||
|
mockService.reportDeliveryError(msg.messageId, msg.reason);
|
||||||
|
});
|
||||||
chromeScript.addMessageListener("service-request", function(msg) {
|
chromeScript.addMessageListener("service-request", function(msg) {
|
||||||
let promise;
|
let promise;
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user