Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /** |
michael@0 | 8 | * What this is aimed to test: |
michael@0 | 9 | * |
michael@0 | 10 | * Expiring a full page should fire an onDeleteURI notification. |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | let hs = Cc["@mozilla.org/browser/nav-history-service;1"]. |
michael@0 | 14 | getService(Ci.nsINavHistoryService); |
michael@0 | 15 | let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. |
michael@0 | 16 | getService(Ci.nsINavBookmarksService); |
michael@0 | 17 | |
michael@0 | 18 | let tests = [ |
michael@0 | 19 | |
michael@0 | 20 | { desc: "Add 1 bookmarked page.", |
michael@0 | 21 | addPages: 1, |
michael@0 | 22 | addBookmarks: 1, |
michael@0 | 23 | expectedNotifications: 0, // No expirable pages. |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | { desc: "Add 2 pages, 1 bookmarked.", |
michael@0 | 27 | addPages: 2, |
michael@0 | 28 | addBookmarks: 1, |
michael@0 | 29 | expectedNotifications: 1, // Only one expirable page. |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | { desc: "Add 10 pages, none bookmarked.", |
michael@0 | 33 | addPages: 10, |
michael@0 | 34 | addBookmarks: 0, |
michael@0 | 35 | expectedNotifications: 10, // Will expire everything. |
michael@0 | 36 | }, |
michael@0 | 37 | |
michael@0 | 38 | { desc: "Add 10 pages, all bookmarked.", |
michael@0 | 39 | addPages: 10, |
michael@0 | 40 | addBookmarks: 10, |
michael@0 | 41 | expectedNotifications: 0, // No expirable pages. |
michael@0 | 42 | }, |
michael@0 | 43 | |
michael@0 | 44 | ]; |
michael@0 | 45 | |
michael@0 | 46 | function run_test() { |
michael@0 | 47 | run_next_test(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | add_task(function test_notifications_onDeleteURI() { |
michael@0 | 51 | // Set interval to a large value so we don't expire on it. |
michael@0 | 52 | setInterval(3600); // 1h |
michael@0 | 53 | |
michael@0 | 54 | // Expire anything that is expirable. |
michael@0 | 55 | setMaxPages(0); |
michael@0 | 56 | |
michael@0 | 57 | for (let testIndex = 1; testIndex <= tests.length; testIndex++) { |
michael@0 | 58 | let currentTest = tests[testIndex -1]; |
michael@0 | 59 | print("\nTEST " + testIndex + ": " + currentTest.desc); |
michael@0 | 60 | currentTest.receivedNotifications = 0; |
michael@0 | 61 | |
michael@0 | 62 | // Setup visits. |
michael@0 | 63 | let now = getExpirablePRTime(); |
michael@0 | 64 | for (let i = 0; i < currentTest.addPages; i++) { |
michael@0 | 65 | let page = "http://" + testIndex + "." + i + ".mozilla.org/"; |
michael@0 | 66 | yield promiseAddVisits({ uri: uri(page), visitDate: now++ }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | // Setup bookmarks. |
michael@0 | 70 | currentTest.bookmarks = []; |
michael@0 | 71 | for (let i = 0; i < currentTest.addBookmarks; i++) { |
michael@0 | 72 | let page = "http://" + testIndex + "." + i + ".mozilla.org/"; |
michael@0 | 73 | bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page), |
michael@0 | 74 | bs.DEFAULT_INDEX, null); |
michael@0 | 75 | currentTest.bookmarks.push(page); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | // Observe history. |
michael@0 | 79 | historyObserver = { |
michael@0 | 80 | onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {}, |
michael@0 | 81 | onEndUpdateBatch: function PEX_onEndUpdateBatch() {}, |
michael@0 | 82 | onClearHistory: function() {}, |
michael@0 | 83 | onVisit: function() {}, |
michael@0 | 84 | onTitleChanged: function() {}, |
michael@0 | 85 | onDeleteURI: function(aURI, aGUID, aReason) { |
michael@0 | 86 | currentTest.receivedNotifications++; |
michael@0 | 87 | // Check this uri was not bookmarked. |
michael@0 | 88 | do_check_eq(currentTest.bookmarks.indexOf(aURI.spec), -1); |
michael@0 | 89 | do_check_valid_places_guid(aGUID); |
michael@0 | 90 | do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED); |
michael@0 | 91 | }, |
michael@0 | 92 | onPageChanged: function() {}, |
michael@0 | 93 | onDeleteVisits: function(aURI, aTime) { }, |
michael@0 | 94 | }; |
michael@0 | 95 | hs.addObserver(historyObserver, false); |
michael@0 | 96 | |
michael@0 | 97 | // Expire now. |
michael@0 | 98 | yield promiseForceExpirationStep(-1); |
michael@0 | 99 | |
michael@0 | 100 | hs.removeObserver(historyObserver, false); |
michael@0 | 101 | |
michael@0 | 102 | do_check_eq(currentTest.receivedNotifications, |
michael@0 | 103 | currentTest.expectedNotifications); |
michael@0 | 104 | |
michael@0 | 105 | // Clean up. |
michael@0 | 106 | bs.removeFolderChildren(bs.unfiledBookmarksFolder); |
michael@0 | 107 | yield promiseClearHistory(); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | clearMaxPages(); |
michael@0 | 111 | bs.removeFolderChildren(bs.unfiledBookmarksFolder); |
michael@0 | 112 | yield promiseClearHistory(); |
michael@0 | 113 | }); |