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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /**
michael@0 8 * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if
michael@0 9 * database has been created and one backup is available.
michael@0 10 */
michael@0 11
michael@0 12 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 13
michael@0 14 XPCOMUtils.defineLazyServiceGetter(this, "bs",
michael@0 15 "@mozilla.org/browser/nav-bookmarks-service;1",
michael@0 16 "nsINavBookmarksService");
michael@0 17 XPCOMUtils.defineLazyServiceGetter(this, "anno",
michael@0 18 "@mozilla.org/browser/annotation-service;1",
michael@0 19 "nsIAnnotationService");
michael@0 20
michael@0 21 let bookmarksObserver = {
michael@0 22 onBeginUpdateBatch: function() {},
michael@0 23 onEndUpdateBatch: function() {
michael@0 24 let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
michael@0 25 do_check_neq(itemId, -1);
michael@0 26 if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
michael@0 27 continue_test();
michael@0 28 },
michael@0 29 onItemAdded: function() {},
michael@0 30 onItemRemoved: function(id, folder, index, itemType) {},
michael@0 31 onItemChanged: function() {},
michael@0 32 onItemVisited: function(id, visitID, time) {},
michael@0 33 onItemMoved: function() {},
michael@0 34 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
michael@0 35 };
michael@0 36
michael@0 37 function run_test() {
michael@0 38 do_test_pending();
michael@0 39
michael@0 40 // Create our bookmarks.html copying bookmarks.glue.html to the profile
michael@0 41 // folder. It will be ignored.
michael@0 42 create_bookmarks_html("bookmarks.glue.html");
michael@0 43
michael@0 44 // Create our JSON backup copying bookmarks.glue.json to the profile
michael@0 45 // folder. It will be ignored.
michael@0 46 remove_all_JSON_backups();
michael@0 47 create_JSON_backup("bookmarks.glue.json");
michael@0 48
michael@0 49 // Remove current database file.
michael@0 50 let db = gProfD.clone();
michael@0 51 db.append("places.sqlite");
michael@0 52 if (db.exists()) {
michael@0 53 db.remove(false);
michael@0 54 do_check_false(db.exists());
michael@0 55 }
michael@0 56
michael@0 57 // Initialize nsBrowserGlue before Places.
michael@0 58 Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
michael@0 59
michael@0 60 // Initialize Places through the History Service.
michael@0 61 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 62 getService(Ci.nsINavHistoryService);
michael@0 63 // Check a new database has been created.
michael@0 64 // nsBrowserGlue uses databaseStatus to manage initialization.
michael@0 65 do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
michael@0 66
michael@0 67 // The test will continue once restore has finished and smart bookmarks
michael@0 68 // have been created.
michael@0 69 bs.addObserver(bookmarksObserver, false);
michael@0 70 }
michael@0 71
michael@0 72 function continue_test() {
michael@0 73 // Check that JSON backup has been restored.
michael@0 74 // Notice restore from JSON notification is fired before smart bookmarks creation.
michael@0 75 let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
michael@0 76 do_check_eq(bs.getItemTitle(itemId), "examplejson");
michael@0 77
michael@0 78 remove_bookmarks_html();
michael@0 79 remove_all_JSON_backups();
michael@0 80
michael@0 81 do_test_finished();
michael@0 82 }

mercurial