Commit 02cca2b6 authored by myeongjun's avatar myeongjun
Browse files

Bug 1512171 - Provide better error message when attempt is made to add...

Bug 1512171 - Provide better error message when attempt is made to add bookmark folder to root folder. r=robwu,rpl

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

--HG--
extra : moz-landing-system : lando
parent f7392cb9
......@@ -4,6 +4,10 @@
var {PlacesUtils} = ChromeUtils.import("resource://gre/modules/PlacesUtils.jsm");
var {
ExtensionError,
} = ExtensionUtils;
const {
TYPE_BOOKMARK,
TYPE_FOLDER,
......@@ -101,6 +105,12 @@ const convertBookmarks = result => {
return node;
};
const throwIfRootId = id => {
if (id == PlacesUtils.bookmarks.rootGuid) {
throw new ExtensionError("The bookmark root cannot be modified");
}
};
let observer = new class extends EventEmitter {
constructor() {
super();
......@@ -259,6 +269,7 @@ this.bookmarks = class extends ExtensionAPI {
}
if (bookmark.parentId !== null) {
throwIfRootId(bookmark.parentId);
info.parentGuid = bookmark.parentId;
} else {
info.parentGuid = PlacesUtils.bookmarks.unfiledGuid;
......@@ -273,11 +284,13 @@ this.bookmarks = class extends ExtensionAPI {
},
move: function(id, destination) {
throwIfRootId(id);
let info = {
guid: id,
};
if (destination.parentId !== null) {
throwIfRootId(destination.parentId);
info.parentGuid = destination.parentId;
}
info.index = (destination.index === null) ?
......@@ -292,6 +305,7 @@ this.bookmarks = class extends ExtensionAPI {
},
update: function(id, changes) {
throwIfRootId(id);
let info = {
guid: id,
};
......@@ -312,6 +326,7 @@ this.bookmarks = class extends ExtensionAPI {
},
remove: function(id) {
throwIfRootId(id);
let info = {
guid: id,
};
......@@ -326,6 +341,7 @@ this.bookmarks = class extends ExtensionAPI {
},
removeTree: function(id) {
throwIfRootId(id);
let info = {
guid: id,
};
......
......@@ -18,6 +18,7 @@ add_task(async function test_bookmarks() {
menuGuid: "menu________",
toolbarGuid: "toolbar_____",
unfiledGuid: "unfiled_____",
rootGuid: "root________",
};
function checkOurBookmark(bookmark) {
......@@ -601,6 +602,60 @@ add_task(async function test_bookmarks() {
"Expected error thrown when calling move with a non-existent bookmark"
);
});
}).then(() => {
return browser.test.assertRejects(
browser.bookmarks.create({title: "test root folder", parentId: bookmarkGuids.rootGuid}),
"The bookmark root cannot be modified",
"Expected error thrown when creating bookmark folder at the root"
);
}).then(() => {
return browser.test.assertRejects(
browser.bookmarks.update(bookmarkGuids.rootGuid, {title: "test update title"}),
"The bookmark root cannot be modified",
"Expected error thrown when updating root"
);
}).then(() => {
return browser.test.assertRejects(
browser.bookmarks.remove(bookmarkGuids.rootGuid),
"The bookmark root cannot be modified",
"Expected error thrown when removing root"
);
}).then(() => {
return browser.test.assertRejects(
browser.bookmarks.removeTree(bookmarkGuids.rootGuid),
"The bookmark root cannot be modified",
"Expected error thrown when removing root tree"
);
}).then(() => {
return browser.bookmarks.create({title: "Empty Folder"});
}).then(async result => {
createdFolderId = result.id;
browser.test.assertEq(1, collectedEvents.length, "1 expected events received");
checkOnCreated(createdFolderId, bookmarkGuids.unfiledGuid, 3, "Empty Folder", undefined, result.dateAdded, "folder");
await browser.test.assertRejects(
browser.bookmarks.move(createdFolderId, {parentId: bookmarkGuids.rootGuid}),
"The bookmark root cannot be modified",
"Expected error thrown when moving bookmark folder to the root"
);
return browser.bookmarks.remove(createdFolderId);
}).then(() => {
browser.test.assertEq(1, collectedEvents.length, "1 expected events received");
checkOnRemoved(createdFolderId, bookmarkGuids.unfiledGuid, 3, undefined, "folder");
return browser.test.assertRejects(
browser.bookmarks.get(createdFolderId),
"Bookmark not found",
"Expected error thrown when trying to get a removed folder"
);
}).then(() => {
return browser.test.assertRejects(
browser.bookmarks.move(bookmarkGuids.rootGuid, {parentId: bookmarkGuids.unfiledGuid}),
"The bookmark root cannot be modified",
"Expected error thrown when moving root"
);
}).then(() => {
// remove all created bookmarks
let promises = Array.from(createdBookmarks, guid => browser.bookmarks.remove(guid));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment