test_browserGlue_restore.js (1733B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 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/. */ 6 7 /** 8 * Tests that nsBrowserGlue correctly restores bookmarks from a JSON backup if 9 * database has been created and one backup is available. 10 */ 11 12 function run_test() { 13 // Create our bookmarks.html from bookmarks.glue.html. 14 create_bookmarks_html("bookmarks.glue.html"); 15 16 remove_all_JSON_backups(); 17 18 // Create our JSON backup from bookmarks.glue.json. 19 create_JSON_backup("bookmarks.glue.json"); 20 21 // Remove current database file. 22 clearDB(); 23 24 run_next_test(); 25 } 26 27 registerCleanupFunction(function () { 28 remove_bookmarks_html(); 29 remove_all_JSON_backups(); 30 return PlacesUtils.bookmarks.eraseEverything(); 31 }); 32 33 add_task(async function test_main() { 34 // Initialize nsBrowserGlue before Places. 35 Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsISupports); 36 37 // Initialize Places through the History Service. 38 let hs = Cc["@mozilla.org/browser/nav-history-service;1"].getService( 39 Ci.nsINavHistoryService 40 ); 41 42 // Check a new database has been created. 43 // nsBrowserGlue uses databaseStatus to manage initialization. 44 Assert.equal(hs.databaseStatus, hs.DATABASE_STATUS_CREATE); 45 46 // The test will continue once restore has finished. 47 await promiseTopicObserved("places-browser-init-complete"); 48 49 // Check that JSON backup has been restored. 50 let bm = await PlacesUtils.bookmarks.fetch({ 51 parentGuid: PlacesUtils.bookmarks.toolbarGuid, 52 index: 0, 53 }); 54 Assert.equal(bm.title, "examplejson"); 55 });