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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 * Session annotations should be expired when browsing session ends.
michael@0 11 */
michael@0 12
michael@0 13 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
michael@0 14 getService(Ci.nsINavBookmarksService);
michael@0 15 let as = Cc["@mozilla.org/browser/annotation-service;1"].
michael@0 16 getService(Ci.nsIAnnotationService);
michael@0 17
michael@0 18 function run_test() {
michael@0 19 run_next_test();
michael@0 20 }
michael@0 21
michael@0 22 add_task(function test_annos_expire_session() {
michael@0 23 // Set interval to a large value so we don't expire on it.
michael@0 24 setInterval(3600); // 1h
michael@0 25
michael@0 26 // Add some visited page and a couple session annotations for each.
michael@0 27 let now = Date.now() * 1000;
michael@0 28 for (let i = 0; i < 10; i++) {
michael@0 29 let pageURI = uri("http://session_page_anno." + i + ".mozilla.org/");
michael@0 30 yield promiseAddVisits({ uri: pageURI, visitDate: now++ });
michael@0 31 as.setPageAnnotation(pageURI, "test1", "test", 0, as.EXPIRE_SESSION);
michael@0 32 as.setPageAnnotation(pageURI, "test2", "test", 0, as.EXPIRE_SESSION);
michael@0 33 }
michael@0 34
michael@0 35 // Add some bookmarked page and a couple session annotations for each.
michael@0 36 for (let i = 0; i < 10; i++) {
michael@0 37 let pageURI = uri("http://session_item_anno." + i + ".mozilla.org/");
michael@0 38 let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI,
michael@0 39 bs.DEFAULT_INDEX, null);
michael@0 40 as.setItemAnnotation(id, "test1", "test", 0, as.EXPIRE_SESSION);
michael@0 41 as.setItemAnnotation(id, "test2", "test", 0, as.EXPIRE_SESSION);
michael@0 42 }
michael@0 43
michael@0 44
michael@0 45 let pages = as.getPagesWithAnnotation("test1");
michael@0 46 do_check_eq(pages.length, 10);
michael@0 47 pages = as.getPagesWithAnnotation("test2");
michael@0 48 do_check_eq(pages.length, 10);
michael@0 49 let items = as.getItemsWithAnnotation("test1");
michael@0 50 do_check_eq(items.length, 10);
michael@0 51 items = as.getItemsWithAnnotation("test2");
michael@0 52 do_check_eq(items.length, 10);
michael@0 53
michael@0 54 let deferred = Promise.defer();
michael@0 55 waitForConnectionClosed(function() {
michael@0 56 let stmt = DBConn(true).createAsyncStatement(
michael@0 57 "SELECT id FROM moz_annos "
michael@0 58 + "UNION ALL "
michael@0 59 + "SELECT id FROM moz_items_annos "
michael@0 60 );
michael@0 61 stmt.executeAsync({
michael@0 62 handleResult: function(aResultSet) {
michael@0 63 dump_table("moz_annos");
michael@0 64 dump_table("moz_items_annos");
michael@0 65 do_throw("Should not find any leftover session annotations");
michael@0 66 },
michael@0 67 handleError: function(aError) {
michael@0 68 do_throw("Error code " + aError.result + " with message '" +
michael@0 69 aError.message + "' returned.");
michael@0 70 },
michael@0 71 handleCompletion: function(aReason) {
michael@0 72 do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED);
michael@0 73 deferred.resolve();
michael@0 74 }
michael@0 75 });
michael@0 76 stmt.finalize();
michael@0 77 });
michael@0 78 yield deferred.promise;
michael@0 79 });

mercurial