Bug 1047819 - Add a basic test for PlacesUtils.getAnnotationsForItem. r?mak
MozReview-Commit-ID: 8mainkwtohn
new file mode 100644
--- /dev/null
+++ b/toolkit/components/places/tests/unit/test_PlacesUtils_annotations.js
@@ -0,0 +1,51 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const TEST_ANNOTATIONS = [{
+ name: "fake/annotation1",
+ value: "test",
+ flags: 0,
+ expires: Ci.nsIAnnotationService.EXPIRE_MONTHS,
+}, {
+ name: "fake/annotation2",
+ value: "test2",
+ flags: 0,
+ expires: Ci.nsIAnnotationService.EXPIRE_DAYS,
+}];
+
+function checkAnnotations(annotations, expectedAnnotations) {
+ Assert.equal(annotations.length, expectedAnnotations.length,
+ "Should have the expected number of annotations");
+
+ for (let i = 0; i < annotations.length; i++) {
+ Assert.deepEqual(annotations[i], TEST_ANNOTATIONS[i],
+ "Should have the correct annotation data");
+ }
+}
+
+add_task(async function test_getAnnotationsForItem() {
+ let bms = await PlacesUtils.bookmarks.insertTree({
+ guid: PlacesUtils.bookmarks.unfiledGuid,
+ children: [{
+ title: "no annotations",
+ url: "http://example.com",
+ }, {
+ title: "one annotations",
+ url: "http://example.com/1",
+ annos: [TEST_ANNOTATIONS[0]]
+ }, {
+ title: "two annotations",
+ url: "http://example.com/2",
+ annos: TEST_ANNOTATIONS
+ }],
+ });
+
+ let ids = await PlacesUtils.promiseManyItemIds(bms.map(bm => bm.guid));
+
+ for (let i = 0; i < bms.length; i++) {
+ let annotations = PlacesUtils.getAnnotationsForItem(ids.get(bms[i].guid));
+ checkAnnotations(annotations, TEST_ANNOTATIONS.slice(0, i));
+ }
+});
--- a/toolkit/components/places/tests/unit/xpcshell.ini
+++ b/toolkit/components/places/tests/unit/xpcshell.ini
@@ -92,16 +92,17 @@ skip-if = (os == 'win' && ccov) # Bug 14
[test_mozIAsyncLivemarks.js]
[test_multi_word_tags.js]
[test_nsINavHistoryViewer.js]
[test_null_interfaces.js]
[test_onItemChanged_tags.js]
[test_pageGuid_bookmarkGuid.js]
[test_frecency_observers.js]
[test_placeURIs.js]
+[test_PlacesUtils_annotations.js]
[test_PlacesUtils_invalidateCachedGuidFor.js]
[test_PlacesUtils_isRootItem.js]
[test_preventive_maintenance.js]
[test_preventive_maintenance_checkAndFixDatabase.js]
[test_preventive_maintenance_runTasks.js]
[test_promiseBookmarksTree.js]
[test_resolveNullBookmarkTitles.js]
[test_result_sort.js]