Bug 852690 - Remaining conversion to mailServices.js: news. r=jcranmer

This commit is contained in:
Sebastian Hengst 2013-03-25 19:48:49 +01:00
Родитель f1a36776e6
Коммит 3b65a54d6f
10 изменённых файлов: 37 добавлений и 53 удалений

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

@ -110,14 +110,12 @@ function subscribeServer(incomingServer) {
function setupLocalServer(port) {
if (_server != null)
return _server;
var acctmgr = Cc["@mozilla.org/messenger/account-manager;1"]
.getService(Ci.nsIMsgAccountManager);
var server = acctmgr.createIncomingServer(null, "localhost", "nntp");
var server = MailServices.accounts.createIncomingServer(null, "localhost", "nntp");
server.port = port;
server.valid = false;
var account = acctmgr.createAccount();
var account = MailServices.accounts.createAccount();
account.incomingServer = server;
server.valid = true;
@ -128,9 +126,7 @@ function setupLocalServer(port) {
return server;
}
const URLCreator = Cc["@mozilla.org/messenger/messageservice;1?type=news"]
.getService(Ci.nsINntpService)
.QueryInterface(Ci.nsIProtocolHandler);
const URLCreator = MailServices.nntp.QueryInterface(Ci.nsIProtocolHandler);
function create_post(baseURL, file) {
var url = URLCreator.newURI(baseURL, null, null);

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

@ -6,6 +6,8 @@ load("../../../fakeserver/nntpd.js");
load("../../../resources/mailDirService.js");
load("../../../resources/mailTestUtils.js");
Components.utils.import("resource:///modules/mailServices.js");
const kSimpleNewsArticle =
"From: John Doe <john.doe@example.com>\n"+
"Date: Sat, 24 Mar 1990 10:59:24 -0500\n"+
@ -108,9 +110,7 @@ function setupLocalServer(port) {
return server;
}
const URLCreator = Cc["@mozilla.org/messenger/messageservice;1?type=news"]
.getService(Ci.nsINntpService)
.QueryInterface(Ci.nsIProtocolHandler);
const URLCreator = MailServices.nntp.QueryInterface(Ci.nsIProtocolHandler);
// Sets up a protocol object and prepares to run the test for the news url
function setupProtocolTest(port, newsUrl, incomingServer) {

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

@ -3,6 +3,8 @@
load("../../../resources/filterTestUtils.js");
Components.utils.import("resource:///modules/mailServices.js");
function run_test() {
// Set up the server and add in filters
let daemon = setupNNTPDaemon();
@ -29,16 +31,14 @@ function run_test() {
// for biff. Instead, we use the notifier to look for all 7 messages to be
// added and take that as our sign that the download is finished.
let expectCount = 7, seen = 0;
let notifier = Cc["@mozilla.org/messenger/msgnotificationservice;1"]
.getService(Ci.nsIMsgFolderNotificationService);
let listener = { msgAdded: function() {
if (++seen == expectCount)
localserver.closeCachedConnections();
}};
notifier.addListener(listener, Ci.nsIMsgFolderNotificationService.msgAdded);
MailServices.mfn.addListener(listener, Ci.nsIMsgFolderNotificationService.msgAdded);
localserver.performBiff(null);
server.performTest();
notifier.removeListener(listener);
MailServices.mfn.removeListener(listener);
// We marked, via our filters, one of the messages read. So if we do not
// have 1 read message, either we're not running the filters on biff, or the

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

@ -1,5 +1,6 @@
// Bug 37465 -- assertions with no accounts
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function run_test() {
@ -30,8 +31,6 @@ function run_test() {
daemon.getArticle("<1@regular.invalid>").fullText);
// Shut down connections
var acctMgr = Cc['@mozilla.org/messenger/account-manager;1']
.getService(Ci.nsIMsgAccountManager);
acctMgr.closeCachedConnections();
MailServices.accounts.closeCachedConnections();
server.stop();
}

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

@ -19,6 +19,7 @@ load("../../../resources/logHelper.js");
load("../../../resources/asyncTestUtils.js");
load("../../../resources/alertTestUtils.js");
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var daemon, localserver, server;
@ -76,9 +77,7 @@ function trigger_bug() {
},
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFolderListener])
};
let mailSession = Cc["@mozilla.org/messenger/services/session;1"]
.getService(Ci.nsIMsgMailSession);
mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
MailServices.mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
// Again, two things will need to be listened for
yield false;
yield false;

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

@ -6,6 +6,7 @@ load("../../../resources/logHelper.js");
load("../../../resources/asyncTestUtils.js");
load("../../../resources/alertTestUtils.js");
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
let dummyMsgWindow = {
@ -26,9 +27,6 @@ let dummyMsgWindow = {
};
var daemon, localserver, server;
var nntpService = Cc["@mozilla.org/messenger/nntpservice;1"]
.getService(Components.interfaces.nsINntpService);
let tests = [
test_newMsgs,
test_cancel,
@ -60,19 +58,17 @@ function test_cancel() {
let db = folder.msgDatabase;
let hdr = db.GetMsgHdrForKey(4);
let mailSession = Cc['@mozilla.org/messenger/services/session;1']
.getService(Ci.nsIMsgMailSession);
let atomService = Cc['@mozilla.org/atom-service;1']
.getService(Ci.nsIAtomService);
let kDeleteAtom = atomService.getAtom("DeleteOrMoveMsgCompleted");
let folderListener = {
OnItemEvent: function(aEventFolder, aEvent) {
if (aEvent == kDeleteAtom) {
mailSession.RemoveFolderListener(this);
MailServices.mailSession.RemoveFolderListener(this);
}
}
};
mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
MailServices.mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
folder.QueryInterface(Ci.nsIMsgNewsFolder)
.cancelMessage(hdr, dummyMsgWindow);
yield false;
@ -95,7 +91,7 @@ function test_fetchMessage() {
Ci.nsIRequestObserver])
};
let folder = localserver.rootFolder.getChildNamed("test.filter");
nntpService.fetchMessage(folder, 2, null, streamlistener, asyncUrlListener);
MailServices.nntp.fetchMessage(folder, 2, null, streamlistener, asyncUrlListener);
yield false;
do_check_eq(statuscode, Components.results.NS_OK);
yield true;
@ -158,7 +154,7 @@ function test_grouplist() {
return groups;
}
nntpService.getListOfGroupsOnServer(localserver, null, false);
MailServices.nntp.getListOfGroupsOnServer(localserver, null, false);
yield false;
let groups = enumGroups("");
@ -169,7 +165,7 @@ function test_grouplist() {
function test_postMessage() {
// This tests nsNntpService::SetUpNntpUrlForPosting via PostMessage
nntpService.postMessage(do_get_file("postings/post2.eml"), "misc.test",
MailServices.nntp.postMessage(do_get_file("postings/post2.eml"), "misc.test",
localserver.key, asyncUrlListener, null);
yield false;
do_check_eq(daemon.getGroup("misc.test").keys.length, 1);
@ -179,11 +175,9 @@ function test_postMessage() {
// Not tested because it requires UI, and this is insufficient, I think.
function test_forwardInline() {
// This tests mime_parse_stream_complete via forwarding inline
let composeSvc = Cc['@mozilla.org/messengercompose;1']
.getService(Ci.nsIMsgComposeService);
let folder = localserver.rootFolder.getChildNamed("test.filter");
let hdr = folder.msgDatabase.GetMsgHdrForKey(1);
composeSvc.forwardMessage("a@b.invalid", hdr, null,
MailServices.compose.forwardMessage("a@b.invalid", hdr, null,
localserver, Ci.nsIMsgComposeService.kForwardInline);
}
@ -213,7 +207,7 @@ function test_escapedName() {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener,
Ci.nsIRequestObserver])
};
nntpService.fetchMessage(folder, 1, null, streamlistener, asyncUrlListener);
MailServices.nntp.fetchMessage(folder, 1, null, streamlistener, asyncUrlListener);
yield false;
do_check_eq(statuscode, Components.results.NS_OK);
yield true;
@ -227,12 +221,10 @@ function run_test() {
server.setDebugLevel(fsDebugAll);
// Set up an identity for posting
var acctmgr = Cc["@mozilla.org/messenger/account-manager;1"]
.getService(Ci.nsIMsgAccountManager);
let identity = acctmgr.createIdentity();
let identity = MailServices.accounts.createIdentity();
identity.fullName = "Normal Person";
identity.email = "fake@acme.invalid";
acctmgr.FindAccountForServer(localserver).addIdentity(identity);
MailServices.accounts.FindAccountForServer(localserver).addIdentity(identity);
async_run_tests(tests);
}

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

@ -7,6 +7,8 @@
* default port or the SSL default port. Nothing else!
*/
Components.utils.import("resource:///modules/mailServices.js");
// The basic daemon to use for testing nntpd.js implementations
var daemon = setupNNTPDaemon();
@ -69,13 +71,10 @@ function run_test() {
test = "news:*";
// Get the existing incoming server
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
.getService(Ci.nsIMsgAccountManager);
acctMgr.LoadAccounts();
MailServices.accounts.LoadAccounts();
// Create the incoming server with "original" details.
var incomingServer = acctMgr.getIncomingServer("server2");
var incomingServer = MailServices.accounts.getIncomingServer("server2");
subscribeServer(incomingServer);

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

@ -5,6 +5,7 @@
load("../../../resources/mailTestUtils.js");
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource://gre/modules/Services.jsm");
const kUsername = "testnews";
@ -24,11 +25,8 @@ function run_test()
// Set up the basic accounts and folders.
loadLocalMailAccount();
var acctMgr = Cc["@mozilla.org/messenger/account-manager;1"]
.getService(Ci.nsIMsgAccountManager);
var incomingServer = acctMgr.createIncomingServer(null, kHostname,
kProtocol);
var incomingServer = MailServices.accounts.createIncomingServer(null, kHostname,
kProtocol);
// Force move to new credentials
incomingServer.rootFolder.QueryInterface(Ci.nsIMsgNewsFolder)

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

@ -1,6 +1,8 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
// Tests that the news can correctly post messages
Components.utils.import("resource:///modules/mailServices.js");
function run_test() {
var daemon = setupNNTPDaemon();
var localserver = setupLocalServer(NNTP_PORT);
@ -16,9 +18,7 @@ function run_test() {
server.start(NNTP_PORT);
try {
var nntpService = Cc["@mozilla.org/messenger/nntpservice;1"]
.getService(Ci.nsINntpService);
nntpService.postMessage(do_get_file("postings/post1.eml"), "test.empty",
MailServices.nntp.postMessage(do_get_file("postings/post1.eml"), "test.empty",
localserver.key, listener, null);
server.performTest();
server.stop();

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

@ -6,9 +6,10 @@
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource:///modules/mailServices.js");
function getMessageHeaderFromUrl(aUrl) {
let msgUrl = Cc["@mozilla.org/messenger/messageservice;1?type=news"]
.getService(Ci.nsINntpService)
let msgUrl = MailServices.nntp
.QueryInterface(Ci.nsIProtocolHandler)
.newURI(aUrl, null, null)
.QueryInterface(Ci.nsIMsgMessageUrl);