зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1362816 - Prevent test_data_protocol_registration.js and test_no_remote_registration.js from overwriting previously registered factories. r=jmaher
This patch does two things. The first is that it fixes the two tests mentioned in the title by saving a previously registered XULAppInfoFactory, unregistering it, registering the new factory, and then at the end of the test re-registering the factory which was registered before the test started. The second thing this patch does is remove the skipping conditions for these two tests so we can run them on linux64-jsdcov. MozReview-Commit-ID: 71c1nrYvx1M --HG-- extra : rebase_source : 818fc5e7fff8ff9985e42835928f26fc13387788
This commit is contained in:
Родитель
f5f7370562
Коммит
eabeafee3d
|
@ -9,29 +9,67 @@ var manifests = [
|
|||
];
|
||||
registerManifests(manifests);
|
||||
|
||||
var XULAppInfoFactory = {
|
||||
// These two are used when we register all our factories (and unregister)
|
||||
CID: XULAPPINFO_CID,
|
||||
scheme: "XULAppInfo",
|
||||
contractID: XULAPPINFO_CONTRACTID,
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
function run_test()
|
||||
{
|
||||
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
|
||||
Components.utils.import("resource://testing-common/AppInfo.jsm", this);
|
||||
let XULAppInfo = newAppInfo({
|
||||
name: "XPCShell",
|
||||
ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
|
||||
version: "5",
|
||||
platformVersion: "1.9",
|
||||
});
|
||||
|
||||
let XULAppInfoFactory = {
|
||||
// These two are used when we register all our factories (and unregister)
|
||||
CID: uuidGenerator.generateUUID(),
|
||||
scheme: "XULAppInfo",
|
||||
contractID: XULAPPINFO_CONTRACTID,
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
// Add our XULAppInfo factory
|
||||
let factories = [XULAppInfoFactory];
|
||||
let old_factories = [];
|
||||
let old_factories_inds = [];
|
||||
|
||||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
|
||||
// Register our factories
|
||||
for (let i = 0; i < factories.length; i++) {
|
||||
let factory = factories[i];
|
||||
Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.registerFactory(factory.CID, "test-" + factory.scheme,
|
||||
factory.contractID, factory);
|
||||
|
||||
// Make sure the class ID has not already been registered
|
||||
if (!registrar.isCIDRegistered(factory.CID)) {
|
||||
|
||||
// Check to see if a contract was already registered and
|
||||
// register it if it is not. Otherwise, store the previous one
|
||||
// to be restored later and register the new one.
|
||||
if (registrar.isContractIDRegistered(factory.contractID)) {
|
||||
dump(factory.scheme + " is already registered. Storing currently registered object for restoration later.")
|
||||
old_factories.push({
|
||||
CID: registrar.contractIDToCID(factory.contractID),
|
||||
factory: Components.manager.getClassObject(Cc[factory.contractID], Ci.nsIFactory)
|
||||
});
|
||||
old_factories_inds.push(true);
|
||||
registrar.unregisterFactory(old_factories[i].CID, old_factories[i].factory);
|
||||
}
|
||||
else {
|
||||
dump(factory.scheme + " has never been registered. Registering...")
|
||||
old_factories.push({CID: "", factory: null});
|
||||
old_factories_inds.push(false);
|
||||
}
|
||||
|
||||
registrar.registerFactory(factory.CID, "test-" + factory.scheme, factory.contractID, factory);
|
||||
}
|
||||
else {
|
||||
do_throw("CID " + factory.CID + " has already been registered!");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for new chrome
|
||||
|
@ -59,7 +97,12 @@ function run_test()
|
|||
// Unregister our factories so we do not leak
|
||||
for (let i = 0; i < factories.length; i++) {
|
||||
let factory = factories[i];
|
||||
Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.unregisterFactory(factory.CID, factory);
|
||||
let ind = old_factories_inds[i];
|
||||
registrar.unregisterFactory(factory.CID, factory);
|
||||
|
||||
if (ind == true) {
|
||||
let old_factory = old_factories[i];
|
||||
registrar.registerFactory(old_factory.CID, factory.scheme, factory.contractID, old_factory.factory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,26 +11,6 @@ registerManifests(manifests);
|
|||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
Components.utils.import("resource://testing-common/AppInfo.jsm", this);
|
||||
var XULAppInfo = newAppInfo({
|
||||
name: "XPCShell",
|
||||
ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
|
||||
version: "5",
|
||||
platformVersion: "1.9",
|
||||
});
|
||||
|
||||
var XULAppInfoFactory = {
|
||||
// These two are used when we register all our factories (and unregister)
|
||||
CID: Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"),
|
||||
scheme: "XULAppInfo",
|
||||
contractID: "@mozilla.org/xre/app-info;1",
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
function ProtocolHandler(aScheme, aFlags)
|
||||
{
|
||||
this.scheme = aScheme;
|
||||
|
@ -90,6 +70,30 @@ var testProtocols = [
|
|||
];
|
||||
function run_test()
|
||||
{
|
||||
Components.utils.import("resource://testing-common/AppInfo.jsm", this);
|
||||
let XULAppInfo = newAppInfo({
|
||||
name: "XPCShell",
|
||||
ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
|
||||
version: "5",
|
||||
platformVersion: "1.9",
|
||||
});
|
||||
|
||||
const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
|
||||
let XULAppInfoFactory = {
|
||||
// These two are used when we register all our factories (and unregister)
|
||||
CID: uuidGenerator.generateUUID(),
|
||||
scheme: "XULAppInfo",
|
||||
contractID: "@mozilla.org/xre/app-info;1",
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
return XULAppInfo.QueryInterface(iid);
|
||||
}
|
||||
};
|
||||
|
||||
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||
|
||||
// Create factories
|
||||
let factories = [];
|
||||
for (let i = 0; i < testProtocols.length; i++) {
|
||||
|
@ -107,17 +111,38 @@ function run_test()
|
|||
}
|
||||
};
|
||||
}
|
||||
// Add our XULAppInfo factory
|
||||
factories.push(XULAppInfoFactory);
|
||||
|
||||
// Register our factories
|
||||
for (let i = 0; i < factories.length; i++) {
|
||||
let factory = factories[i];
|
||||
Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.registerFactory(factory.CID, "test-" + factory.scheme,
|
||||
registrar.registerFactory(factory.CID, "test-" + factory.scheme,
|
||||
factory.contractID, factory);
|
||||
}
|
||||
|
||||
// Register the XULAppInfoFactory
|
||||
// Make sure the class ID has not already been registered
|
||||
let old_factory = {CID: "", factory: null};
|
||||
if (!registrar.isCIDRegistered(XULAppInfoFactory.CID)) {
|
||||
|
||||
// Check to see if a contract was already registered and
|
||||
// register it if it is not. Otherwise, store the previous one
|
||||
// to be restored later and register the new one.
|
||||
if (registrar.isContractIDRegistered(XULAppInfoFactory.contractID)) {
|
||||
dump(XULAppInfoFactory.scheme + " is already registered. Storing currently registered object for restoration later.")
|
||||
old_factory.CID = registrar.contractIDToCID(XULAppInfoFactory.contractID);
|
||||
old_factory.factory = Components.manager.getClassObject(Cc[XULAppInfoFactory.contractID], Ci.nsIFactory);
|
||||
registrar.unregisterFactory(old_factory.CID, old_factory.factory);
|
||||
}
|
||||
else {
|
||||
dump(XULAppInfoFactory.scheme + " has never been registered. Registering...")
|
||||
}
|
||||
|
||||
registrar.registerFactory(XULAppInfoFactory.CID, "test-" + XULAppInfoFactory.scheme, XULAppInfoFactory.contractID, XULAppInfoFactory);
|
||||
}
|
||||
else {
|
||||
do_throw("CID " + XULAppInfoFactory.CID + " has already been registered!");
|
||||
}
|
||||
|
||||
// Check for new chrome
|
||||
let cr = Cc["@mozilla.org/chrome/chrome-registry;1"].
|
||||
getService(Ci.nsIChromeRegistry);
|
||||
|
@ -196,7 +221,12 @@ function run_test()
|
|||
// Unregister our factories so we do not leak
|
||||
for (let i = 0; i < factories.length; i++) {
|
||||
let factory = factories[i];
|
||||
Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.unregisterFactory(factory.CID, factory);
|
||||
registrar.unregisterFactory(factory.CID, factory);
|
||||
}
|
||||
|
||||
// Unregister XULAppInfoFactory
|
||||
registrar.unregisterFactory(XULAppInfoFactory.CID, XULAppInfoFactory);
|
||||
if (old_factory.factory != null) {
|
||||
registrar.registerFactory(old_factory.CID, "", XULAppInfoFactory.contractID, old_factory.factory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,5 @@ tags = addons
|
|||
[test_bug848297.js]
|
||||
[test_crlf.js]
|
||||
[test_data_protocol_registration.js]
|
||||
skip-if = coverage # bug 1362816
|
||||
[test_no_remote_registration.js]
|
||||
skip-if = coverage # bug 1362816
|
||||
[test_resolve_uris.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче