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

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

mercurial