Bug 1047819 - Add a basic test for PlacesUtils.getAnnotationsForItem. r?mak draft
authorMark Banner <standard8@mozilla.com>
Wed, 28 Mar 2018 20:43:04 +0100
changeset 774659 1a87c28df4f83ae73f8378a44311d0dd6c240236
parent 774444 6aa3b57955fed5e137d0306478e1a4b424a6d392
child 774660 d2167920cf61c8ae58de6b5450b40f5eac7e10e9
child 774805 a6506c7edd7041b2541fab68771e551cdabb8d52
push id104470
push userbmo:standard8@mozilla.com
push dateThu, 29 Mar 2018 10:06:16 +0000
reviewersmak
bugs1047819
milestone61.0a1
Bug 1047819 - Add a basic test for PlacesUtils.getAnnotationsForItem. r?mak MozReview-Commit-ID: 8mainkwtohn
toolkit/components/places/tests/unit/test_PlacesUtils_annotations.js
toolkit/components/places/tests/unit/xpcshell.ini
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]