Bug 786936 - Use MockFactory.js to register/unregister mocks. r=Standard8

This commit is contained in:
Hiroyuki Ikezoe 2014-01-06 09:31:04 -05:00
Родитель 41317f1e99
Коммит b5d2afc5d5
4 изменённых файлов: 18 добавлений и 97 удалений

Просмотреть файл

@ -5,6 +5,7 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource:///modules/activity/alertHook.js");
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://testing-common/mailnews/MockFactory.js");
alertHook.init();
// Replace the alerts service with our own. This will let us check if we're
@ -20,18 +21,6 @@ var mockAlertsService = {
}
};
var mockAlertsServiceFactory = {
createInstance: function(aOuter, aIID) {
if (aOuter != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
if (!aIID.equals(Ci.nsIAlertsService))
throw Cr.NS_ERROR_NO_INTERFACE;
return mockAlertsService;
}
};
var gMsgWindow = {};
var mailnewsURL = {
@ -45,10 +34,10 @@ var mailnewsURL = {
function run_test() {
// First register the mock alerts service
Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
.registerFactory(Components.ID("{1bda6c33-b089-43df-a8fd-111907d6385a}"),
"Mock Alerts Service", "@mozilla.org/alerts-service;1",
mockAlertsServiceFactory);
let uuid = MockFactory.register("@mozilla.org/alerts-service;1", mockAlertsService);
do_register_cleanup(function() {
MockFactory.unregister(uuid);
});
// Just text, no url or window => expect no error shown to user
gAlertShown = false;

Просмотреть файл

@ -1,7 +1,6 @@
const NS_LOCALFILEOUTPUTSTREAM_CONTRACTID = "@mozilla.org/network/file-output-stream;1";
const kRegistrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
Components.utils.import("resource:///modules/iteratorUtils.jsm");
Components.utils.import("resource://testing-common/mailnews/MockFactory.js");
load("../../../resources/logHelper.js");
load("../../../resources/asyncTestUtils.js");
@ -12,8 +11,6 @@ Services.prefs.setCharPref("mail.serverDefaultStoreContractID",
let gTargetFolder;
let gUuid;
let gOriginalCID =
Components.manager.contractIDToCID(NS_LOCALFILEOUTPUTSTREAM_CONTRACTID);
function LockedFileOutputStream() {
}
@ -26,35 +23,13 @@ LockedFileOutputStream.prototype = {
},
}
var FileOutputStreamFactory = {
createInstance: function(aOuter, aIid) {
if (aOuter)
do_throw(Cr.NS_ERROR_NO_AGGREGATION);
return new LockedFileOutputStream().QueryInterface(aIid);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
};
function setup_output_stream_stub() {
gUuid = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator)
.generateUUID()
.toString();
kRegistrar.registerFactory(Components.ID(gUuid),
"Stub for nsIFileOutputStream",
NS_LOCALFILEOUTPUTSTREAM_CONTRACTID,
FileOutputStreamFactory);
gUuid = MockFactory.register("@mozilla.org/network/file-output-stream;1",
LockedFileOutputStream);
}
function teardown_output_stream_stub() {
kRegistrar.unregisterFactory(Components.ID(gUuid),
FileOutputStreamFactory);
kRegistrar.registerFactory(gOriginalCID,
"",
NS_LOCALFILEOUTPUTSTREAM_CONTRACTID,
null);
MockFactory.unregister(gUuid);
}
function setup_target_folder() {

Просмотреть файл

@ -1,8 +1,5 @@
const CONTRACT_ID = "@mozilla.org/windows-registry-key;1";
const REGISTRAR = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
Components.utils.import("resource://testing-common/mailnews/MockFactory.js");
let gOriginalCID = Components.manager.contractIDToCID(CONTRACT_ID);
let gFactory;
let gUuid;
function MockWindowsRegKey(registryData) {
@ -64,38 +61,11 @@ MockWindowsRegKey.prototype = {
}
};
function MockWindowsRegFactory(registryData) {
this._registryData = registryData;
}
MockWindowsRegFactory.prototype = {
createInstance: function(aOuter, aIid) {
if (aOuter)
do_throw(Cr.NS_ERROR_NO_AGGREGATION);
let key = new MockWindowsRegKey(this._registryData);
return key.QueryInterface(aIid);
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
};
function setup_mock_registry(mockRegistry) {
gUuid = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator)
.generateUUID()
.toString();
gFactory = new MockWindowsRegFactory(mockRegistry);
REGISTRAR.registerFactory(Components.ID(gUuid),
"Mock Windows Registry Implementation",
CONTRACT_ID,
gFactory);
gUuid = MockFactory.register("@mozilla.org/windows-registry-key;1",
MockWindowsRegKey, mockRegistry);
}
function teardown_mock_registry() {
REGISTRAR.unregisterFactory(Components.ID(gUuid),
gFactory);
REGISTRAR.registerFactory(gOriginalCID,
"",
CONTRACT_ID,
null);
MockFactory.unregister(gUuid);
}

Просмотреть файл

@ -30,6 +30,7 @@
*/
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://testing-common/mailnews/MockFactory.js");
// Wrapper to the nsIPrompt interface.
// This allows the send code to attempt to display errors to the user without
@ -251,24 +252,10 @@ var alertUtilsWindowWatcher = {
function registerAlertTestUtils()
{
var WindowWatcherFactory = {
createInstance: function createInstance(outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return alertUtilsWindowWatcher.QueryInterface(iid);
}
};
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"),
"Fake Window Watcher",
"@mozilla.org/embedcomp/window-watcher;1",
WindowWatcherFactory);
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
.registerFactory(Components.ID("{4637b567-6e2d-4a24-9775-e8fc0fb159ba}"),
"Fake Prompt Service",
"@mozilla.org/embedcomp/prompt-service;1",
alertUtilsPromptService);
MockFactory.register("@mozilla.org/embedcomp/window-watcher;1",
alertUtilsWindowWatcher);
MockFactory.register("@mozilla.org/embedcomp/prompt-service;1",
alertUtilsPromptService);
}
// Dummy message window that ensures we get prompted for logins.