browser/components/sessionstore/test/unit/test_backup_once.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_once.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,48 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +let toplevel = this;
     1.8 +Cu.import("resource://gre/modules/osfile.jsm");
     1.9 +
    1.10 +function run_test() {
    1.11 +  let profd = do_get_profile();
    1.12 +  Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel);
    1.13 +  decoder = new TextDecoder();
    1.14 +  pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
    1.15 +  pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak");
    1.16 +  let source = do_get_file("data/sessionstore_valid.js");
    1.17 +  source.copyTo(profd, "sessionstore.js");
    1.18 +  run_next_test();
    1.19 +}
    1.20 +
    1.21 +let pathStore;
    1.22 +let pathBackup;
    1.23 +let decoder;
    1.24 +
    1.25 +// Write to the store, and check that a backup is created first
    1.26 +add_task(function test_first_write_backup() {
    1.27 +  let content = "test_1";
    1.28 +  let initial_content = decoder.decode(yield OS.File.read(pathStore));
    1.29 +
    1.30 +  do_check_true(!(yield OS.File.exists(pathBackup)));
    1.31 +  yield SessionFile.write(content);
    1.32 +  do_check_true(yield OS.File.exists(pathBackup));
    1.33 +
    1.34 +  let backup_content = decoder.decode(yield OS.File.read(pathBackup));
    1.35 +  do_check_eq(initial_content, backup_content);
    1.36 +});
    1.37 +
    1.38 +// Write to the store again, and check that the backup is not updated
    1.39 +add_task(function test_second_write_no_backup() {
    1.40 +  let content = "test_2";
    1.41 +  let initial_content = decoder.decode(yield OS.File.read(pathStore));
    1.42 +  let initial_backup_content = decoder.decode(yield OS.File.read(pathBackup));
    1.43 +
    1.44 +  yield SessionFile.write(content);
    1.45 +
    1.46 +  let written_content = decoder.decode(yield OS.File.read(pathStore));
    1.47 +  do_check_eq(content, written_content);
    1.48 +
    1.49 +  let backup_content = decoder.decode(yield OS.File.read(pathBackup));
    1.50 +  do_check_eq(initial_backup_content, backup_content);
    1.51 +});

mercurial