|
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 |
|
8 const SMART_BOOKMARKS_ANNO = "Places/SmartBookmark"; |
|
9 const SMART_BOOKMARKS_PREF = "browser.places.smartBookmarksVersion"; |
|
10 |
|
11 let gluesvc = Cc["@mozilla.org/browser/browserglue;1"]. |
|
12 getService(Ci.nsIBrowserGlue). |
|
13 QueryInterface(Ci.nsIObserver); |
|
14 // Avoid default bookmarks import. |
|
15 gluesvc.observe(null, "initial-migration-will-import-default-bookmarks", ""); |
|
16 |
|
17 function run_test() { |
|
18 run_next_test(); |
|
19 } |
|
20 |
|
21 add_task(function smart_bookmarks_disabled() { |
|
22 Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1); |
|
23 gluesvc.ensurePlacesDefaultQueriesInitialized(); |
|
24 let smartBookmarkItemIds = |
|
25 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
26 do_check_eq(smartBookmarkItemIds.length, 0); |
|
27 do_log_info("check that pref has not been bumped up"); |
|
28 do_check_eq(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), -1); |
|
29 }); |
|
30 |
|
31 add_task(function create_smart_bookmarks() { |
|
32 Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); |
|
33 gluesvc.ensurePlacesDefaultQueriesInitialized(); |
|
34 let smartBookmarkItemIds = |
|
35 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
36 do_check_neq(smartBookmarkItemIds.length, 0); |
|
37 do_log_info("check that pref has been bumped up"); |
|
38 do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); |
|
39 }); |
|
40 |
|
41 add_task(function remove_smart_bookmark_and_restore() { |
|
42 let smartBookmarkItemIds = |
|
43 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
44 let smartBookmarksCount = smartBookmarkItemIds.length; |
|
45 do_log_info("remove one smart bookmark and restore"); |
|
46 PlacesUtils.bookmarks.removeItem(smartBookmarkItemIds[0]); |
|
47 Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); |
|
48 gluesvc.ensurePlacesDefaultQueriesInitialized(); |
|
49 let smartBookmarkItemIds = |
|
50 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
51 do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); |
|
52 do_log_info("check that pref has been bumped up"); |
|
53 do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); |
|
54 }); |
|
55 |
|
56 add_task(function move_smart_bookmark_rename_and_restore() { |
|
57 let smartBookmarkItemIds = |
|
58 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
59 let smartBookmarksCount = smartBookmarkItemIds.length; |
|
60 do_log_info("smart bookmark should be restored in place"); |
|
61 let parent = PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]); |
|
62 let oldTitle = PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]); |
|
63 // create a subfolder and move inside it |
|
64 let newParent = |
|
65 PlacesUtils.bookmarks.createFolder(parent, "test", |
|
66 PlacesUtils.bookmarks.DEFAULT_INDEX); |
|
67 PlacesUtils.bookmarks.moveItem(smartBookmarkItemIds[0], newParent, |
|
68 PlacesUtils.bookmarks.DEFAULT_INDEX); |
|
69 // change title |
|
70 PlacesUtils.bookmarks.setItemTitle(smartBookmarkItemIds[0], "new title"); |
|
71 // restore |
|
72 Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0); |
|
73 gluesvc.ensurePlacesDefaultQueriesInitialized(); |
|
74 smartBookmarkItemIds = |
|
75 PlacesUtils.annotations.getItemsWithAnnotation(SMART_BOOKMARKS_ANNO); |
|
76 do_check_eq(smartBookmarkItemIds.length, smartBookmarksCount); |
|
77 do_check_eq(PlacesUtils.bookmarks.getFolderIdForItem(smartBookmarkItemIds[0]), newParent); |
|
78 do_check_eq(PlacesUtils.bookmarks.getItemTitle(smartBookmarkItemIds[0]), oldTitle); |
|
79 do_log_info("check that pref has been bumped up"); |
|
80 do_check_true(Services.prefs.getIntPref("browser.places.smartBookmarksVersion") > 0); |
|
81 }); |