Bug 1155705 - Safari bookmarks migration is broken. r=Gijs

This commit is contained in:
Marco Bonardo 2015-04-17 21:22:40 +02:00
Родитель 6663c08566
Коммит ea323040f5
6 изменённых файлов: 72 добавлений и 0 удалений

Двоичный файл не отображается.

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

@ -35,3 +35,26 @@ function promiseMigration(migrator, resourceType) {
migrator.migrate(resourceType, null, null);
});
}
/**
* Replaces a directory service entry with a given nsIFile.
*/
function registerFakePath(key, file) {
// Register our own provider for the Library directory.
let provider = {
getFile(prop, persistent) {
persistent.value = true;
if (prop == key) {
return file;
}
throw Cr.NS_ERROR_FAILURE;
},
QueryInterface: XPCOMUtils.generateQI([ Ci.nsIDirectoryServiceProvider ])
};
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
.registerProvider(provider);
do_register_cleanup(() => {
Services.dirsvc.QueryInterface(Ci.nsIDirectoryService)
.unregisterProvider(provider);
});
}

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

@ -0,0 +1,37 @@
add_task(function* () {
registerFakePath("ULibDir", do_get_file("Library/"));
let migrator = MigrationUtils.getMigrator("safari");
// Sanity check for the source.
Assert.ok(migrator.sourceExists);
// Wait for the imported bookmarks. Check that "From Safari"
// folders are created on the toolbar.
let source = MigrationUtils.getLocalizedString("sourceNameSafari");
let label = MigrationUtils.getLocalizedString("importedBookmarksFolder", [source]);
let expectedParents = [ PlacesUtils.toolbarFolderId ];
PlacesUtils.bookmarks.addObserver({
onItemAdded(aItemId, aParentId, aIndex, aItemType, aURI, aTitle) {
if (aTitle == label) {
let index = expectedParents.indexOf(aParentId);
Assert.notEqual(index, -1);
expectedParents.splice(index, 1);
if (expectedParents.length == 0)
PlacesUtils.bookmarks.removeObserver(this);
}
},
onBeginUpdateBatch() {},
onEndUpdateBatch() {},
onItemRemoved() {},
onItemChanged() {},
onItemVisited() {},
onItemMoved() {},
}, false);
yield promiseMigration(migrator, MigrationUtils.resourceTypes.BOOKMARKS);
// Check the bookmarks have been imported to all the expected parents.
Assert.equal(expectedParents.length, 0);
});

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

@ -3,9 +3,13 @@ head = head_migration.js
tail =
firefox-appdir = browser
skip-if = toolkit == 'android' || toolkit == 'gonk'
support-files =
Library/Safari/Bookmarks.plist
[test_fx_fhr.js]
[test_IE_bookmarks.js]
skip-if = os != "win"
[test_IE_cookies.js]
skip-if = os != "win"
[test_Safari_bookmarks.js]
skip-if = os != "mac"

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

@ -807,6 +807,8 @@ function LazyMapProxyHandler () {
}
return target.delete(key);
};
case "has":
return key => target.has(key);
default:
return target[name];
}

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

@ -35,7 +35,13 @@ function checkMainPropertyList(aPropertyListRoot) {
const PRIMITIVE = PropertyListUtils.TYPE_PRIMITIVE;
checkValue(aPropertyListRoot, PropertyListUtils.TYPE_DICTIONARY);
// Check .has()
Assert.ok(aPropertyListRoot.has("Boolean"));
Assert.ok(!aPropertyListRoot.has("Nonexistent"));
checkValue(aPropertyListRoot.get("Boolean"), PRIMITIVE, false);
let array = aPropertyListRoot.get("Array");
checkValue(array, PropertyListUtils.TYPE_ARRAY);
do_check_eq(array.length, 8);