зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1139254 - Use MockRegistrar in services. r=gps
This commit is contained in:
Родитель
2cb5a25170
Коммит
c06c81c0ef
|
@ -6,6 +6,7 @@ Cu.import("resource://gre/modules/Log.jsm");
|
|||
Cu.import("resource://services-common/utils.js");
|
||||
Cu.import("resource://testing-common/httpd.js");
|
||||
Cu.import("resource://testing-common/services/common/logging.js");
|
||||
Cu.import("resource://testing-common/MockRegistrar.jsm");
|
||||
|
||||
let btoa = Cu.import("resource://gre/modules/Log.jsm").btoa;
|
||||
let atob = Cu.import("resource://gre/modules/Log.jsm").atob;
|
||||
|
@ -134,22 +135,7 @@ function ensureThrows(func) {
|
|||
* Fake a PAC to prompt a channel replacement.
|
||||
*/
|
||||
let PACSystemSettings = {
|
||||
CID: Components.ID("{5645d2c1-d6d8-4091-b117-fe7ee4027db7}"),
|
||||
contractID: "@mozilla.org/system-proxy-settings;1",
|
||||
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
|
||||
Ci.nsISystemProxySettings]),
|
||||
|
||||
createInstance: function createInstance(outer, iid) {
|
||||
if (outer) {
|
||||
throw Cr.NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
return this.QueryInterface(iid);
|
||||
},
|
||||
|
||||
lockFactory: function lockFactory(lock) {
|
||||
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISystemProxySettings]),
|
||||
|
||||
// Replace this URI for each test to avoid caching. We want to ensure that
|
||||
// each test gets a completely fresh setup.
|
||||
|
@ -160,19 +146,16 @@ let PACSystemSettings = {
|
|||
}
|
||||
};
|
||||
|
||||
let fakePACCID;
|
||||
function installFakePAC() {
|
||||
_("Installing fake PAC.");
|
||||
Cm.nsIComponentRegistrar
|
||||
.registerFactory(PACSystemSettings.CID,
|
||||
"Fake system proxy-settings",
|
||||
PACSystemSettings.contractID,
|
||||
fakePACCID = MockRegistrar.register("@mozilla.org/system-proxy-settings;1",
|
||||
PACSystemSettings);
|
||||
}
|
||||
|
||||
function uninstallFakePAC() {
|
||||
_("Uninstalling fake PAC.");
|
||||
let CID = PACSystemSettings.CID;
|
||||
Cm.nsIComponentRegistrar.unregisterFactory(CID, PACSystemSettings);
|
||||
MockRegistrar.unregister(fakePACCID);
|
||||
}
|
||||
|
||||
// Many tests do service.startOver() and don't expect the provider type to
|
||||
|
|
|
@ -9,6 +9,7 @@ Cu.import("resource://gre/modules/FxAccounts.jsm");
|
|||
Cu.import("resource://gre/modules/FxAccountsCommon.js");
|
||||
Cu.import("resource://gre/modules/FxAccountsManager.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://testing-common/MockRegistrar.jsm");
|
||||
|
||||
// === Mocks ===
|
||||
|
||||
|
@ -22,20 +23,8 @@ let certExpired = false;
|
|||
// Mock RP
|
||||
let principal = {origin: 'app://settings.gaiamobile.org', appId: 27}
|
||||
|
||||
// Override FxAccountsUIGlue.
|
||||
const kFxAccountsUIGlueUUID = "{8f6d5d87-41ed-4bb5-aa28-625de57564c5}";
|
||||
const kFxAccountsUIGlueContractID =
|
||||
"@mozilla.org/fxaccounts/fxaccounts-ui-glue;1";
|
||||
|
||||
// Save original FxAccountsUIGlue factory.
|
||||
const kFxAccountsUIGlueFactory =
|
||||
Cm.getClassObject(Cc[kFxAccountsUIGlueContractID], Ci.nsIFactory);
|
||||
|
||||
let fakeFxAccountsUIGlueFactory = {
|
||||
createInstance: function(aOuter, aIid) {
|
||||
return FxAccountsUIGlue.QueryInterface(aIid);
|
||||
}
|
||||
};
|
||||
// For override FxAccountsUIGlue.
|
||||
let fakeFxAccountsUIGlueCID;
|
||||
|
||||
// FxAccountsUIGlue fake component.
|
||||
let FxAccountsUIGlue = {
|
||||
|
@ -91,11 +80,9 @@ let FxAccountsUIGlue = {
|
|||
};
|
||||
|
||||
(function registerFakeFxAccountsUIGlue() {
|
||||
Cm.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.registerFactory(Components.ID(kFxAccountsUIGlueUUID),
|
||||
"FxAccountsUIGlue",
|
||||
kFxAccountsUIGlueContractID,
|
||||
fakeFxAccountsUIGlueFactory);
|
||||
fakeFxAccountsUIGlueCID =
|
||||
MockRegistrar.register("@mozilla.org/fxaccounts/fxaccounts-ui-glue;1",
|
||||
FxAccountsUIGlue);
|
||||
})();
|
||||
|
||||
// Save original fxAccounts instance
|
||||
|
@ -246,16 +233,7 @@ FxAccountsManager._getFxAccountsClient = function() {
|
|||
// Unregister mocks and restore original code.
|
||||
do_register_cleanup(function() {
|
||||
// Unregister the factory so we do not leak
|
||||
Cm.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.unregisterFactory(Components.ID(kFxAccountsUIGlueUUID),
|
||||
fakeFxAccountsUIGlueFactory);
|
||||
|
||||
// Restore the original factory.
|
||||
Cm.QueryInterface(Ci.nsIComponentRegistrar)
|
||||
.registerFactory(Components.ID(kFxAccountsUIGlueUUID),
|
||||
"FxAccountsUIGlue",
|
||||
kFxAccountsUIGlueContractID,
|
||||
kFxAccountsUIGlueFactory);
|
||||
MockRegistrar.unregister(fakeFxAccountsUIGlueCID);
|
||||
|
||||
// Restore the original FxAccounts instance from FxAccountsManager.
|
||||
FxAccountsManager._fxAccounts = kFxAccounts;
|
||||
|
|
Загрузка…
Ссылка в новой задаче