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

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

mercurial