Bug 1770237: Part 11 - Update push service test_handler_service.js to not use chrome manifests for component registration. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D148191
This commit is contained in:
Kris Maglione 2022-06-22 20:31:35 +00:00
parent 2c3055767b
commit d3a792ec5b
5 changed files with 27 additions and 51 deletions

View File

@ -1,33 +0,0 @@
// An XPCOM service that's registered with the category manager in the parent
// process for handling push notifications with scope "chrome://test-scope"
"use strict";
const { ComponentUtils } = ChromeUtils.import(
"resource://gre/modules/ComponentUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
let pushService = Cc["@mozilla.org/push/Service;1"].getService(
Ci.nsIPushService
);
function PushServiceHandler() {
// So JS code can reach into us.
this.wrappedJSObject = this;
// Register a push observer.
this.observed = [];
Services.obs.addObserver(this, pushService.pushTopic);
Services.obs.addObserver(this, pushService.subscriptionChangeTopic);
Services.obs.addObserver(this, pushService.subscriptionModifiedTopic);
}
PushServiceHandler.prototype = {
classID: Components.ID("{bb7c5199-c0f7-4976-9f6d-1306e32c5591}"),
QueryInterface: ChromeUtils.generateQI([]),
observe(subject, topic, data) {
this.observed.push({ subject, topic, data });
},
};
this.NSGetFactory = ComponentUtils.generateNSGetFactory([PushServiceHandler]);

View File

@ -1,4 +0,0 @@
component {bb7c5199-c0f7-4976-9f6d-1306e32c5591} PushServiceHandler.js
contract @mozilla.org/dom/push/test/PushServiceHandler;1 {bb7c5199-c0f7-4976-9f6d-1306e32c5591}
category push chrome://test-scope @mozilla.org/dom/push/test/PushServiceHandler;1

View File

@ -1,8 +1,3 @@
EXTRA_COMPONENTS += [
"PushServiceHandler.js",
"PushServiceHandler.manifest",
]
TESTING_JS_MODULES += [
"broadcast_handler.jsm",
]

View File

@ -4,27 +4,46 @@
// manager for push notifications against a specific scope, that service is
// instantiated before the message is delivered.
// This component is registered for "chrome://test-scope"
const kServiceContractID = "@mozilla.org/dom/push/test/PushServiceHandler;1";
const { MockRegistrar } = ChromeUtils.import(
"resource://testing-common/MockRegistrar.jsm"
);
let pushService = Cc["@mozilla.org/push/Service;1"].getService(
Ci.nsIPushService
);
add_test(function test_service_instantiation() {
do_load_manifest("PushServiceHandler.manifest");
function PushServiceHandler() {
// Register a push observer.
this.observed = [];
Services.obs.addObserver(this, pushService.pushTopic);
Services.obs.addObserver(this, pushService.subscriptionChangeTopic);
Services.obs.addObserver(this, pushService.subscriptionModifiedTopic);
}
PushServiceHandler.prototype = {
classID: Components.ID("{bb7c5199-c0f7-4976-9f6d-1306e32c5591}"),
QueryInterface: ChromeUtils.generateQI([]),
observe(subject, topic, data) {
this.observed.push({ subject, topic, data });
},
};
let handlerService = new PushServiceHandler();
add_test(function test_service_instantiation() {
const CONTRACT_ID = "@mozilla.org/dom/push/test/PushServiceHandler;1";
let scope = "chrome://test-scope";
MockRegistrar.register(CONTRACT_ID, handlerService);
Services.catMan.addCategoryEntry("push", scope, CONTRACT_ID, false, false);
let pushNotifier = Cc["@mozilla.org/push/Notifier;1"].getService(
Ci.nsIPushNotifier
);
let principal = Services.scriptSecurityManager.getSystemPrincipal();
pushNotifier.notifyPush(scope, principal, "");
// Now get a handle to our service and check it received the notification.
let handlerService = Cc[kServiceContractID].getService(Ci.nsISupports)
.wrappedJSObject;
equal(handlerService.observed.length, 1);
equal(handlerService.observed[0].topic, pushService.pushTopic);
let message = handlerService.observed[0].subject.QueryInterface(

View File

@ -11,7 +11,6 @@ support-files = broadcast_handler.jsm
[test_crypto_encrypt.js]
[test_drop_expired.js]
[test_handler_service.js]
support-files = PushServiceHandler.js PushServiceHandler.manifest
[test_notification_ack.js]
[test_notification_data.js]
[test_notification_duplicate.js]