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