Bug 1047819 - Add a basic test for PlacesUtils.getAnnotationsForItem. r=mak
authorMark Banner <standard8@mozilla.com>
Wed, 28 Mar 2018 20:43:04 +0100
changeset 410617 b2b99ec4dca66a9fce67a226ead6a4e8f82cb58d
parent 410616 a9c4bf921486d8be6dc72dedcea1792357be8f41
child 410618 cb8cbe3c000f80ea886c6406cdad87e3c6236bfc
push id33733
push useraciure@mozilla.com
push dateThu, 29 Mar 2018 22:05:29 +0000
treeherdermozilla-central@7ca58ce09779 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1047819
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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]