|
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/. */ |
|
6 |
|
7 /** |
|
8 * What this is aimed to test: |
|
9 * |
|
10 * Expiring a full page should fire an onDeleteURI notification. |
|
11 */ |
|
12 |
|
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); |
|
17 |
|
18 let tests = [ |
|
19 |
|
20 { desc: "Add 1 bookmarked page.", |
|
21 addPages: 1, |
|
22 addBookmarks: 1, |
|
23 expectedNotifications: 0, // No expirable pages. |
|
24 }, |
|
25 |
|
26 { desc: "Add 2 pages, 1 bookmarked.", |
|
27 addPages: 2, |
|
28 addBookmarks: 1, |
|
29 expectedNotifications: 1, // Only one expirable page. |
|
30 }, |
|
31 |
|
32 { desc: "Add 10 pages, none bookmarked.", |
|
33 addPages: 10, |
|
34 addBookmarks: 0, |
|
35 expectedNotifications: 10, // Will expire everything. |
|
36 }, |
|
37 |
|
38 { desc: "Add 10 pages, all bookmarked.", |
|
39 addPages: 10, |
|
40 addBookmarks: 10, |
|
41 expectedNotifications: 0, // No expirable pages. |
|
42 }, |
|
43 |
|
44 ]; |
|
45 |
|
46 function run_test() { |
|
47 run_next_test(); |
|
48 } |
|
49 |
|
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 |
|
53 |
|
54 // Expire anything that is expirable. |
|
55 setMaxPages(0); |
|
56 |
|
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; |
|
61 |
|
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 } |
|
68 |
|
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 } |
|
77 |
|
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); |
|
96 |
|
97 // Expire now. |
|
98 yield promiseForceExpirationStep(-1); |
|
99 |
|
100 hs.removeObserver(historyObserver, false); |
|
101 |
|
102 do_check_eq(currentTest.receivedNotifications, |
|
103 currentTest.expectedNotifications); |
|
104 |
|
105 // Clean up. |
|
106 bs.removeFolderChildren(bs.unfiledBookmarksFolder); |
|
107 yield promiseClearHistory(); |
|
108 } |
|
109 |
|
110 clearMaxPages(); |
|
111 bs.removeFolderChildren(bs.unfiledBookmarksFolder); |
|
112 yield promiseClearHistory(); |
|
113 }); |