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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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_NEVER annotations should be expired when a page is removed from the
michael@0 11 * database.
michael@0 12 * If the annotation is a page annotation this will happen when the page is
michael@0 13 * expired, namely when the page has no visits and is not bookmarked.
michael@0 14 * Otherwise if it's an item annotation the annotation will be expired when
michael@0 15 * the item is removed, thus expiration won't handle this case at all.
michael@0 16 */
michael@0 17
michael@0 18 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
michael@0 19 getService(Ci.nsINavBookmarksService);
michael@0 20 let as = Cc["@mozilla.org/browser/annotation-service;1"].
michael@0 21 getService(Ci.nsIAnnotationService);
michael@0 22
michael@0 23 function run_test() {
michael@0 24 run_next_test();
michael@0 25 }
michael@0 26
michael@0 27 add_task(function test_annos_expire_never() {
michael@0 28 // Set interval to a large value so we don't expire on it.
michael@0 29 setInterval(3600); // 1h
michael@0 30
michael@0 31 // Expire all expirable pages.
michael@0 32 setMaxPages(0);
michael@0 33
michael@0 34 // Add some visited page and a couple expire never annotations for each.
michael@0 35 let now = getExpirablePRTime();
michael@0 36 for (let i = 0; i < 5; i++) {
michael@0 37 let pageURI = uri("http://page_anno." + i + ".mozilla.org/");
michael@0 38 yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
michael@0 39 as.setPageAnnotation(pageURI, "page_expire1", "test", 0, as.EXPIRE_NEVER);
michael@0 40 as.setPageAnnotation(pageURI, "page_expire2", "test", 0, as.EXPIRE_NEVER);
michael@0 41 }
michael@0 42
michael@0 43 let pages = as.getPagesWithAnnotation("page_expire1");
michael@0 44 do_check_eq(pages.length, 5);
michael@0 45 pages = as.getPagesWithAnnotation("page_expire2");
michael@0 46 do_check_eq(pages.length, 5);
michael@0 47
michael@0 48 // Add some bookmarked page and a couple expire never annotations for each.
michael@0 49 for (let i = 0; i < 5; i++) {
michael@0 50 let pageURI = uri("http://item_anno." + i + ".mozilla.org/");
michael@0 51 // We also add a visit before bookmarking.
michael@0 52 yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
michael@0 53 let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
michael@0 54 bs.DEFAULT_INDEX, null);
michael@0 55 as.setItemAnnotation(id, "item_persist1", "test", 0, as.EXPIRE_NEVER);
michael@0 56 as.setItemAnnotation(id, "item_persist2", "test", 0, as.EXPIRE_NEVER);
michael@0 57 }
michael@0 58
michael@0 59 let items = as.getItemsWithAnnotation("item_persist1");
michael@0 60 do_check_eq(items.length, 5);
michael@0 61 items = as.getItemsWithAnnotation("item_persist2");
michael@0 62 do_check_eq(items.length, 5);
michael@0 63
michael@0 64 // Add other visited page and a couple expire never annotations for each.
michael@0 65 // We won't expire these visits, so the annotations should survive.
michael@0 66 for (let i = 0; i < 5; i++) {
michael@0 67 let pageURI = uri("http://persist_page_anno." + i + ".mozilla.org/");
michael@0 68 yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
michael@0 69 as.setPageAnnotation(pageURI, "page_persist1", "test", 0, as.EXPIRE_NEVER);
michael@0 70 as.setPageAnnotation(pageURI, "page_persist2", "test", 0, as.EXPIRE_NEVER);
michael@0 71 }
michael@0 72
michael@0 73 pages = as.getPagesWithAnnotation("page_persist1");
michael@0 74 do_check_eq(pages.length, 5);
michael@0 75 pages = as.getPagesWithAnnotation("page_persist2");
michael@0 76 do_check_eq(pages.length, 5);
michael@0 77
michael@0 78 // Expire all visits for the first 5 pages and the bookmarks.
michael@0 79 yield promiseForceExpirationStep(10);
michael@0 80
michael@0 81 let pages = as.getPagesWithAnnotation("page_expire1");
michael@0 82 do_check_eq(pages.length, 0);
michael@0 83 pages = as.getPagesWithAnnotation("page_expire2");
michael@0 84 do_check_eq(pages.length, 0);
michael@0 85 let items = as.getItemsWithAnnotation("item_persist1");
michael@0 86 do_check_eq(items.length, 5);
michael@0 87 items = as.getItemsWithAnnotation("item_persist2");
michael@0 88 do_check_eq(items.length, 5);
michael@0 89 pages = as.getPagesWithAnnotation("page_persist1");
michael@0 90 do_check_eq(pages.length, 5);
michael@0 91 pages = as.getPagesWithAnnotation("page_persist2");
michael@0 92 do_check_eq(pages.length, 5);
michael@0 93 });

mercurial