mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 17:25:36 +00:00
Bug 1431470 - Add getTotalBookmarksCount to NewTabUtils.jsm r=ursula
MozReview-Commit-ID: BlcBcMap2Xw --HG-- extra : rebase_source : d1e523f4a290528868646d52302b219dbe9c781e
This commit is contained in:
parent
85584725b3
commit
39dfbe5bf6
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user