1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/expiration/test_annos_expire_session.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +/** 1.11 + * What this is aimed to test: 1.12 + * 1.13 + * Session annotations should be expired when browsing session ends. 1.14 + */ 1.15 + 1.16 +let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.17 + getService(Ci.nsINavBookmarksService); 1.18 +let as = Cc["@mozilla.org/browser/annotation-service;1"]. 1.19 + getService(Ci.nsIAnnotationService); 1.20 + 1.21 +function run_test() { 1.22 + run_next_test(); 1.23 +} 1.24 + 1.25 +add_task(function test_annos_expire_session() { 1.26 + // Set interval to a large value so we don't expire on it. 1.27 + setInterval(3600); // 1h 1.28 + 1.29 + // Add some visited page and a couple session annotations for each. 1.30 + let now = Date.now() * 1000; 1.31 + for (let i = 0; i < 10; i++) { 1.32 + let pageURI = uri("http://session_page_anno." + i + ".mozilla.org/"); 1.33 + yield promiseAddVisits({ uri: pageURI, visitDate: now++ }); 1.34 + as.setPageAnnotation(pageURI, "test1", "test", 0, as.EXPIRE_SESSION); 1.35 + as.setPageAnnotation(pageURI, "test2", "test", 0, as.EXPIRE_SESSION); 1.36 + } 1.37 + 1.38 + // Add some bookmarked page and a couple session annotations for each. 1.39 + for (let i = 0; i < 10; i++) { 1.40 + let pageURI = uri("http://session_item_anno." + i + ".mozilla.org/"); 1.41 + let id = bs.insertBookmark(bs.unfiledBookmarksFolder, pageURI, 1.42 + bs.DEFAULT_INDEX, null); 1.43 + as.setItemAnnotation(id, "test1", "test", 0, as.EXPIRE_SESSION); 1.44 + as.setItemAnnotation(id, "test2", "test", 0, as.EXPIRE_SESSION); 1.45 + } 1.46 + 1.47 + 1.48 + let pages = as.getPagesWithAnnotation("test1"); 1.49 + do_check_eq(pages.length, 10); 1.50 + pages = as.getPagesWithAnnotation("test2"); 1.51 + do_check_eq(pages.length, 10); 1.52 + let items = as.getItemsWithAnnotation("test1"); 1.53 + do_check_eq(items.length, 10); 1.54 + items = as.getItemsWithAnnotation("test2"); 1.55 + do_check_eq(items.length, 10); 1.56 + 1.57 + let deferred = Promise.defer(); 1.58 + waitForConnectionClosed(function() { 1.59 + let stmt = DBConn(true).createAsyncStatement( 1.60 + "SELECT id FROM moz_annos " 1.61 + + "UNION ALL " 1.62 + + "SELECT id FROM moz_items_annos " 1.63 + ); 1.64 + stmt.executeAsync({ 1.65 + handleResult: function(aResultSet) { 1.66 + dump_table("moz_annos"); 1.67 + dump_table("moz_items_annos"); 1.68 + do_throw("Should not find any leftover session annotations"); 1.69 + }, 1.70 + handleError: function(aError) { 1.71 + do_throw("Error code " + aError.result + " with message '" + 1.72 + aError.message + "' returned."); 1.73 + }, 1.74 + handleCompletion: function(aReason) { 1.75 + do_check_eq(aReason, Ci.mozIStorageStatementCallback.REASON_FINISHED); 1.76 + deferred.resolve(); 1.77 + } 1.78 + }); 1.79 + stmt.finalize(); 1.80 + }); 1.81 + yield deferred.promise; 1.82 +});