michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let toplevel = this; michael@0: Cu.import("resource://gre/modules/osfile.jsm"); michael@0: michael@0: function run_test() { michael@0: let profd = do_get_profile(); michael@0: Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel); michael@0: decoder = new TextDecoder(); michael@0: pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); michael@0: pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak"); michael@0: let source = do_get_file("data/sessionstore_valid.js"); michael@0: source.copyTo(profd, "sessionstore.js"); michael@0: run_next_test(); michael@0: } michael@0: michael@0: let pathStore; michael@0: let pathBackup; michael@0: let decoder; michael@0: michael@0: // Write to the store, and check that a backup is created first michael@0: add_task(function test_first_write_backup() { michael@0: let content = "test_1"; michael@0: let initial_content = decoder.decode(yield OS.File.read(pathStore)); michael@0: michael@0: do_check_true(!(yield OS.File.exists(pathBackup))); michael@0: yield SessionFile.write(content); michael@0: do_check_true(yield OS.File.exists(pathBackup)); michael@0: michael@0: let backup_content = decoder.decode(yield OS.File.read(pathBackup)); michael@0: do_check_eq(initial_content, backup_content); michael@0: }); michael@0: michael@0: // Write to the store again, and check that the backup is not updated michael@0: add_task(function test_second_write_no_backup() { michael@0: let content = "test_2"; michael@0: let initial_content = decoder.decode(yield OS.File.read(pathStore)); michael@0: let initial_backup_content = decoder.decode(yield OS.File.read(pathBackup)); michael@0: michael@0: yield SessionFile.write(content); michael@0: michael@0: let written_content = decoder.decode(yield OS.File.read(pathStore)); michael@0: do_check_eq(content, written_content); michael@0: michael@0: let backup_content = decoder.decode(yield OS.File.read(pathBackup)); michael@0: do_check_eq(initial_backup_content, backup_content); michael@0: });