|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et: */ |
|
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 const TEST_URI = NetUtil.newURI("http://mozilla.com/"); |
|
8 const TEST_SUBDOMAIN_URI = NetUtil.newURI("http://foobar.mozilla.com/"); |
|
9 |
|
10 add_test(function test_addPage() |
|
11 { |
|
12 promiseAddVisits(TEST_URI).then(function () { |
|
13 do_check_eq(1, PlacesUtils.history.hasHistoryEntries); |
|
14 run_next_test(); |
|
15 }); |
|
16 }); |
|
17 |
|
18 add_test(function test_removePage() |
|
19 { |
|
20 PlacesUtils.bhistory.removePage(TEST_URI); |
|
21 do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
|
22 run_next_test(); |
|
23 }); |
|
24 |
|
25 add_test(function test_removePages() |
|
26 { |
|
27 let pages = []; |
|
28 for (let i = 0; i < 8; i++) { |
|
29 pages.push(NetUtil.newURI(TEST_URI.spec + i)); |
|
30 } |
|
31 |
|
32 promiseAddVisits(pages.map(function (uri) ({ uri: uri }))).then(function () { |
|
33 // Bookmarked item should not be removed from moz_places. |
|
34 const ANNO_INDEX = 1; |
|
35 const ANNO_NAME = "testAnno"; |
|
36 const ANNO_VALUE = "foo"; |
|
37 const BOOKMARK_INDEX = 2; |
|
38 PlacesUtils.annotations.setPageAnnotation(pages[ANNO_INDEX], |
|
39 ANNO_NAME, ANNO_VALUE, 0, |
|
40 Ci.nsIAnnotationService.EXPIRE_NEVER); |
|
41 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId, |
|
42 pages[BOOKMARK_INDEX], |
|
43 PlacesUtils.bookmarks.DEFAULT_INDEX, |
|
44 "test bookmark"); |
|
45 PlacesUtils.annotations.setPageAnnotation(pages[BOOKMARK_INDEX], |
|
46 ANNO_NAME, ANNO_VALUE, 0, |
|
47 Ci.nsIAnnotationService.EXPIRE_NEVER); |
|
48 |
|
49 PlacesUtils.bhistory.removePages(pages, pages.length); |
|
50 do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
|
51 |
|
52 // Check that the bookmark and its annotation still exist. |
|
53 do_check_true(PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.unfiledBookmarksFolderId, 0) > 0); |
|
54 do_check_eq(PlacesUtils.annotations.getPageAnnotation(pages[BOOKMARK_INDEX], ANNO_NAME), |
|
55 ANNO_VALUE); |
|
56 |
|
57 // Check the annotation on the non-bookmarked page does not exist anymore. |
|
58 try { |
|
59 PlacesUtils.annotations.getPageAnnotation(pages[ANNO_INDEX], ANNO_NAME); |
|
60 do_throw("did not expire expire_never anno on a not bookmarked item"); |
|
61 } catch(ex) {} |
|
62 |
|
63 // Cleanup. |
|
64 PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); |
|
65 promiseClearHistory().then(run_next_test); |
|
66 }); |
|
67 }); |
|
68 |
|
69 add_test(function test_removePagesByTimeframe() |
|
70 { |
|
71 let visits = []; |
|
72 let startDate = Date.now() * 1000; |
|
73 for (let i = 0; i < 10; i++) { |
|
74 visits.push({ |
|
75 uri: NetUtil.newURI(TEST_URI.spec + i), |
|
76 visitDate: startDate + i |
|
77 }); |
|
78 } |
|
79 |
|
80 promiseAddVisits(visits).then(function () { |
|
81 // Delete all pages except the first and the last. |
|
82 PlacesUtils.bhistory.removePagesByTimeframe(startDate + 1, startDate + 8); |
|
83 |
|
84 // Check that we have removed the correct pages. |
|
85 for (let i = 0; i < 10; i++) { |
|
86 do_check_eq(page_in_database(NetUtil.newURI(TEST_URI.spec + i)) == 0, |
|
87 i > 0 && i < 9); |
|
88 } |
|
89 |
|
90 // Clear remaining items and check that all pages have been removed. |
|
91 PlacesUtils.bhistory.removePagesByTimeframe(startDate, startDate + 9); |
|
92 do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
|
93 run_next_test(); |
|
94 }); |
|
95 }); |
|
96 |
|
97 add_test(function test_removePagesFromHost() |
|
98 { |
|
99 promiseAddVisits(TEST_URI).then(function () { |
|
100 PlacesUtils.bhistory.removePagesFromHost("mozilla.com", true); |
|
101 do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
|
102 run_next_test(); |
|
103 }); |
|
104 }); |
|
105 |
|
106 add_test(function test_removePagesFromHost_keepSubdomains() |
|
107 { |
|
108 promiseAddVisits([{ uri: TEST_URI }, { uri: TEST_SUBDOMAIN_URI }]).then(function () { |
|
109 PlacesUtils.bhistory.removePagesFromHost("mozilla.com", false); |
|
110 do_check_eq(1, PlacesUtils.history.hasHistoryEntries); |
|
111 run_next_test(); |
|
112 }); |
|
113 }); |
|
114 |
|
115 add_test(function test_removeAllPages() |
|
116 { |
|
117 PlacesUtils.bhistory.removeAllPages(); |
|
118 do_check_eq(0, PlacesUtils.history.hasHistoryEntries); |
|
119 run_next_test(); |
|
120 }); |
|
121 |
|
122 function run_test() |
|
123 { |
|
124 run_next_test(); |
|
125 } |