browser/components/places/tests/unit/test_browserGlue_migrate.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial