toolkit/components/places/tests/unit/test_database_replaceOnStartup.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 // Tests that history initialization correctly handles a request to forcibly
michael@0 5 // replace the current database.
michael@0 6
michael@0 7 function run_test() {
michael@0 8 // Ensure that our database doesn't already exist.
michael@0 9 let (dbFile = gProfD.clone()) {
michael@0 10 dbFile.append("places.sqlite");
michael@0 11 do_check_false(dbFile.exists());
michael@0 12 }
michael@0 13 let (dbFile = gProfD.clone()) {
michael@0 14 dbFile.append("places.sqlite.corrupt");
michael@0 15 do_check_false(dbFile.exists());
michael@0 16 }
michael@0 17
michael@0 18 let file = do_get_file("default.sqlite");
michael@0 19 file.copyToFollowingLinks(gProfD, "places.sqlite");
michael@0 20 file = gProfD.clone();
michael@0 21 file.append("places.sqlite");
michael@0 22
michael@0 23 // Create some unique stuff to check later.
michael@0 24 let db = Services.storage.openUnsharedDatabase(file);
michael@0 25 db.executeSimpleSQL("CREATE TABLE test (id INTEGER PRIMARY KEY)");
michael@0 26 db.close();
michael@0 27
michael@0 28 Services.prefs.setBoolPref("places.database.replaceOnStartup", true);
michael@0 29 do_check_eq(PlacesUtils.history.databaseStatus,
michael@0 30 PlacesUtils.history.DATABASE_STATUS_CORRUPT);
michael@0 31
michael@0 32 let (dbFile = gProfD.clone()) {
michael@0 33 dbFile.append("places.sqlite");
michael@0 34 do_check_true(dbFile.exists());
michael@0 35
michael@0 36 // Check the new database is really a new one.
michael@0 37 let db = Services.storage.openUnsharedDatabase(file);
michael@0 38 try {
michael@0 39 db.executeSimpleSQL("DELETE * FROM test");
michael@0 40 do_throw("The new database should not have our unique content");
michael@0 41 } catch(ex) {}
michael@0 42 db.close();
michael@0 43 }
michael@0 44 let (dbFile = gProfD.clone()) {
michael@0 45 dbFile.append("places.sqlite.corrupt");
michael@0 46 do_check_true(dbFile.exists());
michael@0 47 }
michael@0 48 };

mercurial