michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that history initialization correctly handles a request to forcibly michael@0: // replace the current database. michael@0: michael@0: function run_test() { michael@0: // Ensure that our database doesn't already exist. michael@0: let (dbFile = gProfD.clone()) { michael@0: dbFile.append("places.sqlite"); michael@0: do_check_false(dbFile.exists()); michael@0: } michael@0: let (dbFile = gProfD.clone()) { michael@0: dbFile.append("places.sqlite.corrupt"); michael@0: do_check_false(dbFile.exists()); michael@0: } michael@0: michael@0: let file = do_get_file("default.sqlite"); michael@0: file.copyToFollowingLinks(gProfD, "places.sqlite"); michael@0: file = gProfD.clone(); michael@0: file.append("places.sqlite"); michael@0: michael@0: // Create some unique stuff to check later. michael@0: let db = Services.storage.openUnsharedDatabase(file); michael@0: db.executeSimpleSQL("CREATE TABLE test (id INTEGER PRIMARY KEY)"); michael@0: db.close(); michael@0: michael@0: Services.prefs.setBoolPref("places.database.replaceOnStartup", true); michael@0: do_check_eq(PlacesUtils.history.databaseStatus, michael@0: PlacesUtils.history.DATABASE_STATUS_CORRUPT); michael@0: michael@0: let (dbFile = gProfD.clone()) { michael@0: dbFile.append("places.sqlite"); michael@0: do_check_true(dbFile.exists()); michael@0: michael@0: // Check the new database is really a new one. michael@0: let db = Services.storage.openUnsharedDatabase(file); michael@0: try { michael@0: db.executeSimpleSQL("DELETE * FROM test"); michael@0: do_throw("The new database should not have our unique content"); michael@0: } catch(ex) {} michael@0: db.close(); michael@0: } michael@0: let (dbFile = gProfD.clone()) { michael@0: dbFile.append("places.sqlite.corrupt"); michael@0: do_check_true(dbFile.exists()); michael@0: } michael@0: };