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: * Session annotations should be expired when browsing session ends. 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_session() { michael@0: // Set interval to a large value so we don't expire on it. michael@0: setInterval(3600); // 1h michael@0: michael@0: // Add some visited page and a couple session annotations for each. michael@0: let now = Date.now() * 1000; michael@0: for (let i = 0; i < 10; i++) { michael@0: let pageURI = uri("http://session_page_anno." + i + ".mozilla.org/"); michael@0: yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); michael@0: as.setPageAnnotation(pageURI, "test1", "test", 0, as.EXPIRE_SESSION); michael@0: as.setPageAnnotation(pageURI, "test2", "test", 0, as.EXPIRE_SESSION); michael@0: } michael@0: michael@0: // Add some bookmarked page and a couple session annotations for each. michael@0: for (let i = 0; i < 10; i++) { michael@0: let pageURI = uri("http://session_item_anno." + i + ".mozilla.org/"); michael@0: let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI, michael@0: bs.DEFAULT_INDEX, null); michael@0: as.setItemAnnotation(id, "test1", "test", 0, as.EXPIRE_SESSION); michael@0: as.setItemAnnotation(id, "test2", "test", 0, as.EXPIRE_SESSION); michael@0: } michael@0: michael@0: michael@0: let pages = as.getPagesWithAnnotation("test1"); michael@0: do_check_eq(pages.length, 10); michael@0: pages = as.getPagesWithAnnotation("test2"); michael@0: do_check_eq(pages.length, 10); michael@0: let items = as.getItemsWithAnnotation("test1"); michael@0: do_check_eq(items.length, 10); michael@0: items = as.getItemsWithAnnotation("test2"); michael@0: do_check_eq(items.length, 10); michael@0: michael@0: let deferred = Promise.defer(); michael@0: waitForConnectionClosed(function() { michael@0: let stmt = DBConn(true).createAsyncStatement( michael@0: "SELECT id FROM moz_annos " michael@0: + "UNION ALL " michael@0: + "SELECT id FROM moz_items_annos " michael@0: ); michael@0: stmt.executeAsync({ michael@0: handleResult: function(aResultSet) { michael@0: dump_table("moz_annos"); michael@0: dump_table("moz_items_annos"); michael@0: do_throw("Should not find any leftover session annotations"); michael@0: }, michael@0: handleError: function(aError) { michael@0: do_throw("Error code " + aError.result + " with message '" + michael@0: aError.message + "' returned."); michael@0: }, michael@0: handleCompletion: function(aReason) { michael@0: do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED); michael@0: deferred.resolve(); michael@0: } michael@0: }); michael@0: stmt.finalize(); michael@0: }); michael@0: yield deferred.promise; michael@0: });