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.
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 });