toolkit/components/places/tests/unit/test_utils_setAnnotationsFor.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /**
michael@0 8 * Check for correct functionality of PlacesUtils.setAnnotationsForItem/URI
michael@0 9 */
michael@0 10
michael@0 11 var hs = PlacesUtils.history;
michael@0 12 var bs = PlacesUtils.bookmarks;
michael@0 13 var as = PlacesUtils.annotations;
michael@0 14
michael@0 15 const TEST_URL = "http://test.mozilla.org/";
michael@0 16
michael@0 17 function run_test() {
michael@0 18 var testURI = uri(TEST_URL);
michael@0 19 // add a bookmark
michael@0 20 var itemId = bs.insertBookmark(bs.unfiledBookmarksFolder, testURI,
michael@0 21 bs.DEFAULT_INDEX, "test");
michael@0 22
michael@0 23 // create annotations array
michael@0 24 var testAnnos = [{ name: "testAnno/test0",
michael@0 25 flags: 0,
michael@0 26 value: "test0",
michael@0 27 expires: Ci.nsIAnnotationService.EXPIRE_NEVER },
michael@0 28 { name: "testAnno/test1",
michael@0 29 flags: 0,
michael@0 30 value: "test1",
michael@0 31 expires: Ci.nsIAnnotationService.EXPIRE_NEVER },
michael@0 32 { name: "testAnno/test2",
michael@0 33 flags: 0,
michael@0 34 value: "test2",
michael@0 35 expires: Ci.nsIAnnotationService.EXPIRE_NEVER },
michael@0 36 { name: "testAnno/test3",
michael@0 37 flags: 0,
michael@0 38 value: 0,
michael@0 39 expires: Ci.nsIAnnotationService.EXPIRE_NEVER }];
michael@0 40
michael@0 41 // Add item annotations
michael@0 42 PlacesUtils.setAnnotationsForItem(itemId, testAnnos);
michael@0 43 // Check for correct addition
michael@0 44 testAnnos.forEach(function(anno) {
michael@0 45 do_check_true(as.itemHasAnnotation(itemId, anno.name));
michael@0 46 do_check_eq(as.getItemAnnotation(itemId, anno.name), anno.value);
michael@0 47 });
michael@0 48
michael@0 49 // Add page annotations
michael@0 50 PlacesUtils.setAnnotationsForURI(testURI, testAnnos);
michael@0 51 // Check for correct addition
michael@0 52 testAnnos.forEach(function(anno) {
michael@0 53 do_check_true(as.pageHasAnnotation(testURI, anno.name));
michael@0 54 do_check_eq(as.getPageAnnotation(testURI, anno.name), anno.value);
michael@0 55 });
michael@0 56
michael@0 57 // To unset annotations we unset their values or set them to
michael@0 58 //null/undefined
michael@0 59 testAnnos[0].value = null;
michael@0 60 testAnnos[1].value = undefined;
michael@0 61 delete testAnnos[2].value;
michael@0 62 delete testAnnos[3].value;
michael@0 63
michael@0 64 // Unset all item annotations
michael@0 65 PlacesUtils.setAnnotationsForItem(itemId, testAnnos);
michael@0 66 // Check for correct removal
michael@0 67 testAnnos.forEach(function(anno) {
michael@0 68 do_check_false(as.itemHasAnnotation(itemId, anno.name));
michael@0 69 // sanity: page annotations should not be removed here
michael@0 70 do_check_true(as.pageHasAnnotation(testURI, anno.name));
michael@0 71 });
michael@0 72
michael@0 73 // Unset all page annotations
michael@0 74 PlacesUtils.setAnnotationsForURI(testURI, testAnnos);
michael@0 75 // Check for correct removal
michael@0 76 testAnnos.forEach(function(anno) {
michael@0 77 do_check_false(as.pageHasAnnotation(testURI, anno.name));
michael@0 78 });
michael@0 79 }

mercurial