michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm", this); michael@0: Cu.import("resource://gre/modules/osfile.jsm", this); michael@0: Cu.import("resource://gre/modules/Task.jsm", this); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: Task.spawn(function task() { michael@0: try { michael@0: // Wait until initialization is complete michael@0: yield SessionStore.promiseInitialized; michael@0: michael@0: const PREF_UPGRADE = "browser.sessionstore.upgradeBackup.latestBuildID"; michael@0: let buildID = Services.appinfo.platformBuildID; michael@0: michael@0: // Write state once before starting the test to michael@0: // ensure sessionstore.js writes won't happen in between. michael@0: yield forceSaveState(); michael@0: michael@0: // Force backup to take place with a file decided by us michael@0: Services.prefs.setCharPref(PREF_UPGRADE, ""); michael@0: let contents = "browser_upgrade_backup.js"; michael@0: let pathStore = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); michael@0: yield OS.File.writeAtomic(pathStore, contents, { tmpPath: pathStore + ".tmp" }); michael@0: yield SessionStore._internal._performUpgradeBackup(); michael@0: is(Services.prefs.getCharPref(PREF_UPGRADE), buildID, "upgrade backup should be set (again)"); michael@0: michael@0: let pathBackup = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.bak-" + Services.appinfo.platformBuildID); michael@0: is((yield OS.File.exists(pathBackup)), true, "upgrade backup file has been created"); michael@0: michael@0: let data = yield OS.File.read(pathBackup); michael@0: is(new TextDecoder().decode(data), contents, "upgrade backup contains the expected contents"); michael@0: michael@0: // Ensure that we don't re-backup by accident michael@0: yield OS.File.writeAtomic(pathStore, "something else entirely", { tmpPath: pathStore + ".tmp" }); michael@0: yield SessionStore._internal._performUpgradeBackup(); michael@0: data = yield OS.File.read(pathBackup); michael@0: is(new TextDecoder().decode(data), contents, "upgrade backup hasn't changed"); michael@0: michael@0: } catch (ex) { michael@0: ok(false, "Uncaught error: " + ex + " at " + ex.stack); michael@0: } finally { michael@0: finish(); michael@0: } michael@0: }); michael@0: }