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 | let toplevel = this; |
michael@0 | 5 | Cu.import("resource://gre/modules/osfile.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | function run_test() { |
michael@0 | 8 | let profd = do_get_profile(); |
michael@0 | 9 | Cu.import("resource:///modules/sessionstore/SessionFile.jsm", toplevel); |
michael@0 | 10 | decoder = new TextDecoder(); |
michael@0 | 11 | pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); |
michael@0 | 12 | pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak"); |
michael@0 | 13 | let source = do_get_file("data/sessionstore_valid.js"); |
michael@0 | 14 | source.copyTo(profd, "sessionstore.js"); |
michael@0 | 15 | run_next_test(); |
michael@0 | 16 | } |
michael@0 | 17 | |
michael@0 | 18 | let pathStore; |
michael@0 | 19 | let pathBackup; |
michael@0 | 20 | let decoder; |
michael@0 | 21 | |
michael@0 | 22 | // Write to the store, and check that a backup is created first |
michael@0 | 23 | add_task(function test_first_write_backup() { |
michael@0 | 24 | let content = "test_1"; |
michael@0 | 25 | let initial_content = decoder.decode(yield OS.File.read(pathStore)); |
michael@0 | 26 | |
michael@0 | 27 | do_check_true(!(yield OS.File.exists(pathBackup))); |
michael@0 | 28 | yield SessionFile.write(content); |
michael@0 | 29 | do_check_true(yield OS.File.exists(pathBackup)); |
michael@0 | 30 | |
michael@0 | 31 | let backup_content = decoder.decode(yield OS.File.read(pathBackup)); |
michael@0 | 32 | do_check_eq(initial_content, backup_content); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | // Write to the store again, and check that the backup is not updated |
michael@0 | 36 | add_task(function test_second_write_no_backup() { |
michael@0 | 37 | let content = "test_2"; |
michael@0 | 38 | let initial_content = decoder.decode(yield OS.File.read(pathStore)); |
michael@0 | 39 | let initial_backup_content = decoder.decode(yield OS.File.read(pathBackup)); |
michael@0 | 40 | |
michael@0 | 41 | yield SessionFile.write(content); |
michael@0 | 42 | |
michael@0 | 43 | let written_content = decoder.decode(yield OS.File.read(pathStore)); |
michael@0 | 44 | do_check_eq(content, written_content); |
michael@0 | 45 | |
michael@0 | 46 | let backup_content = decoder.decode(yield OS.File.read(pathBackup)); |
michael@0 | 47 | do_check_eq(initial_backup_content, backup_content); |
michael@0 | 48 | }); |