michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * Check for correct functionality of PlacesUtils.setAnnotationsForItem/URI michael@0: */ michael@0: michael@0: var hs = PlacesUtils.history; michael@0: var bs = PlacesUtils.bookmarks; michael@0: var as = PlacesUtils.annotations; michael@0: michael@0: const TEST_URL = "http://test.mozilla.org/"; michael@0: michael@0: function run_test() { michael@0: var testURI = uri(TEST_URL); michael@0: // add a bookmark michael@0: var itemId = bs.insertBookmark(bs.unfiledBookmarksFolder, testURI, michael@0: bs.DEFAULT_INDEX, "test"); michael@0: michael@0: // create annotations array michael@0: var testAnnos = [{ name: "testAnno/test0", michael@0: flags: 0, michael@0: value: "test0", michael@0: expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, michael@0: { name: "testAnno/test1", michael@0: flags: 0, michael@0: value: "test1", michael@0: expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, michael@0: { name: "testAnno/test2", michael@0: flags: 0, michael@0: value: "test2", michael@0: expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, michael@0: { name: "testAnno/test3", michael@0: flags: 0, michael@0: value: 0, michael@0: expires: Ci.nsIAnnotationService.EXPIRE_NEVER }]; michael@0: michael@0: // Add item annotations michael@0: PlacesUtils.setAnnotationsForItem(itemId, testAnnos); michael@0: // Check for correct addition michael@0: testAnnos.forEach(function(anno) { michael@0: do_check_true(as.itemHasAnnotation(itemId, anno.name)); michael@0: do_check_eq(as.getItemAnnotation(itemId, anno.name), anno.value); michael@0: }); michael@0: michael@0: // Add page annotations michael@0: PlacesUtils.setAnnotationsForURI(testURI, testAnnos); michael@0: // Check for correct addition michael@0: testAnnos.forEach(function(anno) { michael@0: do_check_true(as.pageHasAnnotation(testURI, anno.name)); michael@0: do_check_eq(as.getPageAnnotation(testURI, anno.name), anno.value); michael@0: }); michael@0: michael@0: // To unset annotations we unset their values or set them to michael@0: //null/undefined michael@0: testAnnos[0].value = null; michael@0: testAnnos[1].value = undefined; michael@0: delete testAnnos[2].value; michael@0: delete testAnnos[3].value; michael@0: michael@0: // Unset all item annotations michael@0: PlacesUtils.setAnnotationsForItem(itemId, testAnnos); michael@0: // Check for correct removal michael@0: testAnnos.forEach(function(anno) { michael@0: do_check_false(as.itemHasAnnotation(itemId, anno.name)); michael@0: // sanity: page annotations should not be removed here michael@0: do_check_true(as.pageHasAnnotation(testURI, anno.name)); michael@0: }); michael@0: michael@0: // Unset all page annotations michael@0: PlacesUtils.setAnnotationsForURI(testURI, testAnnos); michael@0: // Check for correct removal michael@0: testAnnos.forEach(function(anno) { michael@0: do_check_false(as.pageHasAnnotation(testURI, anno.name)); michael@0: }); michael@0: }