michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * What this is aimed to test: michael@0: * michael@0: * Expiration can be manually triggered through a debug topic, but that should michael@0: * only expire orphan entries, unless -1 is passed as limit. michael@0: */ michael@0: michael@0: let gNow = getExpirablePRTime(); michael@0: michael@0: add_task(function test_expire_orphans() michael@0: { michael@0: // Add visits to 2 pages and force a orphan expiration. Visits should survive. michael@0: yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: // Create a orphan place. michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: NetUtil.newURI("http://page3.mozilla.org/"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, ""); michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: michael@0: // Expire now. michael@0: yield promiseForceExpirationStep(0); michael@0: michael@0: // Check that visits survived. michael@0: do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1); michael@0: do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); michael@0: do_check_false(page_in_database("http://page3.mozilla.org/")); michael@0: michael@0: // Clean up. michael@0: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function test_expire_orphans_optionalarg() michael@0: { michael@0: // Add visits to 2 pages and force a orphan expiration. Visits should survive. michael@0: yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: // Create a orphan place. michael@0: let id = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, michael@0: NetUtil.newURI("http://page3.mozilla.org/"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, ""); michael@0: PlacesUtils.bookmarks.removeItem(id); michael@0: michael@0: // Expire now. michael@0: yield promiseForceExpirationStep(); michael@0: michael@0: // Check that visits survived. michael@0: do_check_eq(visits_in_database("http://page1.mozilla.org/"), 1); michael@0: do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); michael@0: do_check_false(page_in_database("http://page3.mozilla.org/")); michael@0: michael@0: // Clean up. michael@0: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function test_expire_limited() michael@0: { michael@0: // Add visits to 2 pages and force a single expiration. michael@0: // Only 1 page should survive. michael@0: yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: michael@0: // Expire now. michael@0: yield promiseForceExpirationStep(1); michael@0: michael@0: // Check that visits to the more recent page survived. michael@0: do_check_false(page_in_database("http://page1.mozilla.org/")); michael@0: do_check_eq(visits_in_database("http://page2.mozilla.org/"), 1); michael@0: michael@0: // Clean up. michael@0: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: add_task(function test_expire_unlimited() michael@0: { michael@0: // Add visits to 2 pages and force a single expiration. michael@0: // Only 1 page should survive. michael@0: yield promiseAddVisits({ uri: uri("http://page1.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: yield promiseAddVisits({ uri: uri("http://page2.mozilla.org/"), michael@0: visitDate: gNow++ }); michael@0: michael@0: // Expire now. michael@0: yield promiseForceExpirationStep(-1); michael@0: michael@0: // Check that visits to the more recent page survived. michael@0: do_check_false(page_in_database("http://page1.mozilla.org/")); michael@0: do_check_false(page_in_database("http://page2.mozilla.org/")); michael@0: michael@0: // Clean up. michael@0: yield promiseClearHistory(); michael@0: }); michael@0: michael@0: function run_test() michael@0: { michael@0: // Set interval to a large value so we don't expire on it. michael@0: setInterval(3600); // 1h michael@0: // Set maxPages to a low value, so it's easy to go over it. michael@0: setMaxPages(1); michael@0: michael@0: run_next_test(); michael@0: }