|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests that nsBrowserGlue does not overwrite bookmarks imported from the |
|
6 * migrators. They usually run before nsBrowserGlue, so if we find any |
|
7 * bookmark on init, we should not try to import. |
|
8 */ |
|
9 |
|
10 const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; |
|
11 |
|
12 function run_test() { |
|
13 do_test_pending(); |
|
14 |
|
15 // Create our bookmarks.html copying bookmarks.glue.html to the profile |
|
16 // folder. It should be ignored. |
|
17 create_bookmarks_html("bookmarks.glue.html"); |
|
18 |
|
19 // Remove current database file. |
|
20 let db = gProfD.clone(); |
|
21 db.append("places.sqlite"); |
|
22 if (db.exists()) { |
|
23 db.remove(false); |
|
24 do_check_false(db.exists()); |
|
25 } |
|
26 |
|
27 // Initialize Places through the History Service and check that a new |
|
28 // database has been created. |
|
29 do_check_eq(PlacesUtils.history.databaseStatus, |
|
30 PlacesUtils.history.DATABASE_STATUS_CREATE); |
|
31 |
|
32 // A migrator would run before nsBrowserGlue Places initialization, so mimic |
|
33 // that behavior adding a bookmark and notifying the migration. |
|
34 let bg = Cc["@mozilla.org/browser/browserglue;1"]. |
|
35 getService(Ci.nsIObserver); |
|
36 |
|
37 bg.observe(null, "initial-migration-will-import-default-bookmarks", null); |
|
38 |
|
39 PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"), |
|
40 PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated"); |
|
41 |
|
42 let bookmarksObserver = { |
|
43 onBeginUpdateBatch: function() {}, |
|
44 onEndUpdateBatch: function() { |
|
45 // Check if the currently finished batch created the smart bookmarks. |
|
46 let itemId = |
|
47 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); |
|
48 do_check_neq(itemId, -1); |
|
49 if (PlacesUtils.annotations |
|
50 .itemHasAnnotation(itemId, "Places/SmartBookmark")) { |
|
51 do_execute_soon(onSmartBookmarksCreation); |
|
52 } |
|
53 }, |
|
54 onItemAdded: function() {}, |
|
55 onItemRemoved: function(id, folder, index, itemType) {}, |
|
56 onItemChanged: function() {}, |
|
57 onItemVisited: function(id, visitID, time) {}, |
|
58 onItemMoved: function() {}, |
|
59 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) |
|
60 }; |
|
61 // The test will continue once import has finished and smart bookmarks |
|
62 // have been created. |
|
63 PlacesUtils.bookmarks.addObserver(bookmarksObserver, false); |
|
64 |
|
65 bg.observe(null, "initial-migration-did-import-default-bookmarks", null); |
|
66 } |
|
67 |
|
68 function onSmartBookmarksCreation() { |
|
69 // Check the created bookmarks still exist. |
|
70 let itemId = |
|
71 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, |
|
72 SMART_BOOKMARKS_ON_MENU); |
|
73 do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated"); |
|
74 |
|
75 // Check that we have not imported any new bookmark. |
|
76 itemId = |
|
77 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, |
|
78 SMART_BOOKMARKS_ON_MENU + 1) |
|
79 do_check_eq(itemId, -1); |
|
80 itemId = |
|
81 PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, |
|
82 SMART_BOOKMARKS_ON_MENU) |
|
83 do_check_eq(itemId, -1); |
|
84 |
|
85 remove_bookmarks_html(); |
|
86 |
|
87 do_test_finished(); |
|
88 } |