Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends.
MozReview-Commit-ID: C4ij1o3TXIO
--- a/toolkit/components/extensions/test/xpcshell/test_ext_storage_content.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_storage_content.js
@@ -1,10 +1,12 @@
"use strict";
+ChromeUtils.import("resource://gre/modules/ExtensionStorageIDB.jsm");
+
PromiseTestUtils.whitelistRejectionsGlobally(/WebExtension context not found/);
const server = createHttpServer({hosts: ["example.com"]});
server.registerDirectory("/data/", do_get_file("data"));
// Copied from toolkit/components/extensions/test/xpcshell/test_ext_storage.js.
// The storage API in content scripts should behave identical to the storage API
// in background pages.
@@ -230,29 +232,41 @@ let extensionData = {
permissions: ["storage"],
},
files: {
"content_script.js": `(${contentScript})(${checkGetImpl})`,
},
};
-add_task(async function test_contentscript() {
- await ExtensionTestUtils.startAddonManager();
- Services.prefs.setBoolPref(STORAGE_SYNC_PREF, true);
-
-
+async function test_contentscript_storage(storageType) {
let contentPage = await ExtensionTestUtils.loadContentPage(
"http://example.com/data/file_sample.html");
let extension = ExtensionTestUtils.loadExtension(extensionData);
await extension.startup();
await extension.awaitMessage("ready");
- extension.sendMessage("test-local");
- await extension.awaitMessage("test-finished");
-
- extension.sendMessage("test-sync");
+ extension.sendMessage(`test-${storageType}`);
await extension.awaitMessage("test-finished");
await extension.unload();
await contentPage.close();
+}
+
+add_task(async function setup() {
+ await ExtensionTestUtils.startAddonManager();
});
+
+add_task(async function test_contentscript_storage_sync() {
+ return runWithPrefs([[STORAGE_SYNC_PREF, true]],
+ () => test_contentscript_storage("sync"));
+});
+
+add_task(async function test_contentscript_storage_local_file_backend() {
+ return runWithPrefs([[ExtensionStorageIDB.BACKEND_ENABLED_PREF, false]],
+ () => test_contentscript_storage("local"));
+});
+
+add_task(async function test_contentscript_storage_local_idb_backend() {
+ return runWithPrefs([[ExtensionStorageIDB.BACKEND_ENABLED_PREF, true]],
+ () => test_contentscript_storage("local"));
+});