1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_utils_setAnnotationsFor.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + /** 1.11 + * Check for correct functionality of PlacesUtils.setAnnotationsForItem/URI 1.12 + */ 1.13 + 1.14 +var hs = PlacesUtils.history; 1.15 +var bs = PlacesUtils.bookmarks; 1.16 +var as = PlacesUtils.annotations; 1.17 + 1.18 +const TEST_URL = "http://test.mozilla.org/"; 1.19 + 1.20 +function run_test() { 1.21 + var testURI = uri(TEST_URL); 1.22 + // add a bookmark 1.23 + var itemId = bs.insertBookmark(bs.unfiledBookmarksFolder, testURI, 1.24 + bs.DEFAULT_INDEX, "test"); 1.25 + 1.26 + // create annotations array 1.27 + var testAnnos = [{ name: "testAnno/test0", 1.28 + flags: 0, 1.29 + value: "test0", 1.30 + expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, 1.31 + { name: "testAnno/test1", 1.32 + flags: 0, 1.33 + value: "test1", 1.34 + expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, 1.35 + { name: "testAnno/test2", 1.36 + flags: 0, 1.37 + value: "test2", 1.38 + expires: Ci.nsIAnnotationService.EXPIRE_NEVER }, 1.39 + { name: "testAnno/test3", 1.40 + flags: 0, 1.41 + value: 0, 1.42 + expires: Ci.nsIAnnotationService.EXPIRE_NEVER }]; 1.43 + 1.44 + // Add item annotations 1.45 + PlacesUtils.setAnnotationsForItem(itemId, testAnnos); 1.46 + // Check for correct addition 1.47 + testAnnos.forEach(function(anno) { 1.48 + do_check_true(as.itemHasAnnotation(itemId, anno.name)); 1.49 + do_check_eq(as.getItemAnnotation(itemId, anno.name), anno.value); 1.50 + }); 1.51 + 1.52 + // Add page annotations 1.53 + PlacesUtils.setAnnotationsForURI(testURI, testAnnos); 1.54 + // Check for correct addition 1.55 + testAnnos.forEach(function(anno) { 1.56 + do_check_true(as.pageHasAnnotation(testURI, anno.name)); 1.57 + do_check_eq(as.getPageAnnotation(testURI, anno.name), anno.value); 1.58 + }); 1.59 + 1.60 + // To unset annotations we unset their values or set them to 1.61 + //null/undefined 1.62 + testAnnos[0].value = null; 1.63 + testAnnos[1].value = undefined; 1.64 + delete testAnnos[2].value; 1.65 + delete testAnnos[3].value; 1.66 + 1.67 + // Unset all item annotations 1.68 + PlacesUtils.setAnnotationsForItem(itemId, testAnnos); 1.69 + // Check for correct removal 1.70 + testAnnos.forEach(function(anno) { 1.71 + do_check_false(as.itemHasAnnotation(itemId, anno.name)); 1.72 + // sanity: page annotations should not be removed here 1.73 + do_check_true(as.pageHasAnnotation(testURI, anno.name)); 1.74 + }); 1.75 + 1.76 + // Unset all page annotations 1.77 + PlacesUtils.setAnnotationsForURI(testURI, testAnnos); 1.78 + // Check for correct removal 1.79 + testAnnos.forEach(function(anno) { 1.80 + do_check_false(as.pageHasAnnotation(testURI, anno.name)); 1.81 + }); 1.82 +}