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: * Expiring a full page should fire an onDeleteURI notification. michael@0: */ michael@0: michael@0: let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. michael@0: getService(Ci.nsINavHistoryService); michael@0: let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. michael@0: getService(Ci.nsINavBookmarksService); michael@0: michael@0: let tests = [ michael@0: michael@0: { desc: "Add 1 bookmarked page.", michael@0: addPages: 1, michael@0: addBookmarks: 1, michael@0: expectedNotifications: 0, // No expirable pages. michael@0: }, michael@0: michael@0: { desc: "Add 2 pages, 1 bookmarked.", michael@0: addPages: 2, michael@0: addBookmarks: 1, michael@0: expectedNotifications: 1, // Only one expirable page. michael@0: }, michael@0: michael@0: { desc: "Add 10 pages, none bookmarked.", michael@0: addPages: 10, michael@0: addBookmarks: 0, michael@0: expectedNotifications: 10, // Will expire everything. michael@0: }, michael@0: michael@0: { desc: "Add 10 pages, all bookmarked.", michael@0: addPages: 10, michael@0: addBookmarks: 10, michael@0: expectedNotifications: 0, // No expirable pages. michael@0: }, michael@0: michael@0: ]; michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function test_notifications_onDeleteURI() { michael@0: // Set interval to a large value so we don't expire on it. michael@0: setInterval(3600); // 1h michael@0: michael@0: // Expire anything that is expirable. michael@0: setMaxPages(0); michael@0: michael@0: for (let testIndex = 1; testIndex <= tests.length; testIndex++) { michael@0: let currentTest = tests[testIndex -1]; michael@0: print("\nTEST " + testIndex + ": " + currentTest.desc); michael@0: currentTest.receivedNotifications = 0; michael@0: michael@0: // Setup visits. michael@0: let now = getExpirablePRTime(); michael@0: for (let i = 0; i < currentTest.addPages; i++) { michael@0: let page = "http://" + testIndex + "." + i + ".mozilla.org/"; michael@0: yield promiseAddVisits({ uri: uri(page), visitDate: now++ }); michael@0: } michael@0: michael@0: // Setup bookmarks. michael@0: currentTest.bookmarks = []; michael@0: for (let i = 0; i < currentTest.addBookmarks; i++) { michael@0: let page = "http://" + testIndex + "." + i + ".mozilla.org/"; michael@0: bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page), michael@0: bs.DEFAULT_INDEX, null); michael@0: currentTest.bookmarks.push(page); michael@0: } michael@0: michael@0: // Observe history. michael@0: historyObserver = { michael@0: onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {}, michael@0: onEndUpdateBatch: function PEX_onEndUpdateBatch() {}, michael@0: onClearHistory: function() {}, michael@0: onVisit: function() {}, michael@0: onTitleChanged: function() {}, michael@0: onDeleteURI: function(aURI, aGUID, aReason) { michael@0: currentTest.receivedNotifications++; michael@0: // Check this uri was not bookmarked. michael@0: do_check_eq(currentTest.bookmarks.indexOf(aURI.spec), -1); michael@0: do_check_valid_places_guid(aGUID); michael@0: do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED); michael@0: }, michael@0: onPageChanged: function() {}, michael@0: onDeleteVisits: function(aURI, aTime) { }, michael@0: }; michael@0: hs.addObserver(historyObserver, false); michael@0: michael@0: // Expire now. michael@0: yield promiseForceExpirationStep(-1); michael@0: michael@0: hs.removeObserver(historyObserver, false); michael@0: michael@0: do_check_eq(currentTest.receivedNotifications, michael@0: currentTest.expectedNotifications); michael@0: michael@0: // Clean up. michael@0: bs.removeFolderChildren(bs.unfiledBookmarksFolder); michael@0: yield promiseClearHistory(); michael@0: } michael@0: michael@0: clearMaxPages(); michael@0: bs.removeFolderChildren(bs.unfiledBookmarksFolder); michael@0: yield promiseClearHistory(); michael@0: });