1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/expiration/test_notifications_onDeleteURI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,113 @@ 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 + * Expiring a full page should fire an onDeleteURI notification. 1.14 + */ 1.15 + 1.16 +let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.17 + getService(Ci.nsINavHistoryService); 1.18 +let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.19 + getService(Ci.nsINavBookmarksService); 1.20 + 1.21 +let tests = [ 1.22 + 1.23 + { desc: "Add 1 bookmarked page.", 1.24 + addPages: 1, 1.25 + addBookmarks: 1, 1.26 + expectedNotifications: 0, // No expirable pages. 1.27 + }, 1.28 + 1.29 + { desc: "Add 2 pages, 1 bookmarked.", 1.30 + addPages: 2, 1.31 + addBookmarks: 1, 1.32 + expectedNotifications: 1, // Only one expirable page. 1.33 + }, 1.34 + 1.35 + { desc: "Add 10 pages, none bookmarked.", 1.36 + addPages: 10, 1.37 + addBookmarks: 0, 1.38 + expectedNotifications: 10, // Will expire everything. 1.39 + }, 1.40 + 1.41 + { desc: "Add 10 pages, all bookmarked.", 1.42 + addPages: 10, 1.43 + addBookmarks: 10, 1.44 + expectedNotifications: 0, // No expirable pages. 1.45 + }, 1.46 + 1.47 +]; 1.48 + 1.49 +function run_test() { 1.50 + run_next_test(); 1.51 +} 1.52 + 1.53 +add_task(function test_notifications_onDeleteURI() { 1.54 + // Set interval to a large value so we don't expire on it. 1.55 + setInterval(3600); // 1h 1.56 + 1.57 + // Expire anything that is expirable. 1.58 + setMaxPages(0); 1.59 + 1.60 + for (let testIndex = 1; testIndex <= tests.length; testIndex++) { 1.61 + let currentTest = tests[testIndex -1]; 1.62 + print("\nTEST " + testIndex + ": " + currentTest.desc); 1.63 + currentTest.receivedNotifications = 0; 1.64 + 1.65 + // Setup visits. 1.66 + let now = getExpirablePRTime(); 1.67 + for (let i = 0; i < currentTest.addPages; i++) { 1.68 + let page = "http://" + testIndex + "." + i + ".mozilla.org/"; 1.69 + yield promiseAddVisits({ uri: uri(page), visitDate: now++ }); 1.70 + } 1.71 + 1.72 + // Setup bookmarks. 1.73 + currentTest.bookmarks = []; 1.74 + for (let i = 0; i < currentTest.addBookmarks; i++) { 1.75 + let page = "http://" + testIndex + "." + i + ".mozilla.org/"; 1.76 + bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page), 1.77 + bs.DEFAULT_INDEX, null); 1.78 + currentTest.bookmarks.push(page); 1.79 + } 1.80 + 1.81 + // Observe history. 1.82 + historyObserver = { 1.83 + onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {}, 1.84 + onEndUpdateBatch: function PEX_onEndUpdateBatch() {}, 1.85 + onClearHistory: function() {}, 1.86 + onVisit: function() {}, 1.87 + onTitleChanged: function() {}, 1.88 + onDeleteURI: function(aURI, aGUID, aReason) { 1.89 + currentTest.receivedNotifications++; 1.90 + // Check this uri was not bookmarked. 1.91 + do_check_eq(currentTest.bookmarks.indexOf(aURI.spec), -1); 1.92 + do_check_valid_places_guid(aGUID); 1.93 + do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED); 1.94 + }, 1.95 + onPageChanged: function() {}, 1.96 + onDeleteVisits: function(aURI, aTime) { }, 1.97 + }; 1.98 + hs.addObserver(historyObserver, false); 1.99 + 1.100 + // Expire now. 1.101 + yield promiseForceExpirationStep(-1); 1.102 + 1.103 + hs.removeObserver(historyObserver, false); 1.104 + 1.105 + do_check_eq(currentTest.receivedNotifications, 1.106 + currentTest.expectedNotifications); 1.107 + 1.108 + // Clean up. 1.109 + bs.removeFolderChildren(bs.unfiledBookmarksFolder); 1.110 + yield promiseClearHistory(); 1.111 + } 1.112 + 1.113 + clearMaxPages(); 1.114 + bs.removeFolderChildren(bs.unfiledBookmarksFolder); 1.115 + yield promiseClearHistory(); 1.116 +});