Bug 463860 - "make gloda unit tests work again" [r=Standard8]
This commit is contained in:
Родитель
c003951690
Коммит
f7a4d38b4e
|
@ -47,8 +47,7 @@ DIRS = modules components
|
|||
#DIRS = components
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
#turn off tests for now
|
||||
#DIRS += test
|
||||
DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -38,6 +38,12 @@
|
|||
// -- Pull in the POP3 fake-server / local account helper code
|
||||
do_import_script("../mailnews/local/test/unit/head_maillocal.js");
|
||||
|
||||
// enable the gloda prefs
|
||||
const gPrefs = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefBranch);
|
||||
gPrefs.setBoolPref("mailnews.database.global.indexer.enabled", true);
|
||||
gPrefs.setBoolPref("mailnews.database.global.logging.dump", true);
|
||||
|
||||
// -- Import our modules
|
||||
Components.utils.import("resource://app/modules/gloda/public.js");
|
||||
Components.utils.import("resource://app/modules/gloda/indexer.js");
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
* - Full-text search. Happens in query testing.
|
||||
*/
|
||||
|
||||
do_import_script("../mailnews/db/global/test/resources/messageGenerator.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/messageGenerator.js");
|
||||
|
||||
//these are imported by glodaTestHelper's import of head_maillocal
|
||||
// do_import_script("../mailnews/test/resources/mailDirService.js");
|
||||
// do_import_script("../mailnews/test/resources/mailTestUtils.js");
|
||||
do_import_script("../mailnews/db/global/test/resources/glodaTestHelper.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/glodaTestHelper.js");
|
||||
|
||||
// Create a message generator
|
||||
var msgGen = new MessageGenerator();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
* are primarily concerned about memory utilization and processor load.
|
||||
*/
|
||||
|
||||
do_import_script("../mailnews/db/global/test/resources/messageGenerator.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/messageGenerator.js");
|
||||
|
||||
//these are imported by glodaTestHelper's import of head_maillocal
|
||||
// do_import_script("../mailnews/test/resources/mailDirService.js");
|
||||
// do_import_script("../mailnews/test/resources/mailTestUtils.js");
|
||||
do_import_script("../mailnews/db/global/test/resources/glodaTestHelper.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/glodaTestHelper.js");
|
||||
|
||||
// Create a message generator
|
||||
var msgGen = new MessageGenerator();
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/* This file tests our querying support, including full-text search.
|
||||
*/
|
||||
|
||||
do_import_script("../mailnews/db/global/test/resources/messageGenerator.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/messageGenerator.js");
|
||||
|
||||
//these are imported by glodaTestHelper's import of head_maillocal
|
||||
// do_import_script("../mailnews/test/resources/mailDirService.js");
|
||||
// do_import_script("../mailnews/test/resources/mailTestUtils.js");
|
||||
do_import_script("../mailnews/db/global/test/resources/glodaTestHelper.js");
|
||||
do_import_script("../mailnews/db/gloda/test/resources/glodaTestHelper.js");
|
||||
|
||||
// Create a message generator
|
||||
var msgGen = new MessageGenerator();
|
||||
|
|
|
@ -37,17 +37,29 @@ pop3Daemon.prototype = {
|
|||
_messages: null,
|
||||
_totalMessageSize: 0,
|
||||
|
||||
/**
|
||||
* Set the messages that the POP3 daemon will provide to its clients.
|
||||
*
|
||||
* @param messages An array of either 1) strings that are filenames whose
|
||||
* contents will be loaded from the files or 2) objects with a "fileData"
|
||||
* attribute whose value is the content of the file.
|
||||
*/
|
||||
setMessages: function(messages) {
|
||||
this._messages = [];
|
||||
this._totalMessageSize = 0;
|
||||
|
||||
function addMessage(element) {
|
||||
this._messages.push( { fileData: readFile(element), size: -1 });
|
||||
// if it's a string, then it's a file-name.
|
||||
if (typeof element == "string")
|
||||
this._messages.push( { fileData: readFile(element), size: -1 });
|
||||
// otherwise it's an object as dictionary already
|
||||
else
|
||||
this._messages.push(element);
|
||||
}
|
||||
messages.forEach(addMessage, this);
|
||||
|
||||
for (var i = 0; i < this._messages.length; ++i) {
|
||||
this._messages[i].size = this._messages[i].length;
|
||||
this._messages[i].size = this._messages[i].fileData.length;
|
||||
this._totalMessageSize += this._messages[i].size;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -53,11 +53,17 @@ function initializeDirServer() {
|
|||
processDir.append("mailtest");
|
||||
|
||||
return processDir;
|
||||
} else if (prop == "TmpD") {
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
} else {
|
||||
dump("Wants directory: "+prop+"\n");
|
||||
}
|
||||
if (prop == "resource:app") {
|
||||
// app should return the same as gre...
|
||||
return dirSvc.get("GreD", Ci.nsIFile);
|
||||
}
|
||||
if (prop == "TmpD") {
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
dump("Directory request for: " + prop + " that we (mailDirService.js)" +
|
||||
" are not handling, leaving it to another handler.\n");
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
},
|
||||
|
||||
|
@ -72,8 +78,9 @@ function initializeDirServer() {
|
|||
// If there's no location registered for the profile directory, register one
|
||||
var dirSvc = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIProperties);
|
||||
var profileDir;
|
||||
try {
|
||||
var profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
|
||||
profileDir = dirSvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
|
||||
} catch (e) { }
|
||||
|
||||
if (!profileDir) {
|
||||
|
|
|
@ -204,3 +204,53 @@ function loadFileToString(aFile, aCharset) {
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the given nsIMsgFolder's database is up-to-date, calling the provided
|
||||
* callback once the folder has been loaded. (This may be instantly or
|
||||
* after a re-parse.)
|
||||
*
|
||||
* @param aFolder The nsIMsgFolder whose database you want to ensure is
|
||||
* up-to-date.
|
||||
* @param aCallback The callback function to invoke once the folder has been
|
||||
* loaded.
|
||||
* @param aCallbackThis The 'this' to use when calling the callback. Pass null
|
||||
* if your callback does not rely on 'this'.
|
||||
* @param aCallbackArgs A list of arguments to pass to the callback via apply.
|
||||
* If you provide [1,2,3], we will effectively call:
|
||||
* aCallbackThis.aCallback(1,2,3);
|
||||
*/
|
||||
function updateFolderAndNotify(aFolder, aCallback, aCallbackThis,
|
||||
aCallbackArgs) {
|
||||
// register for the folder loaded notification ahead of time... even though
|
||||
// we may not need it...
|
||||
let mailSession = Cc["@mozilla.org/messenger/services/session;1"]
|
||||
.getService(Ci.nsIMsgMailSession);
|
||||
let atomService = Cc["@mozilla.org/atom-service;1"]
|
||||
.getService(Ci.nsIAtomService);
|
||||
let kFolderLoadedAtom = atomService.getAtom("FolderLoaded");
|
||||
|
||||
let folderListener = {
|
||||
OnItemEvent: function (aEventFolder, aEvent) {
|
||||
if (aEvent == kFolderLoadedAtom && aFolder.URI == aEventFolder.URI) {
|
||||
mailSession.RemoveFolderListener(this);
|
||||
aCallback.apply(aCallbackThis, aCallbackArgs);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mailSession.AddFolderListener(folderListener, Ci.nsIFolderListener.event);
|
||||
|
||||
let needToWait = false;
|
||||
try {
|
||||
aFolder.updateFolder(null);
|
||||
}
|
||||
catch (e if e.result == Cr.NS_ERROR_NOT_INITIALIZED) {
|
||||
needToWait = true;
|
||||
}
|
||||
|
||||
if (!needToWait) {
|
||||
mailSession.RemoveFolderListener(folderListener);
|
||||
aCallback.apply(aCallbackThis, aCallbackArgs);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче