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: const Ci = Components.interfaces; michael@0: const Cc = Components.classes; michael@0: const Cr = Components.results; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: // Import common head. michael@0: let (commonFile = do_get_file("../head_common.js", false)) { michael@0: let uri = Services.io.newFileURI(commonFile); michael@0: Services.scriptloader.loadSubScript(uri.spec, this); michael@0: } michael@0: michael@0: // Put any other stuff relative to this test folder below. michael@0: michael@0: michael@0: // Simulates an expiration at shutdown. michael@0: function shutdownExpiration() michael@0: { michael@0: let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver); michael@0: expire.observe(null, "places-will-close-connection", null); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Causes expiration component to start, otherwise it would wait for the first michael@0: * history notification. michael@0: */ michael@0: function force_expiration_start() { michael@0: Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsISupports); michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Forces an expiration run. michael@0: * michael@0: * @param [optional] aLimit michael@0: * Limit for the expiration. Pass -1 for unlimited. michael@0: * Any other non-positive value will just expire orphans. michael@0: * michael@0: * @return {Promise} michael@0: * @resolves When expiration finishes. michael@0: * @rejects Never. michael@0: */ michael@0: function promiseForceExpirationStep(aLimit) { michael@0: let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); michael@0: let expire = Cc["@mozilla.org/places/expiration;1"].getService(Ci.nsIObserver); michael@0: expire.observe(null, "places-debug-start-expiration", aLimit); michael@0: return promise; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Expiration preferences helpers. michael@0: */ michael@0: michael@0: function setInterval(aNewInterval) { michael@0: Services.prefs.setIntPref("places.history.expiration.interval_seconds", aNewInterval); michael@0: } michael@0: function getInterval() { michael@0: return Services.prefs.getIntPref("places.history.expiration.interval_seconds"); michael@0: } michael@0: function clearInterval() { michael@0: try { michael@0: Services.prefs.clearUserPref("places.history.expiration.interval_seconds"); michael@0: } michael@0: catch(ex) {} michael@0: } michael@0: michael@0: michael@0: function setMaxPages(aNewMaxPages) { michael@0: Services.prefs.setIntPref("places.history.expiration.max_pages", aNewMaxPages); michael@0: } michael@0: function getMaxPages() { michael@0: return Services.prefs.getIntPref("places.history.expiration.max_pages"); michael@0: } michael@0: function clearMaxPages() { michael@0: try { michael@0: Services.prefs.clearUserPref("places.history.expiration.max_pages"); michael@0: } michael@0: catch(ex) {} michael@0: } michael@0: michael@0: michael@0: function setHistoryEnabled(aHistoryEnabled) { michael@0: Services.prefs.setBoolPref("places.history.enabled", aHistoryEnabled); michael@0: } michael@0: function getHistoryEnabled() { michael@0: return Services.prefs.getBoolPref("places.history.enabled"); michael@0: } michael@0: function clearHistoryEnabled() { michael@0: try { michael@0: Services.prefs.clearUserPref("places.history.enabled"); michael@0: } michael@0: catch(ex) {} michael@0: } michael@0: michael@0: /** michael@0: * Returns a PRTime in the past usable to add expirable visits. michael@0: * michael@0: * @note Expiration ignores any visit added in the last 7 days, but it's michael@0: * better be safe against DST issues, by going back one day more. michael@0: */ michael@0: function getExpirablePRTime() { michael@0: let dateObj = new Date(); michael@0: // Normalize to midnight michael@0: dateObj.setHours(0); michael@0: dateObj.setMinutes(0); michael@0: dateObj.setSeconds(0); michael@0: dateObj.setMilliseconds(0); michael@0: dateObj = new Date(dateObj.getTime() - 8 * 86400000); michael@0: return dateObj.getTime() * 1000; michael@0: }