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.

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

mercurial