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

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

mercurial