browser/components/sessionstore/test/browser_upgrade_backup.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial