Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | |
michael@0 | 5 | let toplevel = this; |
michael@0 | 6 | Cu.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 7 | |
michael@0 | 8 | function run_test() { |
michael@0 | 9 | do_get_profile(); |
michael@0 | 10 | Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel); |
michael@0 | 11 | pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); |
michael@0 | 12 | run_next_test(); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | let pathStore; |
michael@0 | 16 | function pathBackup(ext) { |
michael@0 | 17 | return OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak" + ext); |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | // Ensure that things proceed smoothly if there is no file to back up |
michael@0 | 21 | add_task(function test_nothing_to_backup() { |
michael@0 | 22 | yield SessionFile.createBackupCopy(""); |
michael@0 | 23 | }); |
michael@0 | 24 | |
michael@0 | 25 | // Create a file, back it up, remove it |
michael@0 | 26 | add_task(function test_do_backup() { |
michael@0 | 27 | let content = "test_1"; |
michael@0 | 28 | let ext = ".upgrade_test_1"; |
michael@0 | 29 | yield OS.File.writeAtomic(pathStore, content, {tmpPath: pathStore + ".tmp"}); |
michael@0 | 30 | |
michael@0 | 31 | do_print("Ensuring that the backup is created"); |
michael@0 | 32 | yield SessionFile.createBackupCopy(ext); |
michael@0 | 33 | do_check_true((yield OS.File.exists(pathBackup(ext)))); |
michael@0 | 34 | |
michael@0 | 35 | let data = yield OS.File.read(pathBackup(ext)); |
michael@0 | 36 | do_check_eq((new TextDecoder()).decode(data), content); |
michael@0 | 37 | |
michael@0 | 38 | do_print("Ensuring that we can remove the backup"); |
michael@0 | 39 | yield SessionFile.removeBackupCopy(ext); |
michael@0 | 40 | do_check_false((yield OS.File.exists(pathBackup(ext)))); |
michael@0 | 41 | }); |
michael@0 | 42 |