Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends. draft
authorLuca Greco <lgreco@mozilla.com>
Thu, 19 Oct 2017 16:22:58 +0200
changeset 802174 4fb5b52ddf3247f39494a09af4311ec324709190
parent 802173 f4b1666730090cdc5194482be36ef73d71f46cb7
child 802175 1bc2cc6b3a1a645377cbc6df6298ace664480a62
push id111848
push userluca.greco@alcacoop.it
push dateThu, 31 May 2018 16:18:52 +0000
bugs1406181
milestone62.0a1
Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends. MozReview-Commit-ID: C4ij1o3TXIO
toolkit/components/extensions/test/xpcshell/test_ext_storage_content.js
--- 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"));
+});