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

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 let toplevel = this;
     6 Cu.import("resource://gre/modules/osfile.jsm");
     8 function run_test() {
     9   do_get_profile();
    10   Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel);
    11   pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
    12   run_next_test();
    13 }
    15 let pathStore;
    16 function pathBackup(ext) {
    17   return OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak" + ext);
    18 }
    20 // Ensure that things proceed smoothly if there is no file to back up
    21 add_task(function test_nothing_to_backup() {
    22   yield SessionFile.createBackupCopy("");
    23 });
    25 // Create a file, back it up, remove it
    26 add_task(function test_do_backup() {
    27   let content = "test_1";
    28   let ext = ".upgrade_test_1";
    29   yield OS.File.writeAtomic(pathStore, content, {tmpPath: pathStore + ".tmp"});
    31   do_print("Ensuring that the backup is created");
    32   yield SessionFile.createBackupCopy(ext);
    33   do_check_true((yield OS.File.exists(pathBackup(ext))));
    35   let data = yield OS.File.read(pathBackup(ext));
    36   do_check_eq((new TextDecoder()).decode(data), content);
    38   do_print("Ensuring that we can remove the backup");
    39   yield SessionFile.removeBackupCopy(ext);
    40   do_check_false((yield OS.File.exists(pathBackup(ext))));
    41 });

mercurial