toolkit/components/places/tests/expiration/test_notifications_onDeleteVisits.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 only visits for a page, but not the full page, should fire an
michael@0 11 * onDeleteVisits notification.
michael@0 12 */
michael@0 13
michael@0 14 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 15 getService(Ci.nsINavHistoryService);
michael@0 16 let bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
michael@0 17 getService(Ci.nsINavBookmarksService);
michael@0 18
michael@0 19 let tests = [
michael@0 20
michael@0 21 { desc: "Add 1 bookmarked page.",
michael@0 22 addPages: 1,
michael@0 23 visitsPerPage: 1,
michael@0 24 addBookmarks: 1,
michael@0 25 limitExpiration: -1,
michael@0 26 expectedNotifications: 1, // Will expire visits for 1 page.
michael@0 27 },
michael@0 28
michael@0 29 { desc: "Add 2 pages, 1 bookmarked.",
michael@0 30 addPages: 2,
michael@0 31 visitsPerPage: 1,
michael@0 32 addBookmarks: 1,
michael@0 33 limitExpiration: -1,
michael@0 34 expectedNotifications: 1, // Will expire visits for 1 page.
michael@0 35 },
michael@0 36
michael@0 37 { desc: "Add 10 pages, none bookmarked.",
michael@0 38 addPages: 10,
michael@0 39 visitsPerPage: 1,
michael@0 40 addBookmarks: 0,
michael@0 41 limitExpiration: -1,
michael@0 42 expectedNotifications: 0, // Will expire only full pages.
michael@0 43 },
michael@0 44
michael@0 45 { desc: "Add 10 pages, all bookmarked.",
michael@0 46 addPages: 10,
michael@0 47 visitsPerPage: 1,
michael@0 48 addBookmarks: 10,
michael@0 49 limitExpiration: -1,
michael@0 50 expectedNotifications: 10, // Will expire visist for all pages.
michael@0 51 },
michael@0 52
michael@0 53 { desc: "Add 10 pages with lot of visits, none bookmarked.",
michael@0 54 addPages: 10,
michael@0 55 visitsPerPage: 10,
michael@0 56 addBookmarks: 0,
michael@0 57 limitExpiration: 10,
michael@0 58 expectedNotifications: 10, // Will expire 1 visist for each page, but won't
michael@0 59 }, // expire pages since they still have visits.
michael@0 60
michael@0 61 ];
michael@0 62
michael@0 63 function run_test() {
michael@0 64 run_next_test();
michael@0 65 }
michael@0 66
michael@0 67 add_task(function test_notifications_onDeleteVisits() {
michael@0 68 // Set interval to a large value so we don't expire on it.
michael@0 69 setInterval(3600); // 1h
michael@0 70
michael@0 71 // Expire anything that is expirable.
michael@0 72 setMaxPages(0);
michael@0 73
michael@0 74 for (let testIndex = 1; testIndex <= tests.length; testIndex++) {
michael@0 75 let currentTest = tests[testIndex -1];
michael@0 76 print("\nTEST " + testIndex + ": " + currentTest.desc);
michael@0 77 currentTest.receivedNotifications = 0;
michael@0 78
michael@0 79 // Setup visits.
michael@0 80 let now = getExpirablePRTime();
michael@0 81 for (let j = 0; j < currentTest.visitsPerPage; j++) {
michael@0 82 for (let i = 0; i < currentTest.addPages; i++) {
michael@0 83 let page = "http://" + testIndex + "." + i + ".mozilla.org/";
michael@0 84 yield promiseAddVisits({ uri: uri(page), visitDate: now++ });
michael@0 85 }
michael@0 86 }
michael@0 87
michael@0 88 // Setup bookmarks.
michael@0 89 currentTest.bookmarks = [];
michael@0 90 for (let i = 0; i < currentTest.addBookmarks; i++) {
michael@0 91 let page = "http://" + testIndex + "." + i + ".mozilla.org/";
michael@0 92 bs.insertBookmark(bs.unfiledBookmarksFolder, uri(page),
michael@0 93 bs.DEFAULT_INDEX, null);
michael@0 94 currentTest.bookmarks.push(page);
michael@0 95 }
michael@0 96
michael@0 97 // Observe history.
michael@0 98 historyObserver = {
michael@0 99 onBeginUpdateBatch: function PEX_onBeginUpdateBatch() {},
michael@0 100 onEndUpdateBatch: function PEX_onEndUpdateBatch() {},
michael@0 101 onClearHistory: function() {},
michael@0 102 onVisit: function() {},
michael@0 103 onTitleChanged: function() {},
michael@0 104 onDeleteURI: function(aURI, aGUID, aReason) {
michael@0 105 // Check this uri was not bookmarked.
michael@0 106 do_check_eq(currentTest.bookmarks.indexOf(aURI.spec), -1);
michael@0 107 do_check_valid_places_guid(aGUID);
michael@0 108 do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED);
michael@0 109 },
michael@0 110 onPageChanged: function() {},
michael@0 111 onDeleteVisits: function(aURI, aTime, aGUID, aReason) {
michael@0 112 currentTest.receivedNotifications++;
michael@0 113 do_check_guid_for_uri(aURI, aGUID);
michael@0 114 do_check_eq(aReason, Ci.nsINavHistoryObserver.REASON_EXPIRED);
michael@0 115 },
michael@0 116 };
michael@0 117 hs.addObserver(historyObserver, false);
michael@0 118
michael@0 119 // Expire now.
michael@0 120 yield promiseForceExpirationStep(currentTest.limitExpiration);
michael@0 121
michael@0 122 hs.removeObserver(historyObserver, false);
michael@0 123
michael@0 124 do_check_eq(currentTest.receivedNotifications,
michael@0 125 currentTest.expectedNotifications);
michael@0 126
michael@0 127 // Clean up.
michael@0 128 bs.removeFolderChildren(bs.unfiledBookmarksFolder);
michael@0 129 yield promiseClearHistory();
michael@0 130 }
michael@0 131
michael@0 132 clearMaxPages();
michael@0 133 bs.removeFolderChildren(bs.unfiledBookmarksFolder);
michael@0 134 yield promiseClearHistory();
michael@0 135 });

mercurial