toolkit/components/places/tests/expiration/test_annos_expire_never.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/expiration/test_annos_expire_never.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     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 + * What this is aimed to test:
    1.12 + *
    1.13 + * EXPIRE_NEVER annotations should be expired when a page is removed from the
    1.14 + * database.
    1.15 + * If the annotation is a page annotation this will happen when the page is
    1.16 + * expired, namely when the page has no visits and is not bookmarked.
    1.17 + * Otherwise if it's an item annotation the annotation will be expired when
    1.18 + * the item is removed, thus expiration won't handle this case at all.
    1.19 + */
    1.20 +
    1.21 +let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.22 +         getService(Ci.nsINavBookmarksService);
    1.23 +let as = Cc["@mozilla.org/browser/annotation-service;1"].
    1.24 +         getService(Ci.nsIAnnotationService);
    1.25 +
    1.26 +function run_test() {
    1.27 +  run_next_test();
    1.28 +}
    1.29 +
    1.30 +add_task(function test_annos_expire_never() {
    1.31 +  // Set interval to a large value so we don't expire on it.
    1.32 +  setInterval(3600); // 1h
    1.33 +
    1.34 +  // Expire all expirable pages.
    1.35 +  setMaxPages(0);
    1.36 +
    1.37 +  // Add some visited page and a couple expire never annotations for each.
    1.38 +  let now = getExpirablePRTime();
    1.39 +  for (let i = 0; i < 5; i++) {
    1.40 +    let pageURI = uri("http://page_anno." + i + ".mozilla.org/");
    1.41 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.42 +    as.setPageAnnotation(pageURI, "page_expire1", "test", 0, as.EXPIRE_NEVER);
    1.43 +    as.setPageAnnotation(pageURI, "page_expire2", "test", 0, as.EXPIRE_NEVER);
    1.44 +  }
    1.45 +
    1.46 +  let pages = as.getPagesWithAnnotation("page_expire1");
    1.47 +  do_check_eq(pages.length, 5);
    1.48 +  pages = as.getPagesWithAnnotation("page_expire2");
    1.49 +  do_check_eq(pages.length, 5);
    1.50 +
    1.51 +  // Add some bookmarked page and a couple expire never annotations for each.
    1.52 +  for (let i = 0; i < 5; i++) {
    1.53 +    let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
    1.54 +    // We also add a visit before bookmarking.
    1.55 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.56 +    let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
    1.57 +                               bs.DEFAULT_INDEX, null);
    1.58 +    as.setItemAnnotation(id, "item_persist1", "test", 0, as.EXPIRE_NEVER);
    1.59 +    as.setItemAnnotation(id, "item_persist2", "test", 0, as.EXPIRE_NEVER);
    1.60 +  }
    1.61 +
    1.62 +  let items = as.getItemsWithAnnotation("item_persist1");
    1.63 +  do_check_eq(items.length, 5);
    1.64 +  items = as.getItemsWithAnnotation("item_persist2");
    1.65 +  do_check_eq(items.length, 5);
    1.66 +
    1.67 +  // Add other visited page and a couple expire never annotations for each.
    1.68 +  // We won't expire these visits, so the annotations should survive.
    1.69 +  for (let i = 0; i < 5; i++) {
    1.70 +    let pageURI = uri("http://persist_page_anno." + i + ".mozilla.org/");
    1.71 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.72 +    as.setPageAnnotation(pageURI, "page_persist1", "test", 0, as.EXPIRE_NEVER);
    1.73 +    as.setPageAnnotation(pageURI, "page_persist2", "test", 0, as.EXPIRE_NEVER);
    1.74 +  }
    1.75 +
    1.76 +  pages = as.getPagesWithAnnotation("page_persist1");
    1.77 +  do_check_eq(pages.length, 5);
    1.78 +  pages = as.getPagesWithAnnotation("page_persist2");
    1.79 +  do_check_eq(pages.length, 5);
    1.80 +
    1.81 +  // Expire all visits for the first 5 pages and the bookmarks.
    1.82 +  yield promiseForceExpirationStep(10);
    1.83 +
    1.84 +  let pages = as.getPagesWithAnnotation("page_expire1");
    1.85 +  do_check_eq(pages.length, 0);
    1.86 +  pages = as.getPagesWithAnnotation("page_expire2");
    1.87 +  do_check_eq(pages.length, 0);
    1.88 +  let items = as.getItemsWithAnnotation("item_persist1");
    1.89 +  do_check_eq(items.length, 5);
    1.90 +  items = as.getItemsWithAnnotation("item_persist2");
    1.91 +  do_check_eq(items.length, 5);
    1.92 +  pages = as.getPagesWithAnnotation("page_persist1");
    1.93 +  do_check_eq(pages.length, 5);
    1.94 +  pages = as.getPagesWithAnnotation("page_persist2");
    1.95 +  do_check_eq(pages.length, 5);
    1.96 +});

mercurial