browser/components/sessionstore/test/unit/test_backup.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/sessionstore/test/unit/test_backup.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,42 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +
     1.8 +let toplevel = this;
     1.9 +Cu.import("resource://gre/modules/osfile.jsm");
    1.10 +
    1.11 +function run_test() {
    1.12 +  do_get_profile();
    1.13 +  Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel);
    1.14 +  pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
    1.15 +  run_next_test();
    1.16 +}
    1.17 +
    1.18 +let pathStore;
    1.19 +function pathBackup(ext) {
    1.20 +  return OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak" + ext);
    1.21 +}
    1.22 +
    1.23 +// Ensure that things proceed smoothly if there is no file to back up
    1.24 +add_task(function test_nothing_to_backup() {
    1.25 +  yield SessionFile.createBackupCopy("");
    1.26 +});
    1.27 +
    1.28 +// Create a file, back it up, remove it
    1.29 +add_task(function test_do_backup() {
    1.30 +  let content = "test_1";
    1.31 +  let ext = ".upgrade_test_1";
    1.32 +  yield OS.File.writeAtomic(pathStore, content, {tmpPath: pathStore + ".tmp"});
    1.33 +
    1.34 +  do_print("Ensuring that the backup is created");
    1.35 +  yield SessionFile.createBackupCopy(ext);
    1.36 +  do_check_true((yield OS.File.exists(pathBackup(ext))));
    1.37 +
    1.38 +  let data = yield OS.File.read(pathBackup(ext));
    1.39 +  do_check_eq((new TextDecoder()).decode(data), content);
    1.40 +
    1.41 +  do_print("Ensuring that we can remove the backup");
    1.42 +  yield SessionFile.removeBackupCopy(ext);
    1.43 +  do_check_false((yield OS.File.exists(pathBackup(ext))));
    1.44 +});
    1.45 +

mercurial