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