toolkit/components/places/tests/expiration/test_annos_expire_history.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_history.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,92 @@
     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_WITH_HISTORY annotations should be expired when a page has no more
    1.14 + * visits, even if the page still exists in the database.
    1.15 + * This expiration policy is only valid for page annotations.
    1.16 + */
    1.17 +
    1.18 +let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.19 +         getService(Ci.nsINavBookmarksService);
    1.20 +let as = Cc["@mozilla.org/browser/annotation-service;1"].
    1.21 +         getService(Ci.nsIAnnotationService);
    1.22 +
    1.23 +function run_test() {
    1.24 +  run_next_test();
    1.25 +}
    1.26 +
    1.27 +add_task(function test_annos_expire_history() {
    1.28 +  // Set interval to a large value so we don't expire on it.
    1.29 +  setInterval(3600); // 1h
    1.30 +
    1.31 +  // Expire all expirable pages.
    1.32 +  setMaxPages(0);
    1.33 +
    1.34 +  // Add some visited page and a couple expire with history annotations for each.
    1.35 +  let now = getExpirablePRTime();
    1.36 +  for (let i = 0; i < 5; i++) {
    1.37 +    let pageURI = uri("http://page_anno." + i + ".mozilla.org/");
    1.38 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.39 +    as.setPageAnnotation(pageURI, "page_expire1", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.40 +    as.setPageAnnotation(pageURI, "page_expire2", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.41 +  }
    1.42 +
    1.43 +  let pages = as.getPagesWithAnnotation("page_expire1");
    1.44 +  do_check_eq(pages.length, 5);
    1.45 +  pages = as.getPagesWithAnnotation("page_expire2");
    1.46 +  do_check_eq(pages.length, 5);
    1.47 +
    1.48 +  // Add some bookmarked page and a couple session annotations for each.
    1.49 +  for (let i = 0; i < 5; i++) {
    1.50 +    let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
    1.51 +    // We also add a visit before bookmarking.
    1.52 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.53 +    let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
    1.54 +                               bs.DEFAULT_INDEX, null);
    1.55 +    // Notice we use page annotations here, items annotations can't use this
    1.56 +    // kind of expiration policy.
    1.57 +    as.setPageAnnotation(pageURI, "item_persist1", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.58 +    as.setPageAnnotation(pageURI, "item_persist2", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.59 +  }
    1.60 +
    1.61 +  let items = as.getPagesWithAnnotation("item_persist1");
    1.62 +  do_check_eq(items.length, 5);
    1.63 +  items = as.getPagesWithAnnotation("item_persist2");
    1.64 +  do_check_eq(items.length, 5);
    1.65 +
    1.66 +  // Add other visited page and a couple expire with history annotations for each.
    1.67 +  // We won't expire these visits, so the annotations should survive.
    1.68 +  for (let i = 0; i < 5; i++) {
    1.69 +    let pageURI = uri("http://persist_page_anno." + i + ".mozilla.org/");
    1.70 +    yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    1.71 +    as.setPageAnnotation(pageURI, "page_persist1", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.72 +    as.setPageAnnotation(pageURI, "page_persist2", "test", 0, as.EXPIRE_WITH_HISTORY);
    1.73 +  }
    1.74 +
    1.75 +  pages = as.getPagesWithAnnotation("page_persist1");
    1.76 +  do_check_eq(pages.length, 5);
    1.77 +  pages = as.getPagesWithAnnotation("page_persist2");
    1.78 +  do_check_eq(pages.length, 5);
    1.79 +
    1.80 +  // Expire all visits for the first 5 pages and the bookmarks.
    1.81 +  yield promiseForceExpirationStep(10);
    1.82 +
    1.83 +  let pages = as.getPagesWithAnnotation("page_expire1");
    1.84 +  do_check_eq(pages.length, 0);
    1.85 +  pages = as.getPagesWithAnnotation("page_expire2");
    1.86 +  do_check_eq(pages.length, 0);
    1.87 +  let items = as.getItemsWithAnnotation("item_persist1");
    1.88 +  do_check_eq(items.length, 0);
    1.89 +  items = as.getItemsWithAnnotation("item_persist2");
    1.90 +  do_check_eq(items.length, 0);
    1.91 +  pages = as.getPagesWithAnnotation("page_persist1");
    1.92 +  do_check_eq(pages.length, 5);
    1.93 +  pages = as.getPagesWithAnnotation("page_persist2");
    1.94 +  do_check_eq(pages.length, 5);
    1.95 +});
    1.96 \ No newline at end of file

mercurial