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.

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 // Tests that history initialization correctly handles a request to forcibly
     5 // replace the current database.
     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   }
    18   let file = do_get_file("default.sqlite");
    19   file.copyToFollowingLinks(gProfD, "places.sqlite");
    20   file = gProfD.clone();
    21   file.append("places.sqlite");
    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();
    28   Services.prefs.setBoolPref("places.database.replaceOnStartup", true);
    29   do_check_eq(PlacesUtils.history.databaseStatus,
    30               PlacesUtils.history.DATABASE_STATUS_CORRUPT);
    32   let (dbFile = gProfD.clone()) {
    33     dbFile.append("places.sqlite");
    34     do_check_true(dbFile.exists());
    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