Bug 1489409 - Remove annotation options for PlacesTransactions.NewBookmark/NewFolder. r=mak

Differential Revision: https://phabricator.services.mozilla.com/D6093

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kajal Kumari Sah 2018-11-23 10:35:31 +00:00
Родитель 5973fb688b
Коммит 71787750bc
2 изменённых файлов: 5 добавлений и 123 удалений

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

@ -723,23 +723,6 @@ function checkProperty(obj, prop, required, checkFn) {
return !required;
}
DefineTransaction.annotationObjectValidate = function(obj) {
if (obj &&
checkProperty(obj, "name", true, v => typeof(v) == "string" && v.length > 0) &&
checkProperty(obj, "expires", false, Number.isInteger) &&
checkProperty(obj, "flags", false, Number.isInteger) &&
checkProperty(obj, "value", false, isPrimitive) ) {
// Nothing else should be set
let validKeys = ["name", "value", "flags", "expires"];
if (Object.keys(obj).every(k => validKeys.includes(k))) {
// Annotations objects are passed through to the backend, to avoid memory
// leaks, we must clone the object.
return {...obj};
}
}
throw new Error("Invalid annotation object");
};
DefineTransaction.childObjectValidate = function(obj) {
if (obj &&
checkProperty(obj, "title", false, v => typeof(v) == "string") &&
@ -908,14 +891,11 @@ DefineTransaction.defineInputProps(["keyword", "oldKeyword", "oldTag", "tag",
DefineTransaction.defineInputProps(["index", "newIndex"],
DefineTransaction.indexValidate,
PlacesUtils.bookmarks.DEFAULT_INDEX);
DefineTransaction.defineInputProps(["annotation"],
DefineTransaction.annotationObjectValidate);
DefineTransaction.defineInputProps(["child"],
DefineTransaction.childObjectValidate);
DefineTransaction.defineArrayInputProp("guids", "guid");
DefineTransaction.defineArrayInputProp("urls", "url");
DefineTransaction.defineArrayInputProp("tags", "tag");
DefineTransaction.defineArrayInputProp("annotations", "annotation");
DefineTransaction.defineArrayInputProp("children", "child");
DefineTransaction.defineArrayInputProp("excludingAnnotations",
"excludingAnnotation");
@ -1034,9 +1014,9 @@ var PT = PlacesTransactions;
* When this transaction is executed, it's resolved to the new bookmark's GUID.
*/
PT.NewBookmark = DefineTransaction(["parentGuid", "url"],
["index", "title", "annotations", "tags"]);
["index", "title", "tags"]);
PT.NewBookmark.prototype = Object.seal({
async execute({ parentGuid, url, index, title, annotations, tags }) {
async execute({ parentGuid, url, index, title, tags }) {
let info = { parentGuid, index, url, title };
// Filter tags to exclude already existing ones.
if (tags.length > 0) {
@ -1047,11 +1027,6 @@ PT.NewBookmark.prototype = Object.seal({
async function createItem() {
info = await PlacesUtils.bookmarks.insert(info);
if (annotations.length > 0) {
let itemId = await PlacesUtils.promiseItemId(info.guid);
PlacesUtils.setAnnotationsForItem(itemId, annotations,
Ci.nsINavBookmarksService.SOURCE_DEFAULT, true);
}
if (tags.length > 0) {
PlacesUtils.tagging.tagURI(Services.io.newURI(url.href), tags);
}
@ -1083,9 +1058,9 @@ PT.NewBookmark.prototype = Object.seal({
* When this transaction is executed, it's resolved to the new folder's GUID.
*/
PT.NewFolder = DefineTransaction(["parentGuid", "title"],
["index", "annotations", "children"]);
["index", "children"]);
PT.NewFolder.prototype = Object.seal({
async execute({ parentGuid, title, index, annotations, children }) {
async execute({ parentGuid, title, index, children }) {
let folderGuid;
let info = {
children: [{
@ -1122,12 +1097,6 @@ PT.NewFolder.prototype = Object.seal({
bmInfo[0].index = index;
bmInfo = await PlacesUtils.bookmarks.update(bmInfo[0]);
}
if (annotations.length > 0) {
let itemId = await PlacesUtils.promiseItemId(folderGuid);
PlacesUtils.setAnnotationsForItem(itemId, annotations,
Ci.nsINavBookmarksService.SOURCE_DEFAULT, true);
}
}
await createItem();

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

@ -422,46 +422,6 @@ add_task(async function test_recycled_transactions() {
observer.reset();
});
add_task(async function test_new_folder_with_annotation() {
const ANNO = { name: "TestAnno", value: "TestValue" };
let folder_info = createTestFolderInfo();
folder_info.index = bmStartIndex;
folder_info.annotations = [ANNO];
ensureUndoState();
let txn = PT.NewFolder(folder_info);
folder_info.guid = await txn.transact();
let originalInfo = await PlacesUtils.promiseBookmarksTree(folder_info.guid);
let ensureDo = async function(aRedo = false) {
ensureUndoState([[txn]], 0);
await ensureItemsAdded(folder_info);
ensureAnnotationsSet(folder_info.guid, [ANNO]);
if (aRedo) {
// Ignore lastModified in the comparison, for performance reasons.
originalInfo.lastModified = null;
await ensureBookmarksTreeRestoredCorrectlyExceptDates(originalInfo);
}
observer.reset();
};
let ensureUndo = () => {
ensureUndoState([[txn]], 1);
ensureItemsRemoved({ guid: folder_info.guid,
parentGuid: folder_info.parentGuid,
index: bmStartIndex });
observer.reset();
};
await ensureDo();
await PT.undo();
await ensureUndo();
await PT.redo();
await ensureDo(true);
await PT.undo();
ensureUndo();
await PT.clearTransactionsHistory();
ensureUndoState();
});
add_task(async function test_new_folder_with_children() {
let folder_info = createTestFolderInfo("Test folder", PlacesUtils.bookmarks.menuGuid, [{
url: "http://test_create_item.com",
@ -922,7 +882,6 @@ add_task(async function test_add_and_remove_bookmarks_with_additional_info() {
const testURI = "http://add.remove.tag";
const TAG_1 = "TestTag1";
const TAG_2 = "TestTag2";
const ANNO = { name: "TestAnno", value: "TestAnnoValue" };
let folder_info = createTestFolderInfo();
folder_info.guid = await PT.NewFolder(folder_info).transact();
@ -965,15 +924,8 @@ add_task(async function test_add_and_remove_bookmarks_with_additional_info() {
observer.reset();
let b2_info = { parentGuid: folder_info.guid,
url: testURI,
tags: [TAG_1, TAG_2],
annotations: [ANNO] };
tags: [TAG_1, TAG_2] };
b2_info.guid = await PT.NewBookmark(b2_info).transact();
let b2_post_creation_changes = [
{ guid: b2_info.guid,
isAnnoProperty: true,
property: ANNO.name,
newValue: ANNO.value } ];
ensureItemsChanged(...b2_post_creation_changes);
ensureTags([TAG_1, TAG_2]);
observer.reset();
@ -984,10 +936,6 @@ add_task(async function test_add_and_remove_bookmarks_with_additional_info() {
// Check if Remove correctly restores tags and annotations.
observer.reset();
await PT.redo();
ensureItemsChanged({ guid: b2_info.guid,
isAnnoProperty: true,
property: ANNO.name,
newValue: ANNO.value });
ensureTags([TAG_1, TAG_2]);
// Test Remove for multiple items.
@ -1005,7 +953,6 @@ add_task(async function test_add_and_remove_bookmarks_with_additional_info() {
observer.reset();
await PT.undo();
ensureItemsChanged(...b2_post_creation_changes);
ensureTags([TAG_1, TAG_2]);
observer.reset();
@ -1656,40 +1603,6 @@ add_task(async function test_array_input_for_batch() {
await PT.clearTransactionsHistory();
});
add_task(async function test_copy_excluding_annotations() {
let folderInfo = createTestFolderInfo();
let anno = n => { return { name: n, value: 1 }; };
folderInfo.annotations = [anno("a"), anno("b"), anno("c")];
let folderGuid = await PT.NewFolder(folderInfo).transact();
let ensureAnnosSet = async function(guid, ...expectedAnnoNames) {
let tree = await PlacesUtils.promiseBookmarksTree(guid);
let annoNames = "annos" in tree ?
tree.annos.map(a => a.name).sort() : [];
Assert.deepEqual(annoNames, expectedAnnoNames);
};
await ensureAnnosSet(folderGuid, "a", "b", "c");
let excluding_a_dupeGuid =
await PT.Copy({ guid: folderGuid,
newParentGuid: PlacesUtils.bookmarks.unfiledGuid,
excludingAnnotation: "a" }).transact();
await ensureAnnosSet(excluding_a_dupeGuid, "b", "c");
let excluding_ac_dupeGuid =
await PT.Copy({ guid: folderGuid,
newParentGuid: PlacesUtils.bookmarks.unfiledGuid,
excludingAnnotations: ["a", "c"] }).transact();
await ensureAnnosSet(excluding_ac_dupeGuid, "b");
// Cleanup
await PT.undo();
await PT.undo();
await PT.undo();
await PT.clearTransactionsHistory();
});
add_task(async function test_invalid_uri_spec_throws() {
Assert.throws(() =>
PT.NewBookmark({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,