Revision control
Copy as Markdown
Other Tools
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
/**
* Tests migrating virtualFolders.dat into the new database.
*/
const { ProfileCreator } = ChromeUtils.importESModule(
);
add_setup(async function () {
const profile = new ProfileCreator(do_get_profile());
const server = await profile.addLocalServer();
await server.rootFolder.addMailFolder("foo");
await server.rootFolder.addMailFolder("bar");
await profile.addFile(
"virtualFolders.dat",
`version=1
terms=ALL
searchOnline=false
terms=AND (subject,contains,test)
searchOnline=false
searchFolderFlag=1000
scope=*
terms=AND (tag,contains,$label1)
searchOnline=false
searchFolderFlag=100
terms=ALL
searchOnline=true
`
);
loadExistingDB();
MailServices.accounts.accounts;
});
add_task(async function () {
const rootFolder = MailServices.accounts.localFoldersServer.rootFolder;
Assert.deepEqual(rootFolder.subFolders.map(f => f.name).toSorted(), [
"Trash",
"Unsent Messages",
"all messages",
"bar",
"foo",
]);
const foo = rootFolder.getChildNamed("foo");
const bar = rootFolder.getChildNamed("bar");
// Check "all messages" is migrated correctly.
const allMessages = rootFolder.getChildNamed("all messages");
const allMessagesInfo = allMessages.msgDatabase.dBFolderInfo;
Assert.equal(
allMessages.flags,
Ci.nsMsgFolderFlags.Virtual | Ci.nsMsgFolderFlags.Mail
);
Assert.equal(allMessagesInfo.getCharProperty("searchStr"), "ALL");
Assert.ok(!allMessagesInfo.getBooleanProperty("searchOnline", true));
const allMessagesWrapper = Cc[
"@mozilla.org/mailnews/virtual-folder-wrapper;1"
].createInstance(Ci.nsIVirtualFolderWrapper);
allMessagesWrapper.virtualFolder = allMessages;
Assert.deepEqual(
allMessagesWrapper.searchFolderURIs,
);
Assert.deepEqual(allMessagesWrapper.searchFolders, [foo, bar]);
Assert.equal(allMessagesWrapper.searchString, "ALL");
Assert.equal(allMessagesWrapper.onlineSearch, false);
// Check "test" is migrated correctly.
const test = foo.getChildNamed("test");
const testInfo = test.msgDatabase.dBFolderInfo;
Assert.equal(
test.flags,
Ci.nsMsgFolderFlags.Virtual | Ci.nsMsgFolderFlags.Mail
);
Assert.equal(
testInfo.getCharProperty("searchStr"),
"AND (subject,contains,test)"
);
Assert.ok(!testInfo.getBooleanProperty("searchOnline", true));
const testWrapper = Cc[
"@mozilla.org/mailnews/virtual-folder-wrapper;1"
].createInstance(Ci.nsIVirtualFolderWrapper);
testWrapper.virtualFolder = test;
Assert.deepEqual(
testWrapper.searchFolderURIs,
);
Assert.deepEqual(testWrapper.searchFolders, [foo]);
Assert.equal(testWrapper.searchString, "AND (subject,contains,test)");
Assert.equal(testWrapper.onlineSearch, false);
// Check the database is populated correctly.
const allMessagesId = folders.getFolderByPath("server1/all messages").id;
checkRow(allMessagesId, {
id: allMessagesId,
parent: folders.getFolderByPath("server1").id,
ordinal: null,
name: "all messages",
flags: Ci.nsMsgFolderFlags.Virtual | Ci.nsMsgFolderFlags.Mail,
});
const testId = folders.getFolderByPath("server1/foo/test").id;
checkRow(testId, {
id: testId,
parent: folders.getFolderByPath("server1/foo").id,
ordinal: null,
name: "test",
flags: Ci.nsMsgFolderFlags.Virtual | Ci.nsMsgFolderFlags.Mail,
});
let stmt = database.connection.createStatement(
"SELECT id, name, value FROM folder_properties ORDER BY id, name"
);
let rows = [];
while (stmt.executeStep()) {
rows.push([stmt.row.id, stmt.row.name, stmt.row.value]);
}
stmt.finalize();
Assert.deepEqual(rows, [
[allMessagesId, "searchOnline", 0],
[allMessagesId, "searchStr", "ALL"],
[testId, "searchOnline", 0],
[testId, "searchStr", "AND (subject,contains,test)"],
]);
const fooId = folders.getFolderByPath("server1/foo").id;
const barId = folders.getFolderByPath("server1/bar").id;
stmt = database.connection.createStatement(
"SELECT virtualFolderId, searchFolderId FROM virtualFolder_folders ORDER BY virtualFolderId, searchFolderId"
);
rows = [];
while (stmt.executeStep()) {
rows.push([stmt.row.virtualFolderId, stmt.row.searchFolderId]);
}
stmt.finalize();
Assert.deepEqual(rows, [
[allMessagesId, Math.min(fooId, barId)],
[allMessagesId, Math.max(fooId, barId)],
[testId, fooId],
]);
});