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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 let toplevel = this;
     5 Cu.import("resource://gre/modules/osfile.jsm");
     7 function run_test() {
     8   let profd = do_get_profile();
     9   Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel);
    10   decoder = new TextDecoder();
    11   pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
    12   pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak");
    13   let source = do_get_file("data/sessionstore_valid.js");
    14   source.copyTo(profd, "sessionstore.js");
    15   run_next_test();
    16 }
    18 let pathStore;
    19 let pathBackup;
    20 let decoder;
    22 // Write to the store, and check that a backup is created first
    23 add_task(function test_first_write_backup() {
    24   let content = "test_1";
    25   let initial_content = decoder.decode(yield OS.File.read(pathStore));
    27   do_check_true(!(yield OS.File.exists(pathBackup)));
    28   yield SessionFile.write(content);
    29   do_check_true(yield OS.File.exists(pathBackup));
    31   let backup_content = decoder.decode(yield OS.File.read(pathBackup));
    32   do_check_eq(initial_content, backup_content);
    33 });
    35 // Write to the store again, and check that the backup is not updated
    36 add_task(function test_second_write_no_backup() {
    37   let content = "test_2";
    38   let initial_content = decoder.decode(yield OS.File.read(pathStore));
    39   let initial_backup_content = decoder.decode(yield OS.File.read(pathBackup));
    41   yield SessionFile.write(content);
    43   let written_content = decoder.decode(yield OS.File.read(pathStore));
    44   do_check_eq(content, written_content);
    46   let backup_content = decoder.decode(yield OS.File.read(pathBackup));
    47   do_check_eq(initial_backup_content, backup_content);
    48 });

mercurial