Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'win' && socketprocess_networking && fission OR os == 'mac' && socketprocess_networking && fission OR os == 'mac' && debug OR os == 'linux' && socketprocess_networking
- Manifest: toolkit/components/extensions/test/xpcshell/xpcshell-remote.toml includes toolkit/components/extensions/test/xpcshell/xpcshell-common.toml
- Manifest: toolkit/components/extensions/test/xpcshell/xpcshell.toml includes toolkit/components/extensions/test/xpcshell/xpcshell-common.toml
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
function backgroundScript() {
let hasRun = localStorage.getItem("has-run");
let result;
if (!hasRun) {
localStorage.setItem("has-run", "yup");
localStorage.setItem("test-item", "item1");
result = "item1";
} else {
let data = localStorage.getItem("test-item");
if (data == "item1") {
localStorage.setItem("test-item", "item2");
result = "item2";
} else if (data == "item2") {
localStorage.removeItem("test-item");
result = "deleted";
} else if (!data) {
localStorage.clear();
result = "cleared";
}
}
browser.test.sendMessage("result", result);
browser.test.notifyPass("localStorage");
}
const ID = "test-webextension@mozilla.com";
let extensionData = {
manifest: { browser_specific_settings: { gecko: { id: ID } } },
background: backgroundScript,
};
add_task(async function test_localStorage() {
const RESULTS = ["item1", "item2", "deleted", "cleared", "item1"];
for (let expected of RESULTS) {
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
let actual = await extension.awaitMessage("result");
await extension.awaitFinish("localStorage");
await extension.unload();
equal(actual, expected, "got expected localStorage data");
}
});