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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
     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  * What this is aimed to test:
     9  *
    10  * EXPIRE_WITH_HISTORY annotations should be expired when a page has no more
    11  * visits, even if the page still exists in the database.
    12  * This expiration policy is only valid for page annotations.
    13  */
    15 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    16          getService(Ci.nsINavBookmarksService);
    17 let as = Cc["@mozilla.org/browser/annotation-service;1"].
    18          getService(Ci.nsIAnnotationService);
    20 function run_test() {
    21   run_next_test();
    22 }
    24 add_task(function test_annos_expire_history() {
    25   // Set interval to a large value so we don't expire on it.
    26   setInterval(3600); // 1h
    28   // Expire all expirable pages.
    29   setMaxPages(0);
    31   // Add some visited page and a couple expire with history annotations for each.
    32   let now = getExpirablePRTime();
    33   for (let i = 0; i < 5; i++) {
    34     let pageURI = uri("http://page_anno." + i + ".mozilla.org/");
    35     yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    36     as.setPageAnnotation(pageURI, "page_expire1", "test", 0, as.EXPIRE_WITH_HISTORY);
    37     as.setPageAnnotation(pageURI, "page_expire2", "test", 0, as.EXPIRE_WITH_HISTORY);
    38   }
    40   let pages = as.getPagesWithAnnotation("page_expire1");
    41   do_check_eq(pages.length, 5);
    42   pages = as.getPagesWithAnnotation("page_expire2");
    43   do_check_eq(pages.length, 5);
    45   // Add some bookmarked page and a couple session annotations for each.
    46   for (let i = 0; i < 5; i++) {
    47     let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
    48     // We also add a visit before bookmarking.
    49     yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    50     let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
    51                                bs.DEFAULT_INDEX, null);
    52     // Notice we use page annotations here, items annotations can't use this
    53     // kind of expiration policy.
    54     as.setPageAnnotation(pageURI, "item_persist1", "test", 0, as.EXPIRE_WITH_HISTORY);
    55     as.setPageAnnotation(pageURI, "item_persist2", "test", 0, as.EXPIRE_WITH_HISTORY);
    56   }
    58   let items = as.getPagesWithAnnotation("item_persist1");
    59   do_check_eq(items.length, 5);
    60   items = as.getPagesWithAnnotation("item_persist2");
    61   do_check_eq(items.length, 5);
    63   // Add other visited page and a couple expire with history annotations for each.
    64   // We won't expire these visits, so the annotations should survive.
    65   for (let i = 0; i < 5; i++) {
    66     let pageURI = uri("http://persist_page_anno." + i + ".mozilla.org/");
    67     yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
    68     as.setPageAnnotation(pageURI, "page_persist1", "test", 0, as.EXPIRE_WITH_HISTORY);
    69     as.setPageAnnotation(pageURI, "page_persist2", "test", 0, as.EXPIRE_WITH_HISTORY);
    70   }
    72   pages = as.getPagesWithAnnotation("page_persist1");
    73   do_check_eq(pages.length, 5);
    74   pages = as.getPagesWithAnnotation("page_persist2");
    75   do_check_eq(pages.length, 5);
    77   // Expire all visits for the first 5 pages and the bookmarks.
    78   yield promiseForceExpirationStep(10);
    80   let pages = as.getPagesWithAnnotation("page_expire1");
    81   do_check_eq(pages.length, 0);
    82   pages = as.getPagesWithAnnotation("page_expire2");
    83   do_check_eq(pages.length, 0);
    84   let items = as.getItemsWithAnnotation("item_persist1");
    85   do_check_eq(items.length, 0);
    86   items = as.getItemsWithAnnotation("item_persist2");
    87   do_check_eq(items.length, 0);
    88   pages = as.getPagesWithAnnotation("page_persist1");
    89   do_check_eq(pages.length, 5);
    90   pages = as.getPagesWithAnnotation("page_persist2");
    91   do_check_eq(pages.length, 5);
    92 });

mercurial