diff --git a/browser/base/content/sanitize.js b/browser/base/content/sanitize.js index 0930b739ce1..99d207176af 100644 --- a/browser/base/content/sanitize.js +++ b/browser/base/content/sanitize.js @@ -486,6 +486,11 @@ Sanitizer.prototype = { .getService(Ci.nsISiteSecurityService); sss.clearAll(); + // Clear all push notification subscriptions + var push = Cc["@mozilla.org/push/NotificationService;1"] + .getService(Ci.nsIPushNotificationService); + push.clearAll(); + TelemetryStopwatch.finish("FX_SANITIZE_SITESETTINGS"); }, diff --git a/dom/interfaces/push/nsIPushNotificationService.idl b/dom/interfaces/push/nsIPushNotificationService.idl index 7d5ca9f00d8..19619ce0f0a 100644 --- a/dom/interfaces/push/nsIPushNotificationService.idl +++ b/dom/interfaces/push/nsIPushNotificationService.idl @@ -11,7 +11,7 @@ * uses service workers to notify applications. This interface exists to allow * privileged code to receive messages without migrating to service workers. */ -[scriptable, uuid(32028e38-903b-4a64-a180-5857eb4cb3dd)] +[scriptable, uuid(3da6a16c-69f8-4843-9149-1e89d58a53e2)] interface nsIPushNotificationService : nsISupports { /** @@ -46,4 +46,9 @@ interface nsIPushNotificationService : nsISupports * given |scope|, or `null` if the |scope| does not have a subscription. */ jsval registration(in string scope); + + /** + * Clear all subscriptions + */ + jsval clearAll(); }; diff --git a/dom/push/PushNotificationService.js b/dom/push/PushNotificationService.js index 41084a93127..9229ef6c6bc 100644 --- a/dom/push/PushNotificationService.js +++ b/dom/push/PushNotificationService.js @@ -50,6 +50,10 @@ PushNotificationService.prototype = { return PushService._registration({scope}); }, + clearAll: function clearAll() { + return PushService._clearAll(); + }, + observe: function observe(subject, topic, data) { switch (topic) { case "app-startup": diff --git a/dom/push/PushService.jsm b/dom/push/PushService.jsm index c4d10a372fb..60ae0d4351d 100644 --- a/dom/push/PushService.jsm +++ b/dom/push/PushService.jsm @@ -135,6 +135,19 @@ this.PushDB.prototype = { ); }, + clearAll: function clear(aSuccessCb, aErrorCb) { + this.newTxn( + "readwrite", + kPUSHDB_STORE_NAME, + function (aTxn, aStore) { + debug("Going to clear all!"); + aStore.clear(); + }, + aSuccessCb, + aErrorCb + ); + }, + getByPushEndpoint: function(aPushEndpoint, aSuccessCb, aErrorCb) { debug("getByPushEndpoint()"); @@ -1627,6 +1640,13 @@ this.PushService = { ); }, + _clearAll: function _clearAll() { + return new Promise((resolve, reject) => { + this._db.clearAll(() => resolve(), + () => reject("Database error")); + }); + }, + /** * Called on message from the child process */ diff --git a/dom/push/test/xpcshell/test_clearAll_successful.js b/dom/push/test/xpcshell/test_clearAll_successful.js new file mode 100644 index 00000000000..bf16f6434c6 --- /dev/null +++ b/dom/push/test/xpcshell/test_clearAll_successful.js @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +'use strict'; + +const {PushDB, PushService} = serviceExports; + +const channelID = 'db0a7021-ec2d-4bd3-8802-7a6966f10ed8'; + +function run_test() { + do_get_profile(); + setPrefs(); + run_next_test(); +} + +add_task(function* test_unregister_success() { + let db = new PushDB(); + let promiseDB = promisifyDatabase(db); + do_register_cleanup(() => cleanupDatabase(db)); + yield promiseDB.put({ + channelID, + pushEndpoint: 'https://example.org/update/unregister-success', + scope: 'https://example.com/page/unregister-success', + version: 1 + }); + + let unregisterDefer = Promise.defer(); + PushService.init({ + networkInfo: new MockDesktopNetworkInfo(), + db, + makeWebSocket(uri) { + return new MockWebSocket(uri, { + onHello(request) { + this.serverSendMsg(JSON.stringify({ + messageType: 'hello', + status: 200, + uaid: 'fbe865a6-aeb8-446f-873c-aeebdb8d493c' + })); + } + }); + } + }); + + yield PushNotificationService.clearAll(); + let record = yield promiseDB.getByChannelID(channelID); + ok(!record, 'Unregister did not remove record'); +}); diff --git a/dom/push/test/xpcshell/xpcshell.ini b/dom/push/test/xpcshell/xpcshell.ini index a9cf90544ad..aa9d99a2b43 100644 --- a/dom/push/test/xpcshell/xpcshell.ini +++ b/dom/push/test/xpcshell/xpcshell.ini @@ -4,6 +4,8 @@ tail = # Push notifications and alarms are currently disabled on Android. skip-if = toolkit == 'android' +[test_clearAll_successful.js] +run-sequentially = This will delete all existing push subscritions. [test_notification_ack.js] [test_notification_duplicate.js] [test_notification_error.js]