--- a/browser/components/sessionstore/test/browser_506482.js
+++ b/browser/components/sessionstore/test/browser_506482.js
@@ -9,17 +9,17 @@ function test() {
waitForExplicitFinish();
// read the sessionstore.js mtime (picked from browser_248970_a.js)
let profilePath = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("ProfD", Ci.nsIFile);
function getSessionstoreFile() {
let sessionStoreJS = profilePath.clone();
- sessionStoreJS.append("sessionstore.js");
+ sessionStoreJS.append("sessionstore.jsonlz4");
return sessionStoreJS;
}
function getSessionstorejsModificationTime() {
let file = getSessionstoreFile();
if (file.exists()) {
return file.lastModifiedTime;
}
return -1;
--- a/browser/components/sessionstore/test/browser_backup_recovery.js
+++ b/browser/components/sessionstore/test/browser_backup_recovery.js
@@ -8,36 +8,36 @@
var OS = Cu.import("resource://gre/modules/osfile.jsm", {}).OS;
var {File, Constants, Path} = OS;
const PREF_SS_INTERVAL = "browser.sessionstore.interval";
const Paths = SessionFile.Paths;
// A text decoder.
var gDecoder = new TextDecoder();
-// Global variables that contain sessionstore.js and sessionstore.bak data for
+// Global variables that contain sessionstore.jsonlz4 and sessionstore.baklz4 data for
// comparison between tests.
var gSSData;
var gSSBakData;
function promiseRead(path) {
- return File.read(path, {encoding: "utf-8"});
+ return File.read(path, {encoding: "utf-8", compression: "lz4"});
}
add_task(async function init() {
// Make sure that we are not racing with SessionSaver's time based
// saves.
Services.prefs.setIntPref(PREF_SS_INTERVAL, 10000000);
registerCleanupFunction(() => Services.prefs.clearUserPref(PREF_SS_INTERVAL));
});
add_task(async function test_creation() {
// Create dummy sessionstore backups
- let OLD_BACKUP = Path.join(Constants.Path.profileDir, "sessionstore.bak");
- let OLD_UPGRADE_BACKUP = Path.join(Constants.Path.profileDir, "sessionstore.bak-0000000");
+ let OLD_BACKUP = Path.join(Constants.Path.profileDir, "sessionstore.baklz4");
+ let OLD_UPGRADE_BACKUP = Path.join(Constants.Path.profileDir, "sessionstore.baklz4-0000000");
await File.writeAtomic(OLD_BACKUP, "sessionstore.bak");
await File.writeAtomic(OLD_UPGRADE_BACKUP, "sessionstore upgrade backup");
await SessionFile.wipe();
await SessionFile.read(); // Reinitializes SessionFile
// Ensure none of the sessionstore files and backups exists
@@ -106,53 +106,53 @@ var promiseSource = async function(name)
add_task(async function test_recovery() {
// Remove all files.
await SessionFile.wipe();
info("Attempting to recover from the recovery file");
// Create Paths.recovery, ensure that we can recover from it.
let SOURCE = await promiseSource("Paths.recovery");
await File.makeDir(Paths.backups);
- await File.writeAtomic(Paths.recovery, SOURCE);
+ await File.writeAtomic(Paths.recovery, SOURCE, {encoding: "utf-8", compression: "lz4"});
is((await SessionFile.read()).source, SOURCE, "Recovered the correct source from the recovery file");
await SessionFile.wipe();
info("Corrupting recovery file, attempting to recover from recovery backup");
SOURCE = await promiseSource("Paths.recoveryBackup");
await File.makeDir(Paths.backups);
- await File.writeAtomic(Paths.recoveryBackup, SOURCE);
- await File.writeAtomic(Paths.recovery, "<Invalid JSON>");
+ await File.writeAtomic(Paths.recoveryBackup, SOURCE, {encoding: "utf-8", compression: "lz4"});
+ await File.writeAtomic(Paths.recovery, "<Invalid JSON>", {encoding: "utf-8", compression: "lz4"});
is((await SessionFile.read()).source, SOURCE, "Recovered the correct source from the recovery file");
await SessionFile.wipe();
});
add_task(async function test_recovery_inaccessible() {
// Can't do chmod() on non-UNIX platforms, we need that for this test.
if (AppConstants.platform != "macosx" && AppConstants.platform != "linux") {
return;
}
info("Making recovery file inaccessible, attempting to recover from recovery backup");
let SOURCE_RECOVERY = await promiseSource("Paths.recovery");
let SOURCE = await promiseSource("Paths.recoveryBackup");
await File.makeDir(Paths.backups);
- await File.writeAtomic(Paths.recoveryBackup, SOURCE);
+ await File.writeAtomic(Paths.recoveryBackup, SOURCE, {encoding: "utf-8", compression: "lz4"});
// Write a valid recovery file but make it inaccessible.
- await File.writeAtomic(Paths.recovery, SOURCE_RECOVERY);
+ await File.writeAtomic(Paths.recovery, SOURCE_RECOVERY, {encoding: "utf-8", compression: "lz4"});
await File.setPermissions(Paths.recovery, { unixMode: 0 });
is((await SessionFile.read()).source, SOURCE, "Recovered the correct source from the recovery file");
await File.setPermissions(Paths.recovery, { unixMode: 0o644 });
});
add_task(async function test_clean() {
await SessionFile.wipe();
let SOURCE = await promiseSource("Paths.clean");
- await File.writeAtomic(Paths.clean, SOURCE);
+ await File.writeAtomic(Paths.clean, SOURCE, {encoding: "utf-8", compression: "lz4"});
await SessionFile.read();
await SessionSaver.run();
is((await promiseRead(Paths.cleanBackup)), SOURCE, "After first read/write, clean shutdown file has been moved to cleanBackup");
});
/**
* Tests loading of sessionstore when format version is known.
@@ -161,17 +161,17 @@ add_task(async function test_version() {
info("Preparing sessionstore");
let SOURCE = await promiseSource("Paths.clean");
// Check there's a format version number
is(JSON.parse(SOURCE).version[0], "sessionrestore", "Found sessionstore format version");
// Create Paths.clean file
await File.makeDir(Paths.backups);
- await File.writeAtomic(Paths.clean, SOURCE);
+ await File.writeAtomic(Paths.clean, SOURCE, {encoding: "utf-8", compression: "lz4"});
info("Attempting to recover from the clean file");
// Ensure that we can recover from Paths.recovery
is((await SessionFile.read()).source, SOURCE, "Recovered the correct source from the clean file");
});
/**
* Tests fallback to previous backups if format version is unknown.
@@ -184,23 +184,23 @@ add_task(async function test_version_fal
is(JSON.parse(SOURCE).version[0], "sessionrestore", "Found sessionstore format version");
is(JSON.parse(BACKUP_SOURCE).version[0], "sessionrestore", "Found backup sessionstore format version");
await File.makeDir(Paths.backups);
info("Modifying format version number to something incorrect, to make sure that we disregard the file.");
let parsedSource = JSON.parse(SOURCE);
parsedSource.version[0] = "bookmarks";
- await File.writeAtomic(Paths.clean, JSON.stringify(parsedSource));
- await File.writeAtomic(Paths.cleanBackup, BACKUP_SOURCE);
+ await File.writeAtomic(Paths.clean, JSON.stringify(parsedSource), {encoding: "utf-8", compression: "lz4"});
+ await File.writeAtomic(Paths.cleanBackup, BACKUP_SOURCE, {encoding: "utf-8", compression: "lz4"});
is((await SessionFile.read()).source, BACKUP_SOURCE, "Recovered the correct source from the backup recovery file");
info("Modifying format version number to a future version, to make sure that we disregard the file.");
parsedSource = JSON.parse(SOURCE);
parsedSource.version[1] = Number.MAX_SAFE_INTEGER;
- await File.writeAtomic(Paths.clean, JSON.stringify(parsedSource));
- await File.writeAtomic(Paths.cleanBackup, BACKUP_SOURCE);
+ await File.writeAtomic(Paths.clean, JSON.stringify(parsedSource), {encoding: "utf-8", compression: "lz4"});
+ await File.writeAtomic(Paths.cleanBackup, BACKUP_SOURCE, {encoding: "utf-8", compression: "lz4"});
is((await SessionFile.read()).source, BACKUP_SOURCE, "Recovered the correct source from the backup recovery file");
});
add_task(async function cleanup() {
await SessionFile.wipe();
});
--- a/browser/components/sessionstore/test/browser_upgrade_backup.js
+++ b/browser/components/sessionstore/test/browser_upgrade_backup.js
@@ -56,54 +56,54 @@ add_task(async function init() {
// Wait until initialization is complete
await SessionStore.promiseInitialized;
await SessionFile.wipe();
});
add_task(async function test_upgrade_backup() {
let test = await prepareTest();
info("Let's check if we create an upgrade backup");
- await OS.File.writeAtomic(Paths.clean, test.contents);
+ await OS.File.writeAtomic(Paths.clean, test.contents, {encoding: "utf-8", compression: "lz4"});
await SessionFile.read(); // First call to read() initializes the SessionWorker
await SessionFile.write(""); // First call to write() triggers the backup
is(Services.prefs.getCharPref(PREF_UPGRADE), test.buildID, "upgrade backup should be set");
is((await OS.File.exists(Paths.upgradeBackup)), true, "upgrade backup file has been created");
- let data = await OS.File.read(Paths.upgradeBackup);
+ let data = await OS.File.read(Paths.upgradeBackup, {compression: "lz4"});
is(test.contents, (new TextDecoder()).decode(data), "upgrade backup contains the expected contents");
info("Let's check that we don't overwrite this upgrade backup");
let newContents = JSON.stringify({"something else entirely": Math.random()});
- await OS.File.writeAtomic(Paths.clean, newContents);
+ await OS.File.writeAtomic(Paths.clean, newContents, {encoding: "utf-8", compression: "lz4"});
await SessionFile.read(); // Reinitialize the SessionWorker
await SessionFile.write(""); // Next call to write() shouldn't trigger the backup
- data = await OS.File.read(Paths.upgradeBackup);
+ data = await OS.File.read(Paths.upgradeBackup, {compression: "lz4"});
is(test.contents, (new TextDecoder()).decode(data), "upgrade backup hasn't changed");
});
add_task(async function test_upgrade_backup_removal() {
let test = await prepareTest();
let maxUpgradeBackups = Preferences.get(PREF_MAX_UPGRADE_BACKUPS, 3);
info("Let's see if we remove backups if there are too many");
- await OS.File.writeAtomic(Paths.clean, test.contents);
+ await OS.File.writeAtomic(Paths.clean, test.contents, {encoding: "utf-8", compression: "lz4"});
// if the nextUpgradeBackup already exists (from another test), remove it
if (OS.File.exists(Paths.nextUpgradeBackup)) {
await OS.File.remove(Paths.nextUpgradeBackup);
}
// create dummy backups
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20080101010101", "");
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20090101010101", "");
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20100101010101", "");
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20110101010101", "");
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20120101010101", "");
- await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20130101010101", "");
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20080101010101", "", {encoding: "utf-8", compression: "lz4"});
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20090101010101", "", {encoding: "utf-8", compression: "lz4"});
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20100101010101", "", {encoding: "utf-8", compression: "lz4"});
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20110101010101", "", {encoding: "utf-8", compression: "lz4"});
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20120101010101", "", {encoding: "utf-8", compression: "lz4"});
+ await OS.File.writeAtomic(Paths.upgradeBackupPrefix + "20130101010101", "", {encoding: "utf-8", compression: "lz4"});
// get currently existing backups
let backups = await getUpgradeBackups();
// trigger new backup
await SessionFile.read(); // First call to read() initializes the SessionWorker
await SessionFile.write(""); // First call to write() triggers the backup and the cleanup
--- a/browser/components/sessionstore/test/head.js
+++ b/browser/components/sessionstore/test/head.js
@@ -265,25 +265,25 @@ function promiseSaveState() {
}
function forceSaveState() {
return SessionSaver.run();
}
function promiseRecoveryFileContents() {
let promise = forceSaveState();
return promise.then(function() {
- return OS.File.read(SessionFile.Paths.recovery, { encoding: "utf-8" });
+ return OS.File.read(SessionFile.Paths.recovery, { encoding: "utf-8", compression: "lz4" });
});
}
var promiseForEachSessionRestoreFile = async function(cb) {
for (let key of SessionFile.Paths.loadOrder) {
let data = "";
try {
- data = await OS.File.read(SessionFile.Paths[key], { encoding: "utf-8" });
+ data = await OS.File.read(SessionFile.Paths[key], { encoding: "utf-8", compression: "lz4" });
} catch (ex) {
// Ignore missing files
if (!(ex instanceof OS.File.Error && ex.becauseNoSuchFile)) {
throw ex;
}
}
cb(data, key);
}
--- a/browser/components/sessionstore/test/unit/head.js
+++ b/browser/components/sessionstore/test/unit/head.js
@@ -1,13 +1,14 @@
var Cu = Components.utils;
var Cc = Components.classes;
var Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/Services.jsm");
+const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
// Call a function once initialization of SessionStartup is complete
function afterSessionStartupInitialization(cb) {
do_print("Waiting for session startup initialization");
let observer = function() {
try {
do_print("Session startup initialization observed");
Services.obs.removeObserver(observer, "sessionstore-state-finalized");
@@ -25,8 +26,16 @@ function afterSessionStartupInitializati
// Start sessionstartup initialization.
let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
getService(Ci.nsIObserver);
Services.obs.addObserver(startup, "final-ui-startup");
Services.obs.addObserver(startup, "quit-application");
Services.obs.notifyObservers(null, "final-ui-startup");
Services.obs.addObserver(observer, "sessionstore-state-finalized");
}
+
+// Compress the source file using lz4 and put the result to destination file.
+// After that, source file is deleted.
+async function writeCompressedFile(source, destination) {
+ let s = await OS.File.read(source);
+ await OS.File.writeAtomic(destination, s, {compression: "lz4"});
+ await OS.File.remove(source);
+}
--- a/browser/components/sessionstore/test/unit/test_backup_once.js
+++ b/browser/components/sessionstore/test/unit/test_backup_once.js
@@ -1,14 +1,13 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
-var {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
var {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
var {SessionWorker} = Cu.import("resource:///modules/sessionstore/SessionWorker.jsm", {});
var File = OS.File;
var Paths;
var SessionFile;
// We need a XULAppInfo to initialize SessionFile
@@ -25,19 +24,19 @@ function run_test() {
}
add_task(async function init() {
// Make sure that we have a profile before initializing SessionFile
let profd = do_get_profile();
SessionFile = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {}).SessionFile;
Paths = SessionFile.Paths;
-
let source = do_get_file("data/sessionstore_valid.js");
source.copyTo(profd, "sessionstore.js");
+ await writeCompressedFile(Paths.clean.replace("jsonlz4", "js"), Paths.clean);
// Finish initialization of SessionFile
await SessionFile.read();
});
var pathStore;
var pathBackup;
var decoder;
@@ -49,17 +48,17 @@ function promise_check_exist(path, shoul
throw new Error("File " + path + " should " + (shouldExist ? "exist" : "not exist"));
}
})();
}
function promise_check_contents(path, expect) {
return (async function() {
do_print("Checking whether " + path + " has the right contents");
- let actual = await OS.File.read(path, { encoding: "utf-8"});
+ let actual = await OS.File.read(path, { encoding: "utf-8", compression: "lz4" });
Assert.deepEqual(JSON.parse(actual), expect, `File ${path} contains the expected data.`);
})();
}
function generateFileContents(id) {
let url = `http://example.com/test_backup_once#${id}_${Math.random()}`;
return {windows: [{tabs: [{entries: [{url}], index: 1}]}]}
}
@@ -70,17 +69,17 @@ function generateFileContents(id) {
add_task(async function test_first_write_backup() {
let initial_content = generateFileContents("initial");
let new_content = generateFileContents("test_1");
do_print("Before the first write, none of the files should exist");
await promise_check_exist(Paths.backups, false);
await File.makeDir(Paths.backups);
- await File.writeAtomic(Paths.clean, JSON.stringify(initial_content), { encoding: "utf-8" });
+ await File.writeAtomic(Paths.clean, JSON.stringify(initial_content), { encoding: "utf-8", compression: "lz4" });
await SessionFile.write(new_content);
do_print("After first write, a few files should have been created");
await promise_check_exist(Paths.backups, true);
await promise_check_exist(Paths.clean, false);
await promise_check_exist(Paths.cleanBackup, true);
await promise_check_exist(Paths.recovery, true);
await promise_check_exist(Paths.recoveryBackup, false);
@@ -91,17 +90,17 @@ add_task(async function test_first_write
});
// Write to the store again, and check that
// - $Path.clean is not written
// - $Path.recovery contains the new data
// - $Path.recoveryBackup contains the previous data
add_task(async function test_second_write_no_backup() {
let new_content = generateFileContents("test_2");
- let previous_backup_content = await File.read(Paths.recovery, { encoding: "utf-8" });
+ let previous_backup_content = await File.read(Paths.recovery, { encoding: "utf-8", compression: "lz4" });
previous_backup_content = JSON.parse(previous_backup_content);
await OS.File.remove(Paths.cleanBackup);
await SessionFile.write(new_content);
await promise_check_exist(Paths.backups, true);
await promise_check_exist(Paths.clean, false);
--- a/browser/components/sessionstore/test/unit/test_histogram_corrupt_files.js
+++ b/browser/components/sessionstore/test/unit/test_histogram_corrupt_files.js
@@ -15,32 +15,34 @@ const Path = OS.Path;
const HistogramId = "FX_SESSION_RESTORE_ALL_FILES_CORRUPT";
// Prepare the session file.
var profd = do_get_profile();
Cu.import("resource:///modules/sessionstore/SessionFile.jsm", this);
/**
* A utility function for resetting the histogram and the contents
- * of the backup directory.
+ * of the backup directory. This will also compress the file using lz4 compression.
*/
-function reset_session(backups = {}) {
-
- // Reset the histogram.
- Telemetry.getHistogramById(HistogramId).clear();
+function promise_reset_session(backups = {}) {
+ return (async function() {
+ // Reset the histogram.
+ Telemetry.getHistogramById(HistogramId).clear();
- // Reset the contents of the backups directory
- OS.File.makeDir(SessionFile.Paths.backups);
- for (let key of SessionFile.Paths.loadOrder) {
- if (backups.hasOwnProperty(key)) {
- OS.File.copy(backups[key], SessionFile.Paths[key]);
- } else {
- OS.File.remove(SessionFile.Paths[key]);
+ // Reset the contents of the backups directory
+ OS.File.makeDir(SessionFile.Paths.backups);
+ for (let key of SessionFile.Paths.loadOrder) {
+ if (backups.hasOwnProperty(key)) {
+ let s = await OS.File.read(backups[key]);
+ await OS.File.writeAtomic(SessionFile.Paths[key], s, {compression: "lz4"});
+ } else {
+ await OS.File.remove(SessionFile.Paths[key]);
+ }
}
- }
+ })();
}
/**
* In order to use FX_SESSION_RESTORE_ALL_FILES_CORRUPT histogram
* it has to be registered in "toolkit/components/telemetry/Histograms.json".
* This test ensures that the histogram is registered and empty.
*/
add_task(async function test_ensure_histogram_exists_and_empty() {
@@ -49,17 +51,17 @@ add_task(async function test_ensure_hist
});
/**
* Makes sure that the histogram is negatively updated when no
* backup files are present.
*/
add_task(async function test_no_files_exist() {
// No session files are available to SessionFile.
- reset_session();
+ await promise_reset_session();
await SessionFile.read();
// Checking if the histogram is updated negatively
let h = Telemetry.getHistogramById(HistogramId);
let s = h.snapshot();
Assert.equal(s.counts[0], 1, "One probe for the 'false' bucket.");
Assert.equal(s.counts[1], 0, "No probes in the 'true' bucket.");
});
@@ -67,17 +69,17 @@ add_task(async function test_no_files_ex
/**
* Makes sure that the histogram is negatively updated when at least one
* backup file is not corrupted.
*/
add_task(async function test_one_file_valid() {
// Corrupting some backup files.
let invalidSession = "data/sessionstore_invalid.js";
let validSession = "data/sessionstore_valid.js";
- reset_session({
+ await promise_reset_session({
clean: invalidSession,
cleanBackup: validSession,
recovery: invalidSession,
recoveryBackup: invalidSession
});
await SessionFile.read();
// Checking if the histogram is updated negatively.
@@ -89,17 +91,17 @@ add_task(async function test_one_file_va
/**
* Makes sure that the histogram is positively updated when all
* backup files are corrupted.
*/
add_task(async function test_all_files_corrupt() {
// Corrupting all backup files.
let invalidSession = "data/sessionstore_invalid.js";
- reset_session({
+ await promise_reset_session({
clean: invalidSession,
cleanBackup: invalidSession,
recovery: invalidSession,
recoveryBackup: invalidSession
});
await SessionFile.read();
// Checking if the histogram is positively updated.
--- a/browser/components/sessionstore/test/unit/test_shutdown_cleanup.js
+++ b/browser/components/sessionstore/test/unit/test_shutdown_cleanup.js
@@ -9,17 +9,16 @@
const {XPCOMUtils} = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
const {SessionWorker} = Cu.import("resource:///modules/sessionstore/SessionWorker.jsm", {});
const profd = do_get_profile();
const {SessionFile} = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {});
const {Paths} = SessionFile;
-const {OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
const {File} = OS;
const MAX_ENTRIES = 9;
const URL = "http://example.com/#";
// We need a XULAppInfo to initialize SessionFile
Cu.import("resource://testing-common/AppInfo.jsm", this);
updateAppInfo({
@@ -27,16 +26,17 @@ updateAppInfo({
ID: "{230de50e-4cd1-11dc-8314-0800200c9a66}",
version: "1",
platformVersion: "",
});
add_task(async function setup() {
let source = do_get_file("data/sessionstore_valid.js");
source.copyTo(profd, "sessionstore.js");
+ await writeCompressedFile(Paths.clean.replace("jsonlz4", "js"), Paths.clean);
// Finish SessionFile initialization.
await SessionFile.read();
// Reset prefs on cleanup.
do_register_cleanup(() => {
Services.prefs.clearUserPref("browser.sessionstore.max_serialize_back");
Services.prefs.clearUserPref("browser.sessionstore.max_serialize_forward");
@@ -57,17 +57,17 @@ function createSessionState(index) {
async function setMaxBackForward(back, fwd) {
Services.prefs.setIntPref("browser.sessionstore.max_serialize_back", back);
Services.prefs.setIntPref("browser.sessionstore.max_serialize_forward", fwd);
await SessionFile.read();
}
async function writeAndParse(state, path, options = {}) {
await SessionWorker.post("write", [state, options]);
- return JSON.parse(await File.read(path, {encoding: "utf-8"}));
+ return JSON.parse(await File.read(path, {encoding: "utf-8", compression: "lz4"}));
}
add_task(async function test_shistory_cap_none() {
let state = createSessionState(5);
// Don't limit the number of shistory entries.
await setMaxBackForward(-1, -1);
--- a/browser/components/sessionstore/test/unit/test_startup_invalid_session.js
+++ b/browser/components/sessionstore/test/unit/test_startup_invalid_session.js
@@ -1,21 +1,28 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
let profd = do_get_profile();
+ var SessionFile = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {}).SessionFile;
let sourceSession = do_get_file("data/sessionstore_invalid.js");
sourceSession.copyTo(profd, "sessionstore.js");
let sourceCheckpoints = do_get_file("data/sessionCheckpoints_all.json");
sourceCheckpoints.copyTo(profd, "sessionCheckpoints.json");
- do_test_pending();
- let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
- getService(Ci.nsISessionStartup);
+ // Compress sessionstore.js to sessionstore.jsonlz4
+ // and remove sessionstore.js
+ let oldExtSessionFile = SessionFile.Paths.clean.replace("jsonlz4", "js");
+ writeCompressedFile(oldExtSessionFile, SessionFile.Paths.clean).then(() => {
+ let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
+ getService(Ci.nsISessionStartup);
- afterSessionStartupInitialization(function cb() {
- do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION);
- do_test_finished();
+ afterSessionStartupInitialization(function cb() {
+ do_check_eq(startup.sessionType, Ci.nsISessionStartup.NO_SESSION);
+ do_test_finished();
+ });
});
+
+ do_test_pending();
}
--- a/browser/components/sessionstore/test/unit/test_startup_session_async.js
+++ b/browser/components/sessionstore/test/unit/test_startup_session_async.js
@@ -4,24 +4,31 @@
// Test nsISessionStartup.sessionType in the following scenario:
// - valid sessionstore.js;
// - valid sessionCheckpoints.json with all checkpoints;
// - the session store has been loaded
function run_test() {
let profd = do_get_profile();
+ var SessionFile = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {}).SessionFile;
let sourceSession = do_get_file("data/sessionstore_valid.js");
sourceSession.copyTo(profd, "sessionstore.js");
let sourceCheckpoints = do_get_file("data/sessionCheckpoints_all.json");
sourceCheckpoints.copyTo(profd, "sessionCheckpoints.json");
- do_test_pending();
- let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
- getService(Ci.nsISessionStartup);
+ // Compress sessionstore.js to sessionstore.jsonlz4
+ // and remove sessionstore.js
+ let oldExtSessionFile = SessionFile.Paths.clean.replace("jsonlz4", "js");
+ writeCompressedFile(oldExtSessionFile, SessionFile.Paths.clean).then(() => {
+ let startup = Cc["@mozilla.org/browser/sessionstartup;1"].
+ getService(Ci.nsISessionStartup);
- afterSessionStartupInitialization(function cb() {
- do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION);
- do_test_finished();
+ afterSessionStartupInitialization(function cb() {
+ do_check_eq(startup.sessionType, Ci.nsISessionStartup.DEFER_SESSION);
+ do_test_finished();
+ });
});
+
+ do_test_pending();
}