michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@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: do_get_profile(); michael@0: Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel); michael@0: pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); michael@0: run_next_test(); michael@0: } michael@0: michael@0: let pathStore; michael@0: function pathBackup(ext) { michael@0: return OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak" + ext); michael@0: } michael@0: michael@0: // Ensure that things proceed smoothly if there is no file to back up michael@0: add_task(function test_nothing_to_backup() { michael@0: yield SessionFile.createBackupCopy(""); michael@0: }); michael@0: michael@0: // Create a file, back it up, remove it michael@0: add_task(function test_do_backup() { michael@0: let content = "test_1"; michael@0: let ext = ".upgrade_test_1"; michael@0: yield OS.File.writeAtomic(pathStore, content, {tmpPath: pathStore + ".tmp"}); michael@0: michael@0: do_print("Ensuring that the backup is created"); michael@0: yield SessionFile.createBackupCopy(ext); michael@0: do_check_true((yield OS.File.exists(pathBackup(ext)))); michael@0: michael@0: let data = yield OS.File.read(pathBackup(ext)); michael@0: do_check_eq((new TextDecoder()).decode(data), content); michael@0: michael@0: do_print("Ensuring that we can remove the backup"); michael@0: yield SessionFile.removeBackupCopy(ext); michael@0: do_check_false((yield OS.File.exists(pathBackup(ext)))); michael@0: }); michael@0: