michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * What this is aimed to test: michael@0: * michael@0: * EXPIRE_WITH_HISTORY annotations should be expired when a page has no more michael@0: * visits, even if the page still exists in the database. michael@0: * This expiration policy is only valid for page annotations. michael@0: */ michael@0: michael@0: let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: let as = Cc["@mozilla.org/browser/annotation-service;1"]. michael@0: getService(Ci.nsIAnnotationService); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_annos_expire_history() { michael@0: // Set interval to a large value so we don't expire on it. michael@0: setInterval(3600); // 1h michael@0: michael@0: // Expire all expirable pages. michael@0: setMaxPages(0); michael@0: michael@0: // Add some visited page and a couple expire with history annotations for each. michael@0: let now = getExpirablePRTime(); michael@0: for (let i = 0; i < 5; i++) { michael@0: let pageURI = uri("http://page_anno." + i + ".mozilla.org/"); michael@0: yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); michael@0: as.setPageAnnotation(pageURI, "page_expire1", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: as.setPageAnnotation(pageURI, "page_expire2", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: } michael@0: michael@0: let pages = as.getPagesWithAnnotation("page_expire1"); michael@0: do_check_eq(pages.length, 5); michael@0: pages = as.getPagesWithAnnotation("page_expire2"); michael@0: do_check_eq(pages.length, 5); michael@0: michael@0: // Add some bookmarked page and a couple session annotations for each. michael@0: for (let i = 0; i < 5; i++) { michael@0: let pageURI = uri("http://item_anno." + i + ".mozilla.org/"); michael@0: // We also add a visit before bookmarking. michael@0: yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); michael@0: let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI, michael@0: bs.DEFAULT_INDEX, null); michael@0: // Notice we use page annotations here, items annotations can't use this michael@0: // kind of expiration policy. michael@0: as.setPageAnnotation(pageURI, "item_persist1", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: as.setPageAnnotation(pageURI, "item_persist2", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: } michael@0: michael@0: let items = as.getPagesWithAnnotation("item_persist1"); michael@0: do_check_eq(items.length, 5); michael@0: items = as.getPagesWithAnnotation("item_persist2"); michael@0: do_check_eq(items.length, 5); michael@0: michael@0: // Add other visited page and a couple expire with history annotations for each. michael@0: // We won't expire these visits, so the annotations should survive. michael@0: for (let i = 0; i < 5; i++) { michael@0: let pageURI = uri("http://persist_page_anno." + i + ".mozilla.org/"); michael@0: yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); michael@0: as.setPageAnnotation(pageURI, "page_persist1", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: as.setPageAnnotation(pageURI, "page_persist2", "test", 0, as.EXPIRE_WITH_HISTORY); michael@0: } michael@0: michael@0: pages = as.getPagesWithAnnotation("page_persist1"); michael@0: do_check_eq(pages.length, 5); michael@0: pages = as.getPagesWithAnnotation("page_persist2"); michael@0: do_check_eq(pages.length, 5); michael@0: michael@0: // Expire all visits for the first 5 pages and the bookmarks. michael@0: yield promiseForceExpirationStep(10); michael@0: michael@0: let pages = as.getPagesWithAnnotation("page_expire1"); michael@0: do_check_eq(pages.length, 0); michael@0: pages = as.getPagesWithAnnotation("page_expire2"); michael@0: do_check_eq(pages.length, 0); michael@0: let items = as.getItemsWithAnnotation("item_persist1"); michael@0: do_check_eq(items.length, 0); michael@0: items = as.getItemsWithAnnotation("item_persist2"); michael@0: do_check_eq(items.length, 0); michael@0: pages = as.getPagesWithAnnotation("page_persist1"); michael@0: do_check_eq(pages.length, 5); michael@0: pages = as.getPagesWithAnnotation("page_persist2"); michael@0: do_check_eq(pages.length, 5); michael@0: });