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 Cu.import("resource://gre/modules/Services.jsm", this);
5 Cu.import("resource://gre/modules/osfile.jsm", this);
6 Cu.import("resource://gre/modules/Task.jsm", this);
8 function test() {
9 waitForExplicitFinish();
11 Task.spawn(function task() {
12 try {
13 // Wait until initialization is complete
14 yield SessionStore.promiseInitialized;
16 const PREF_UPGRADE = "browser.sessionstore.upgradeBackup.latestBuildID";
17 let buildID = Services.appinfo.platformBuildID;
19 // Write state once before starting the test to
20 // ensure sessionstore.js writes won't happen in between.
21 yield forceSaveState();
23 // Force backup to take place with a file decided by us
24 Services.prefs.setCharPref(PREF_UPGRADE, "");
25 let contents = "browser_upgrade_backup.js";
26 let pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js");
27 yield OS.File.writeAtomic(pathStore, contents, { tmpPath: pathStore + ".tmp" });
28 yield SessionStore._internal._performUpgradeBackup();
29 is(Services.prefs.getCharPref(PREF_UPGRADE), buildID, "upgrade backup should be set (again)");
31 let pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak-" + Services.appinfo.platformBuildID);
32 is((yield OS.File.exists(pathBackup)), true, "upgrade backup file has been created");
34 let data = yield OS.File.read(pathBackup);
35 is(new TextDecoder().decode(data), contents, "upgrade backup contains the expected contents");
37 // Ensure that we don't re-backup by accident
38 yield OS.File.writeAtomic(pathStore, "something else entirely", { tmpPath: pathStore + ".tmp" });
39 yield SessionStore._internal._performUpgradeBackup();
40 data = yield OS.File.read(pathBackup);
41 is(new TextDecoder().decode(data), contents, "upgrade backup hasn't changed");
43 } catch (ex) {
44 ok(false, "Uncaught error: " + ex + " at " + ex.stack);
45 } finally {
46 finish();
47 }
48 });
49 }