Bug 1127277 - Default to TYPE_BOOKMARK when no type is given for Bookmarks.insert() r=mak

This commit is contained in:
Tim Taubert 2015-03-11 14:54:05 +01:00
Родитель e439c48b38
Коммит 7f5745cc9d
2 изменённых файлов: 13 добавлений и 2 удалений

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

@ -140,7 +140,7 @@ let Bookmarks = Object.freeze({
// dateAdded may be imposed by the caller.
let time = (info && info.dateAdded) || new Date();
let insertInfo = validateBookmarkObject(info,
{ type: { required: true }
{ type: { defaultValue: this.TYPE_BOOKMARK }
, index: { defaultValue: this.DEFAULT_INDEX }
, url: { requiredIf: b => b.type == this.TYPE_BOOKMARK
, validIf: b => b.type == this.TYPE_BOOKMARK }
@ -1229,7 +1229,7 @@ function validateBookmarkObject(input, behavior={}) {
throw new Error(`Invalid value for property '${prop}': ${input[prop]}`);
}
if (behavior[prop].hasOwnProperty("defaultValue") && input[prop] === undefined) {
normalizedInput[prop] = behavior[prop].defaultValue;
input[prop] = behavior[prop].defaultValue;
}
}

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

@ -248,6 +248,17 @@ add_task(function* create_bookmark_frecency() {
Assert.ok(frecencyForUrl(bm.url) > 0, "Check frecency has been updated")
});
add_task(function* create_bookmark_without_type() {
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/",
title: "a bookmark" });
checkBookmarkObject(bm);
Assert.equal(bm.parentGuid, PlacesUtils.bookmarks.unfiledGuid);
Assert.equal(bm.type, PlacesUtils.bookmarks.TYPE_BOOKMARK);
Assert.equal(bm.url.href, "http://example.com/");
Assert.equal(bm.title, "a bookmark");
});
function run_test() {
run_next_test();
}