--- a/toolkit/components/extensions/test/mochitest/test_ext_bookmarks.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_bookmarks.html
@@ -10,17 +10,24 @@
</head>
<body>
<script type="text/javascript">
"use strict";
function backgroundScript() {
let unsortedId, ourId;
+ let initialBookmarkCount = 0;
+ let createdBookmarks = new Set();
const nonExistentId = "000000000000";
+ const bookmarkGuids = {
+ menuGuid: "menu________",
+ toolbarGuid: "toolbar_____",
+ unfiledGuid: "unfiled_____",
+ };
function checkOurBookmark(bookmark) {
browser.test.assertEq(ourId, bookmark.id, "Bookmark has the expected Id");
browser.test.assertTrue("parentId" in bookmark, "Bookmark has a parentId");
browser.test.assertEq(0, bookmark.index, "Bookmark has the expected index"); // We assume there are no other bookmarks.
browser.test.assertEq("http://example.org/", bookmark.url, "Bookmark has the expected url");
browser.test.assertEq("test bookmark", bookmark.title, "Bookmark has the expected title");
browser.test.assertTrue("dateAdded" in bookmark, "Bookmark has a dateAdded");
@@ -49,16 +56,19 @@ function backgroundScript() {
return browser.bookmarks.get([nonExistentId]).then(expectedError, error => {
browser.test.assertTrue(
error.message.includes("Bookmark not found"),
"Expected error thrown when trying to get a bookmark using a non-existent Id"
);
});
}).then(() => {
+ return browser.bookmarks.search({});
+ }).then(results => {
+ initialBookmarkCount = results.length;
return browser.bookmarks.create({title: "test bookmark", url: "http://example.org"});
}).then(result => {
ourId = result.id;
checkOurBookmark(result);
return browser.bookmarks.get(ourId);
}).then(results => {
browser.test.assertEq(results.length, 1);
@@ -145,20 +155,23 @@ function backgroundScript() {
});
}).then(() => {
// test bookmarks.search
return Promise.all([
browser.bookmarks.create({title: "MØzillä", url: "http://møzîllä.örg"}),
browser.bookmarks.create({title: "Example", url: "http://example.org"}),
browser.bookmarks.create({title: "Mozilla Folder"}),
browser.bookmarks.create({title: "EFF", url: "http://eff.org"}),
- browser.bookmarks.create({title: "Menu Item", url: "http://menu.org", parentId: "menu________"}),
- browser.bookmarks.create({title: "Toolbar Item", url: "http://toolbar.org", parentId: "toolbar_____"}),
+ browser.bookmarks.create({title: "Menu Item", url: "http://menu.org", parentId: bookmarkGuids.menuGuid}),
+ browser.bookmarks.create({title: "Toolbar Item", url: "http://toolbar.org", parentId: bookmarkGuids.toolbarGuid}),
]);
}).then(results => {
+ for (let result of results) {
+ if (result.title !== "Mozilla Folder") createdBookmarks.add(result.id);
+ }
let createdFolderId = results[2].id;
return Promise.all([
browser.bookmarks.create({title: "Mozilla", url: "http://allizom.org", parentId: createdFolderId}),
browser.bookmarks.create({title: "Mozilla Corporation", url: "http://allizom.com", parentId: createdFolderId}),
browser.bookmarks.create({title: "Firefox", url: "http://allizom.org/firefox", parentId: createdFolderId}),
]).then(results => {
return browser.bookmarks.create({
title: "About Mozilla",
@@ -244,29 +257,29 @@ function backgroundScript() {
}).then(results => {
browser.test.assertEq(1, results.length, "Expected number of results returned for url search");
checkBookmark({title: "Example", url: "http://example.org/", index: 2}, results[0]);
// queries the title
return browser.bookmarks.search("EFF");
}).then(results => {
browser.test.assertEq(1, results.length, "Expected number of results returned for title search");
- checkBookmark({title: "EFF", url: "http://eff.org/", index: 0, parentId: "unfiled_____"}, results[0]);
+ checkBookmark({title: "EFF", url: "http://eff.org/", index: 0, parentId: bookmarkGuids.unfiledGuid}, results[0]);
// finds menu items
return browser.bookmarks.search("Menu Item");
}).then(results => {
browser.test.assertEq(1, results.length, "Expected number of results returned for menu item search");
- checkBookmark({title: "Menu Item", url: "http://menu.org/", index: 4, parentId: "menu________"}, results[0]);
+ checkBookmark({title: "Menu Item", url: "http://menu.org/", index: 4, parentId: bookmarkGuids.menuGuid}, results[0]);
// finds toolbar items
return browser.bookmarks.search("Toolbar Item");
}).then(results => {
browser.test.assertEq(1, results.length, "Expected number of results returned for toolbar item search");
- checkBookmark({title: "Toolbar Item", url: "http://toolbar.org/", index: 2, parentId: "toolbar_____"}, results[0]);
+ checkBookmark({title: "Toolbar Item", url: "http://toolbar.org/", index: 2, parentId: bookmarkGuids.toolbarGuid}, results[0]);
// finds folders
return browser.bookmarks.search("Mozilla Folder");
}).then(results => {
browser.test.assertEq(1, results.length, "Expected number of folders returned");
browser.test.assertEq("Mozilla Folder", results[0].title, "Folder has the expected title");
// is case-insensitive
@@ -347,34 +360,65 @@ function backgroundScript() {
return browser.bookmarks.getRecent(1.234);
}).then(expectedError, error => {
browser.test.assertTrue(
error.message.includes("Incorrect argument types for bookmarks.getRecent"),
"Expected error thrown when calling getRecent with a decimal number"
);
});
}).then(() => {
+ return Promise.all([
+ browser.bookmarks.search("corporation"),
+ browser.bookmarks.getChildren(bookmarkGuids.menuGuid),
+ ]);
+ }).then(results => {
+ let corporationBookmark = results[0][0];
+ let childCount = results[1].length;
+
+ browser.test.assertEq(2, corporationBookmark.index, "Bookmark has the expected index");
+
+ return browser.bookmarks.move(corporationBookmark.id, {index: 0}).then(result => {
+ browser.test.assertEq(0, result.index, "Bookmark has the expected index");
+
+ return browser.bookmarks.move(corporationBookmark.id, {parentId: bookmarkGuids.menuGuid});
+ }).then(result => {
+ browser.test.assertEq(bookmarkGuids.menuGuid, result.parentId, "Bookmark has the expected parent");
+ browser.test.assertEq(childCount + 1, result.index, "Bookmark has the expected index");
+
+ return browser.bookmarks.move(corporationBookmark.id, {index: 1});
+ }).then(result => {
+ browser.test.assertEq(bookmarkGuids.menuGuid, result.parentId, "Bookmark has the expected parent");
+ browser.test.assertEq(1, result.index, "Bookmark has the expected index");
+
+ return browser.bookmarks.move(corporationBookmark.id, {parentId: bookmarkGuids.toolbarGuid, index: 1});
+ }).then(result => {
+ browser.test.assertEq(bookmarkGuids.toolbarGuid, result.parentId, "Bookmark has the expected parent");
+ browser.test.assertEq(1, result.index, "Bookmark has the expected index");
+ createdBookmarks.add(corporationBookmark.id);
+ });
+ }).then(() => {
return browser.bookmarks.getRecent(5);
}).then(results => {
browser.test.assertEq(5, results.length, "Expected number of results returned by getRecent");
browser.test.assertEq("About Mozilla", results[0].title, "Bookmark has the expected title");
browser.test.assertEq("Firefox", results[1].title, "Bookmark has the expected title");
browser.test.assertEq("Mozilla Corporation", results[2].title, "Bookmark has the expected title");
browser.test.assertEq("Mozilla", results[3].title, "Bookmark has the expected title");
browser.test.assertEq("Toolbar Item", results[4].title, "Bookmark has the expected title");
return browser.bookmarks.search({});
}).then(results => {
let startBookmarkCount = results.length;
+
return browser.bookmarks.search({title: "Mozilla Folder"}).then(result => {
return browser.bookmarks.removeTree(result[0].id);
}).then(() => {
return browser.bookmarks.search({}).then(results => {
browser.test.assertEq(
- startBookmarkCount - 5,
+ startBookmarkCount - 4,
results.length,
"Expected number of results returned after removeTree");
});
});
}).then(() => {
return browser.bookmarks.create({title: "Empty Folder"});
}).then(result => {
let emptyFolderId = result.id;
@@ -390,16 +434,32 @@ function backgroundScript() {
}).then(() => {
return browser.bookmarks.getChildren(nonExistentId).then(expectedError, error => {
browser.test.assertTrue(
error.message.includes("root is null"),
"Expected error thrown when trying to getChildren for a non-existent folder"
);
});
}).then(() => {
+ return Promise.resolve().then(() => {
+ return browser.bookmarks.move(nonExistentId, {});
+ }).then(expectedError, error => {
+ browser.test.assertTrue(
+ error.message.includes("No bookmarks found for the provided GUID"),
+ "Expected error thrown when calling move with a non-existent bookmark"
+ );
+ });
+ }).then(() => {
+ // remove all created bookmarks
+ let promises = Array.from(createdBookmarks, guid => browser.bookmarks.remove(guid));
+ return Promise.all(promises);
+ }).then(() => {
+ return browser.bookmarks.search({});
+ }).then(results => {
+ browser.test.assertEq(initialBookmarkCount, results.length, "All created bookmarks have been removed");
return browser.test.notifyPass("bookmarks");
}).catch(error => {
browser.test.fail(`Error: ${String(error)} :: ${error.stack}`);
browser.test.notifyFail("bookmarks");
});
}
let extensionData = {