Bug 1358127 - Fix bookmarks.search so it doesn't return the contents of tag folders, r=mak

Also fix bookmarks.search so it doesn't return separators.

MozReview-Commit-ID: 18tkepk72f8

--HG--
extra : rebase_source : c1b713e6fb4e479df710bbc244e781a3bd4de48d
This commit is contained in:
Bob Silverberg 2017-04-24 09:04:59 -04:00
parent 9e0ccac709
commit 0c4c482352
2 changed files with 44 additions and 3 deletions

View File

@ -1310,9 +1310,14 @@ function insertBookmarkTree(items, source, parent, urls, lastAddedForParent) {
// Query implementation.
function queryBookmarks(info) {
let queryParams = {tags_folder: PlacesUtils.tagsFolderId};
// we're searching for bookmarks, so exclude tags
let queryString = "WHERE p.parent <> :tags_folder";
let queryParams = {
tags_folder: PlacesUtils.tagsFolderId,
type: Bookmarks.TYPE_SEPARATOR,
};
// We're searching for bookmarks, so exclude tags and separators.
let queryString = "WHERE b.type <> :type";
queryString += " AND b.parent <> :tags_folder";
queryString += " AND p.parent <> :tags_folder";
if (info.title) {
queryString += " AND b.title = :title";

View File

@ -221,3 +221,39 @@ add_task(function* search_folder() {
yield PlacesUtils.bookmarks.eraseEverything();
});
add_task(function* search_excludes_separators() {
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/",
title: "a bookmark" });
let bm2 = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
type: PlacesUtils.bookmarks.TYPE_SEPARATOR });
checkBookmarkObject(bm1);
checkBookmarkObject(bm2);
let results = yield PlacesUtils.bookmarks.search({});
Assert.ok(results.findIndex(bookmark => { return bookmark.guid == bm1.guid }) > -1,
"The bookmark was found in the results.");
Assert.equal(-1, results.findIndex(bookmark => { return bookmark.guid == bm2.guid }),
"The separator was excluded from the results.");
yield PlacesUtils.bookmarks.eraseEverything();
});
add_task(function* search_excludes_tags() {
let bm1 = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/",
title: "a bookmark" });
checkBookmarkObject(bm1);
PlacesUtils.tagging.tagURI(uri(bm1.url.href), ["Test Tag"]);
let results = yield PlacesUtils.bookmarks.search("example.com");
// If tags are not being excluded, this would return two results, one representing the tag.
Assert.equal(1, results.length, "A single object was returned from search.");
Assert.deepEqual(bm1, results[0], "The bookmark was returned.");
results = yield PlacesUtils.bookmarks.search("Test Tag");
Assert.equal(0, results.length, "The tag folder was not returned.");
yield PlacesUtils.bookmarks.eraseEverything();
});