blob: 9adb549afe19e380b1ae8d7649a7de03763b513f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
/* -*- 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");
}
});
|