Backed out 2 changesets (bug 1581765) for Xpcshell failures on Windows. a=backout DONTBUILD
Backed out changeset 72b1cec1260e (bug 1581765) Backed out changeset f8e09ea17f2a (bug 1581765)
This commit is contained in:
Родитель
823abcb520
Коммит
6c35d7efb9
|
@ -11,11 +11,6 @@
|
|||
|
||||
var EXPORTED_SYMBOLS = ["MailMigrator"];
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"AddrBookDirectory",
|
||||
"resource:///modules/AddrBookDirectory.jsm"
|
||||
);
|
||||
const { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
@ -680,130 +675,29 @@ var MailMigrator = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Migrate address books from Mork to JS/SQLite. This must happen before
|
||||
* address book start-up and without causing it.
|
||||
*
|
||||
* All Mork address books found in the prefs are converted to JS/SQLite
|
||||
* address books and the prefs updated. Migrated Mork files in the profile
|
||||
* are renamed with the extension ".mab.bak" to avoid confusion.
|
||||
* Migrate address books away from Mork. In time this will do actual
|
||||
* migration, but for now, just set the default pref back to what it was.
|
||||
*/
|
||||
_migrateAddressBooks() {
|
||||
function migrateBook(fileName, notFoundThrows = true) {
|
||||
let oldFile = profileDir.clone();
|
||||
oldFile.append(`${fileName}.mab`);
|
||||
if (!oldFile.exists()) {
|
||||
if (notFoundThrows) {
|
||||
throw Cr.NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Creating new ${fileName}.sqlite`);
|
||||
let newBook = new AddrBookDirectory();
|
||||
newBook.init(`jsaddrbook://${fileName}.sqlite`);
|
||||
|
||||
let database = Cc[
|
||||
"@mozilla.org/addressbook/carddatabase;1"
|
||||
].createInstance(Ci.nsIAddrDatabase);
|
||||
database.dbPath = oldFile;
|
||||
database.openMDB(oldFile, false);
|
||||
|
||||
let directory = Cc[
|
||||
"@mozilla.org/addressbook/directory;1?type=moz-abmdbdirectory"
|
||||
].createInstance(Ci.nsIAbMDBDirectory);
|
||||
|
||||
let cardMap = new Map();
|
||||
for (let card of database.enumerateCards(directory)) {
|
||||
if (!card.isMailList) {
|
||||
newBook.addCard(card);
|
||||
cardMap.set(card.localId, card);
|
||||
}
|
||||
}
|
||||
|
||||
for (let card of database.enumerateCards(directory)) {
|
||||
if (card.isMailList) {
|
||||
let mailList = Cc[
|
||||
"@mozilla.org/addressbook/directoryproperty;1"
|
||||
].createInstance(Ci.nsIAbDirectory);
|
||||
mailList.isMailList = true;
|
||||
mailList.dirName = card.displayName;
|
||||
mailList.listNickName = card.getProperty("NickName", "");
|
||||
mailList.description = card.getProperty("Notes", "");
|
||||
mailList = newBook.addMailList(mailList);
|
||||
|
||||
directory.dbRowID = card.localId;
|
||||
for (let listCard of database.enumerateListAddresses(directory)) {
|
||||
mailList.addCard(
|
||||
cardMap.get(listCard.QueryInterface(Ci.nsIAbCard).localId)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
database.closeMDB(false);
|
||||
|
||||
console.log(`Renaming ${fileName}.mab to ${fileName}.mab.bak`);
|
||||
oldFile.renameTo(profileDir, `${fileName}.mab.bak`);
|
||||
}
|
||||
|
||||
let profileDir = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
for (let name of Services.prefs.getChildList("ldap_2.servers.")) {
|
||||
try {
|
||||
if (
|
||||
!name.endsWith(".dirType") ||
|
||||
Services.prefs.getIntPref(name) != 2
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let prefName = name.substring(0, name.length - 8);
|
||||
let fileName = Services.prefs.getStringPref(`${prefName}.filename`);
|
||||
fileName = fileName.replace(/\.mab$/, "");
|
||||
|
||||
Services.prefs.setIntPref(`${prefName}.dirType`, 101);
|
||||
Services.prefs.setStringPref(
|
||||
`${prefName}.filename`,
|
||||
`${fileName}.sqlite`
|
||||
);
|
||||
if (Services.prefs.prefHasUserValue(`${prefName}.uri`)) {
|
||||
Services.prefs.setStringPref(
|
||||
`${prefName}.uri`,
|
||||
`jsaddrbook://${fileName}.sqlite`
|
||||
);
|
||||
}
|
||||
migrateBook(fileName);
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
migrateBook("abook", false);
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
try {
|
||||
migrateBook("history", false);
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
|
||||
for (let prefName of [
|
||||
"mail.collect_addressbook",
|
||||
"mail.server.default.whiteListAbURI",
|
||||
]) {
|
||||
try {
|
||||
if (Services.prefs.prefHasUserValue(prefName)) {
|
||||
let uri = Services.prefs.getStringPref(prefName);
|
||||
uri = uri.replace(
|
||||
/^moz-abmdbdirectory:\/\/(.*).mab$/,
|
||||
"jsaddrbook://$1.sqlite"
|
||||
);
|
||||
Services.prefs.setStringPref(prefName, uri);
|
||||
}
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
let pab = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
||||
pab.append("abook.mab");
|
||||
if (pab.exists()) {
|
||||
let defaultBranch = Services.prefs.getDefaultBranch("");
|
||||
defaultBranch.setIntPref("ldap_2.servers.pab.dirType", 2);
|
||||
defaultBranch.setStringPref("ldap_2.servers.pab.filename", "abook.mab");
|
||||
defaultBranch.setIntPref("ldap_2.servers.history.dirType", 2);
|
||||
defaultBranch.setStringPref(
|
||||
"ldap_2.servers.history.filename",
|
||||
"history.mab"
|
||||
);
|
||||
defaultBranch.setStringPref(
|
||||
"mail.collect_addressbook",
|
||||
"moz-abmdbdirectory://history.mab"
|
||||
);
|
||||
defaultBranch.setStringPref(
|
||||
"mail.server.default.whiteListAbURI",
|
||||
"moz-abmdbdirectory://abook.mab"
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -667,19 +667,6 @@ var bookPrototype = {
|
|||
insertStatement.finalize();
|
||||
|
||||
for (let { name, value } of fixIterator(card.properties, Ci.nsIProperty)) {
|
||||
if (
|
||||
[
|
||||
"DbRowID",
|
||||
"LowercasePrimaryEmail",
|
||||
"LowercaseSecondEmail",
|
||||
"RecordKey",
|
||||
"UID",
|
||||
].includes(name)
|
||||
) {
|
||||
// These properties are either stored elsewhere (DbRowID, UID), or no
|
||||
// longer needed. Don't store them.
|
||||
continue;
|
||||
}
|
||||
newCard.setProperty(name, value);
|
||||
}
|
||||
this._saveCardProperties(newCard);
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/* 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
|
||||
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var { MailMigrator } = ChromeUtils.import(
|
||||
"resource:///modules/MailMigrator.jsm"
|
||||
);
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
|
||||
// Ensure the profile directory is set up
|
||||
var profileDir = do_get_profile();
|
||||
|
||||
// OSX Address Book deactivation (Bug 955842)
|
||||
Services.prefs.deleteBranch("ldap_2.servers.osx.");
|
||||
|
||||
registerCleanupFunction(function() {
|
||||
load("../../../resources/mailShutdown.js");
|
||||
});
|
||||
|
||||
/**
|
||||
* Copies a file into the profile directory.
|
||||
*
|
||||
* @param {String} path Path to the source data
|
||||
* @param {String} leafName Final file name in the profile
|
||||
*/
|
||||
function copyABFile(path, leafName) {
|
||||
let file = do_get_file(path);
|
||||
file.copyTo(profileDir, leafName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that a file exists or doesn't exist in the profile directory.
|
||||
*
|
||||
* @param {String} leafName File name that should be checked
|
||||
* @param {boolean} shouldExist Whether the file should exist
|
||||
*/
|
||||
function checkFileExists(leafName, shouldExist) {
|
||||
let file = profileDir.clone();
|
||||
file.append(leafName);
|
||||
equal(file.exists(), shouldExist);
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/* 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
|
||||
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Test auto-migration from Mork address books to JS/SQLite address books.
|
||||
*
|
||||
* This test profile has only the two default address books to migrate, and
|
||||
* neither have any mailing lists.
|
||||
*/
|
||||
function run_test() {
|
||||
// Copy address books to be migrated into the profile.
|
||||
|
||||
copyABFile("data/cardForEmail.mab", "abook.mab");
|
||||
copyABFile("data/collect.mab", "history.mab");
|
||||
|
||||
// Do the migration.
|
||||
|
||||
MailMigrator._migrateAddressBooks();
|
||||
|
||||
// Check new files have been created, and old ones renamed.
|
||||
|
||||
checkFileExists("abook.sqlite", true);
|
||||
checkFileExists("abook.mab", false);
|
||||
checkFileExists("abook.mab.bak", true);
|
||||
checkFileExists("history.sqlite", true);
|
||||
checkFileExists("history.mab", false);
|
||||
checkFileExists("history.mab.bak", true);
|
||||
|
||||
// Check that the default preferences are untouched.
|
||||
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.pab.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.pab.filename"),
|
||||
"abook.sqlite"
|
||||
);
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.history.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.history.filename"),
|
||||
"history.sqlite"
|
||||
);
|
||||
|
||||
// Check the new address books.
|
||||
|
||||
let directories = [...MailServices.ab.directories];
|
||||
equal(directories.length, 2);
|
||||
equal(directories[0].dirType, 101);
|
||||
equal(directories[1].dirType, 101);
|
||||
|
||||
let [personalBook, historyBook] = directories;
|
||||
|
||||
// For this directory, just check we have all the right cards.
|
||||
|
||||
let personalCards = [...personalBook.childCards];
|
||||
equal(personalCards.length, 4);
|
||||
Assert.deepEqual(personalCards.map(card => card.displayName).sort(), [
|
||||
"DisplayName1",
|
||||
"Empty Email",
|
||||
"Jane Doe",
|
||||
"John Doe",
|
||||
]);
|
||||
|
||||
let personalLists = [...personalBook.addressLists.enumerate()];
|
||||
equal(personalLists.length, 0);
|
||||
|
||||
// More detailed check.
|
||||
|
||||
let historyCards = [...historyBook.childCards];
|
||||
equal(historyCards.length, 1);
|
||||
equal(historyCards[0].firstName, "Other");
|
||||
equal(historyCards[0].lastName, "Book");
|
||||
equal(historyCards[0].primaryEmail, "other@book.invalid");
|
||||
equal(historyCards[0].displayName, "Other Book");
|
||||
equal(historyCards[0].getProperty("LastModifiedDate", "bad"), "0");
|
||||
equal(historyCards[0].getProperty("AllowRemoteContent", "bad"), "0");
|
||||
equal(historyCards[0].getProperty("PopularityIndex", "bad"), "0");
|
||||
equal(historyCards[0].getProperty("PreferMailFormat", "bad"), "0");
|
||||
// This property exists in the .mab file but should not be copied to the
|
||||
// .sqlite file. It's not wrong, but we don't use them any more.
|
||||
equal(historyCards[0].getProperty("LowercasePrimaryEmail", "bad"), "bad");
|
||||
|
||||
let historyLists = [...historyBook.addressLists.enumerate()];
|
||||
equal(historyLists.length, 0);
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/* 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
|
||||
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Test auto-migration from Mork address books to JS/SQLite address books.
|
||||
*
|
||||
* This test profile has a personal address book with contacts and mailing
|
||||
* lists. The history book doesn't exist, which is unusual but still
|
||||
* shouldn't cause any problems.
|
||||
*/
|
||||
|
||||
const { fixIterator } = ChromeUtils.import(
|
||||
"resource:///modules/iteratorUtils.jsm"
|
||||
);
|
||||
|
||||
function run_test() {
|
||||
// Copy address book to be migrated into the profile.
|
||||
|
||||
copyABFile("../../../data/abLists1.mab", "abook.mab");
|
||||
|
||||
// Do the migration.
|
||||
|
||||
MailMigrator._migrateAddressBooks();
|
||||
|
||||
// Check new files have been created, and old ones renamed.
|
||||
|
||||
checkFileExists("abook.sqlite", true);
|
||||
checkFileExists("abook.mab", false);
|
||||
checkFileExists("abook.mab.bak", true);
|
||||
checkFileExists("history.sqlite", true);
|
||||
checkFileExists("history.mab", false);
|
||||
checkFileExists("history.mab.bak", false);
|
||||
|
||||
// Check that the default preferences are untouched.
|
||||
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.pab.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.pab.filename"),
|
||||
"abook.sqlite"
|
||||
);
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.history.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.history.filename"),
|
||||
"history.sqlite"
|
||||
);
|
||||
|
||||
// Check the new address books.
|
||||
|
||||
let directories = [...MailServices.ab.directories];
|
||||
equal(directories.length, 2);
|
||||
equal(directories[0].dirType, 101);
|
||||
equal(directories[1].dirType, 101);
|
||||
|
||||
let [personalBook, historyBook] = directories;
|
||||
|
||||
// Check we have all the right cards.
|
||||
|
||||
let personalCards = [...personalBook.childCards];
|
||||
equal(personalCards.length, 8);
|
||||
|
||||
let lists = personalCards.slice(0, 3);
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
ok(lists[i].isMailList);
|
||||
equal(lists[i].displayName, `TestList${i + 1}`);
|
||||
equal(lists[i].getProperty("NickName", "bad"), "");
|
||||
equal(lists[i].getProperty("Notes", "bad"), "");
|
||||
}
|
||||
|
||||
let contacts = personalCards.slice(3);
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
ok(!contacts[i].isMailList);
|
||||
equal(contacts[i].primaryEmail, `test${i + 1}@foo.invalid`);
|
||||
}
|
||||
|
||||
// Check the lists have the right members.
|
||||
|
||||
let personalLists = [
|
||||
...fixIterator(personalBook.addressLists.enumerate(), Ci.nsIAbDirectory),
|
||||
];
|
||||
equal(personalLists.length, 3);
|
||||
|
||||
let listCards = [
|
||||
...fixIterator(personalLists[0].addressLists.enumerate(), Ci.nsIAbCard),
|
||||
].map(c => c.primaryEmail);
|
||||
Assert.deepEqual(listCards, [
|
||||
"test1@foo.invalid",
|
||||
"test2@foo.invalid",
|
||||
"test3@foo.invalid",
|
||||
]);
|
||||
|
||||
listCards = [
|
||||
...fixIterator(personalLists[1].addressLists.enumerate(), Ci.nsIAbCard),
|
||||
].map(c => c.primaryEmail);
|
||||
Assert.deepEqual(listCards, ["test4@foo.invalid"]);
|
||||
|
||||
listCards = [
|
||||
...fixIterator(personalLists[2].addressLists.enumerate(), Ci.nsIAbCard),
|
||||
].map(c => c.primaryEmail);
|
||||
Assert.deepEqual(listCards, ["test5@foo.invalid"]);
|
||||
|
||||
// Check the history book, which should be empty.
|
||||
|
||||
let historyCards = [...historyBook.childCards];
|
||||
equal(historyCards.length, 0);
|
||||
|
||||
let historyLists = [...historyBook.addressLists.enumerate()];
|
||||
equal(historyLists.length, 0);
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
/* 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
|
||||
* file, you can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
/*
|
||||
* Test auto-migration from Mork address books to JS/SQLite address books.
|
||||
*
|
||||
* This test profile has a non-default Mork address book, and no default
|
||||
* address books.
|
||||
*/
|
||||
|
||||
const { fixIterator } = ChromeUtils.import(
|
||||
"resource:///modules/iteratorUtils.jsm"
|
||||
);
|
||||
|
||||
function run_test() {
|
||||
// Copy address book to be migrated into the profile.
|
||||
|
||||
copyABFile("data/existing.mab", "test.mab");
|
||||
|
||||
Services.prefs.setStringPref(
|
||||
"ldap_2.servers.Test.description",
|
||||
"This is a test!"
|
||||
);
|
||||
Services.prefs.setIntPref("ldap_2.servers.Test.dirType", 2);
|
||||
Services.prefs.setStringPref("ldap_2.servers.Test.filename", "test.mab");
|
||||
Services.prefs.setStringPref(
|
||||
"ldap_2.servers.Test.uid",
|
||||
"12345678-1234-1234-1234-123456789012"
|
||||
);
|
||||
Services.prefs.setStringPref(
|
||||
"ldap_2.servers.Test.uri",
|
||||
"moz-abmdbdirectory://test.mab"
|
||||
);
|
||||
Services.prefs.setStringPref(
|
||||
"mail.collect_addressbook",
|
||||
"moz-abmdbdirectory://test.mab"
|
||||
);
|
||||
Services.prefs.setStringPref(
|
||||
"mail.server.default.whiteListAbURI",
|
||||
"moz-abmdbdirectory://test.mab"
|
||||
);
|
||||
|
||||
// Do the migration.
|
||||
|
||||
MailMigrator._migrateAddressBooks();
|
||||
|
||||
// Check new files have been created, and old ones renamed.
|
||||
|
||||
checkFileExists("abook.sqlite", true);
|
||||
checkFileExists("abook.mab", false);
|
||||
checkFileExists("abook.mab.bak", false);
|
||||
checkFileExists("history.sqlite", true);
|
||||
checkFileExists("history.mab", false);
|
||||
checkFileExists("history.mab.bak", false);
|
||||
checkFileExists("test.sqlite", true);
|
||||
checkFileExists("test.mab", false);
|
||||
checkFileExists("test.mab.bak", true);
|
||||
|
||||
// Check that the default preferences are untouched.
|
||||
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.pab.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.pab.filename"),
|
||||
"abook.sqlite"
|
||||
);
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.history.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.history.filename"),
|
||||
"history.sqlite"
|
||||
);
|
||||
|
||||
// Check that the test book's preferences are updated, or not updated.
|
||||
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.Test.description"),
|
||||
"This is a test!"
|
||||
);
|
||||
equal(Services.prefs.getIntPref("ldap_2.servers.Test.dirType"), 101);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.Test.filename"),
|
||||
"test.sqlite"
|
||||
);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.Test.uid"),
|
||||
"12345678-1234-1234-1234-123456789012"
|
||||
);
|
||||
equal(
|
||||
Services.prefs.getStringPref("ldap_2.servers.Test.uri"),
|
||||
"jsaddrbook://test.sqlite"
|
||||
);
|
||||
|
||||
// Check that references to the book are updated.
|
||||
|
||||
equal(
|
||||
Services.prefs.getStringPref("mail.collect_addressbook"),
|
||||
"jsaddrbook://test.sqlite"
|
||||
);
|
||||
equal(
|
||||
Services.prefs.getStringPref("mail.server.default.whiteListAbURI"),
|
||||
"jsaddrbook://test.sqlite"
|
||||
);
|
||||
|
||||
// Check the new address books.
|
||||
|
||||
let directories = [...MailServices.ab.directories];
|
||||
equal(directories.length, 3);
|
||||
equal(directories[0].dirType, 101);
|
||||
equal(directories[1].dirType, 101);
|
||||
equal(directories[2].dirType, 101);
|
||||
|
||||
let [testBook] = directories;
|
||||
|
||||
// Check we have all the right cards.
|
||||
|
||||
let testCards = [...testBook.childCards];
|
||||
equal(testCards.length, 2);
|
||||
|
||||
ok(testCards[0].isMailList);
|
||||
equal(testCards[0].displayName, "List");
|
||||
|
||||
ok(!testCards[1].isMailList);
|
||||
equal(testCards[1].displayName, "First Last");
|
||||
equal(testCards[1].primaryEmail, "first@last");
|
||||
}
|
|
@ -6,9 +6,3 @@ support-files = data/*
|
|||
tags = jsaddrbook
|
||||
|
||||
[include:xpcshell.ini]
|
||||
[test_migration1.js]
|
||||
head = head_migration.js
|
||||
[test_migration2.js]
|
||||
head = head_migration.js
|
||||
[test_migration3.js]
|
||||
head = head_migration.js
|
||||
|
|
Загрузка…
Ссылка в новой задаче