Bug 1431470 - Add getTotalBookmarksCount to NewTabUtils.jsm r=ursula

MozReview-Commit-ID: BlcBcMap2Xw

--HG--
extra : rebase_source : d1e523f4a290528868646d52302b219dbe9c781e
This commit is contained in:
k88hudson 2018-02-27 17:50:16 -05:00
parent 85584725b3
commit 39dfbe5bf6
2 changed files with 44 additions and 0 deletions

View File

@ -1098,6 +1098,30 @@ var ActivityStreamProvider = {
}), options, "bookmark");
},
/**
* Get total count of all bookmarks.
* Note: this includes default bookmarks
*
* @return {int} The number bookmarks in the places DB.
*/
async getTotalBookmarksCount() {
let sqlQuery = `
SELECT count(*) FROM moz_bookmarks b
JOIN moz_bookmarks t ON t.id = b.parent
AND t.parent <> :tags_folder
WHERE b.type = :type_bookmark
`;
const result = await this.executePlacesQuery(sqlQuery, {
params: {
tags_folder: PlacesUtils.tagsFolderId,
type_bookmark: PlacesUtils.bookmarks.TYPE_BOOKMARK,
}
});
return result[0][0];
},
/**
* Get most-recently-visited history with metadata for Activity Stream.
*

View File

@ -920,6 +920,26 @@ add_task(async function activityStream_blockedURLs() {
Assert.equal(sizeQueryResult, 1, "got the correct bookmark size");
});
add_task(async function activityStream_getTotalBookmarksCount() {
await setUpActivityStreamTest();
let provider = NewTabUtils.activityStreamProvider;
let bookmarks = [
{url: "https://mozilla1.com/0", parentGuid: PlacesUtils.bookmarks.unfiledGuid},
{url: "https://mozilla1.com/1", parentGuid: PlacesUtils.bookmarks.unfiledGuid}
];
let bookmarksSize = await provider.getTotalBookmarksCount();
Assert.equal(bookmarksSize, 0, ".getTotalBookmarksCount() returns 0 for an empty bookmarks table");
for (const bookmark of bookmarks) {
await PlacesUtils.bookmarks.insert(bookmark);
}
bookmarksSize = await provider.getTotalBookmarksCount();
Assert.equal(bookmarksSize, 2, ".getTotalBookmarksCount() returns 2 after 2 bookmarks are inserted");
});
function TestProvider(getLinksFn) {
this.getLinks = getLinksFn;
this._observers = new Set();