1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_database_replaceOnStartup.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,48 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that history initialization correctly handles a request to forcibly 1.8 +// replace the current database. 1.9 + 1.10 +function run_test() { 1.11 + // Ensure that our database doesn't already exist. 1.12 + let (dbFile = gProfD.clone()) { 1.13 + dbFile.append("places.sqlite"); 1.14 + do_check_false(dbFile.exists()); 1.15 + } 1.16 + let (dbFile = gProfD.clone()) { 1.17 + dbFile.append("places.sqlite.corrupt"); 1.18 + do_check_false(dbFile.exists()); 1.19 + } 1.20 + 1.21 + let file = do_get_file("default.sqlite"); 1.22 + file.copyToFollowingLinks(gProfD, "places.sqlite"); 1.23 + file = gProfD.clone(); 1.24 + file.append("places.sqlite"); 1.25 + 1.26 + // Create some unique stuff to check later. 1.27 + let db = Services.storage.openUnsharedDatabase(file); 1.28 + db.executeSimpleSQL("CREATE TABLE test (id INTEGER PRIMARY KEY)"); 1.29 + db.close(); 1.30 + 1.31 + Services.prefs.setBoolPref("places.database.replaceOnStartup", true); 1.32 + do_check_eq(PlacesUtils.history.databaseStatus, 1.33 + PlacesUtils.history.DATABASE_STATUS_CORRUPT); 1.34 + 1.35 + let (dbFile = gProfD.clone()) { 1.36 + dbFile.append("places.sqlite"); 1.37 + do_check_true(dbFile.exists()); 1.38 + 1.39 + // Check the new database is really a new one. 1.40 + let db = Services.storage.openUnsharedDatabase(file); 1.41 + try { 1.42 + db.executeSimpleSQL("DELETE * FROM test"); 1.43 + do_throw("The new database should not have our unique content"); 1.44 + } catch(ex) {} 1.45 + db.close(); 1.46 + } 1.47 + let (dbFile = gProfD.clone()) { 1.48 + dbFile.append("places.sqlite.corrupt"); 1.49 + do_check_true(dbFile.exists()); 1.50 + } 1.51 +};