test_browserGlue_corrupt.js (1620B)
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 is corrupt 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 run_next_test(); 22 } 23 24 registerCleanupFunction(function () { 25 remove_bookmarks_html(); 26 remove_all_JSON_backups(); 27 return PlacesUtils.bookmarks.eraseEverything(); 28 }); 29 30 add_task(async function test_main() { 31 // Create a corrupt database. 32 await createCorruptDB(); 33 34 // Initialize nsBrowserGlue before Places. 35 Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsISupports); 36 37 // Check the database was corrupt. 38 // nsBrowserGlue uses databaseStatus to manage initialization. 39 Assert.equal( 40 PlacesUtils.history.databaseStatus, 41 PlacesUtils.history.DATABASE_STATUS_CORRUPT 42 ); 43 44 // The test will continue once restore has finished. 45 await promiseTopicObserved("places-browser-init-complete"); 46 47 // Check that JSON backup has been restored. 48 let bm = await PlacesUtils.bookmarks.fetch({ 49 parentGuid: PlacesUtils.bookmarks.toolbarGuid, 50 index: 0, 51 }); 52 Assert.equal(bm.title, "examplejson"); 53 });