michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that nsBrowserGlue does not overwrite bookmarks imported from the michael@0: * migrators. They usually run before nsBrowserGlue, so if we find any michael@0: * bookmark on init, we should not try to import. michael@0: */ michael@0: michael@0: const PREF_SMART_BOOKMARKS_VERSION = "browser.places.smartBookmarksVersion"; michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: // Create our bookmarks.html copying bookmarks.glue.html to the profile michael@0: // folder. It should be ignored. michael@0: create_bookmarks_html("bookmarks.glue.html"); michael@0: michael@0: // Remove current database file. michael@0: let db = gProfD.clone(); michael@0: db.append("places.sqlite"); michael@0: if (db.exists()) { michael@0: db.remove(false); michael@0: do_check_false(db.exists()); michael@0: } michael@0: michael@0: // Initialize Places through the History Service and check that a new michael@0: // database has been created. michael@0: do_check_eq(PlacesUtils.history.databaseStatus, michael@0: PlacesUtils.history.DATABASE_STATUS_CREATE); michael@0: michael@0: // A migrator would run before nsBrowserGlue Places initialization, so mimic michael@0: // that behavior adding a bookmark and notifying the migration. michael@0: let bg = Cc["@mozilla.org/browser/browserglue;1"]. michael@0: getService(Ci.nsIObserver); michael@0: michael@0: bg.observe(null, "initial-migration-will-import-default-bookmarks", null); michael@0: michael@0: PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder, uri("http://mozilla.org/"), michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX, "migrated"); michael@0: michael@0: let bookmarksObserver = { michael@0: onBeginUpdateBatch: function() {}, michael@0: onEndUpdateBatch: function() { michael@0: // Check if the currently finished batch created the smart bookmarks. michael@0: let itemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, 0); michael@0: do_check_neq(itemId, -1); michael@0: if (PlacesUtils.annotations michael@0: .itemHasAnnotation(itemId, "Places/SmartBookmark")) { michael@0: do_execute_soon(onSmartBookmarksCreation); michael@0: } michael@0: }, michael@0: onItemAdded: function() {}, michael@0: onItemRemoved: function(id, folder, index, itemType) {}, michael@0: onItemChanged: function() {}, michael@0: onItemVisited: function(id, visitID, time) {}, michael@0: onItemMoved: function() {}, michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver]) michael@0: }; michael@0: // The test will continue once import has finished and smart bookmarks michael@0: // have been created. michael@0: PlacesUtils.bookmarks.addObserver(bookmarksObserver, false); michael@0: michael@0: bg.observe(null, "initial-migration-did-import-default-bookmarks", null); michael@0: } michael@0: michael@0: function onSmartBookmarksCreation() { michael@0: // Check the created bookmarks still exist. michael@0: let itemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, michael@0: SMART_BOOKMARKS_ON_MENU); michael@0: do_check_eq(PlacesUtils.bookmarks.getItemTitle(itemId), "migrated"); michael@0: michael@0: // Check that we have not imported any new bookmark. michael@0: itemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.bookmarksMenuFolderId, michael@0: SMART_BOOKMARKS_ON_MENU + 1) michael@0: do_check_eq(itemId, -1); michael@0: itemId = michael@0: PlacesUtils.bookmarks.getIdForItemAt(PlacesUtils.toolbarFolderId, michael@0: SMART_BOOKMARKS_ON_MENU) michael@0: do_check_eq(itemId, -1); michael@0: michael@0: remove_bookmarks_html(); michael@0: michael@0: do_test_finished(); michael@0: }