Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 /**
8 * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if
9 * database has been created and one backup is available.
10 */
12 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
14 XPCOMUtils.defineLazyServiceGetter(this, "bs",
15 "@mozilla.org/browser/nav-bookmarks-service;1",
16 "nsINavBookmarksService");
17 XPCOMUtils.defineLazyServiceGetter(this, "anno",
18 "@mozilla.org/browser/annotation-service;1",
19 "nsIAnnotationService");
21 let bookmarksObserver = {
22 onBeginUpdateBatch: function() {},
23 onEndUpdateBatch: function() {
24 let itemId = bs.getIdForItemAt(bs.toolbarFolder, 0);
25 do_check_neq(itemId, -1);
26 if (anno.itemHasAnnotation(itemId, "Places/SmartBookmark"))
27 continue_test();
28 },
29 onItemAdded: function() {},
30 onItemRemoved: function(id, folder, index, itemType) {},
31 onItemChanged: function() {},
32 onItemVisited: function(id, visitID, time) {},
33 onItemMoved: function() {},
34 QueryInterface: XPCOMUtils.generateQI([Ci.nsINavBookmarkObserver])
35 };
37 function run_test() {
38 do_test_pending();
40 // Create our bookmarks.html copying bookmarks.glue.html to the profile
41 // folder. It will be ignored.
42 create_bookmarks_html("bookmarks.glue.html");
44 // Create our JSON backup copying bookmarks.glue.json to the profile
45 // folder. It will be ignored.
46 remove_all_JSON_backups();
47 create_JSON_backup("bookmarks.glue.json");
49 // Remove current database file.
50 let db = gProfD.clone();
51 db.append("places.sqlite");
52 if (db.exists()) {
53 db.remove(false);
54 do_check_false(db.exists());
55 }
57 // Initialize nsBrowserGlue before Places.
58 Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIBrowserGlue);
60 // Initialize Places through the History Service.
61 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
62 getService(Ci.nsINavHistoryService);
63 // Check a new database has been created.
64 // nsBrowserGlue uses databaseStatus to manage initialization.
65 do_check_eq(hs.databaseStatus, hs.DATABASE_STATUS_CREATE);
67 // The test will continue once restore has finished and smart bookmarks
68 // have been created.
69 bs.addObserver(bookmarksObserver, false);
70 }
72 function continue_test() {
73 // Check that JSON backup has been restored.
74 // Notice restore from JSON notification is fired before smart bookmarks creation.
75 let itemId = bs.getIdForItemAt(bs.toolbarFolder, SMART_BOOKMARKS_ON_TOOLBAR);
76 do_check_eq(bs.getItemTitle(itemId), "examplejson");
78 remove_bookmarks_html();
79 remove_all_JSON_backups();
81 do_test_finished();
82 }