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 753010 1a120ff169b0b51726587d3c22e36b66a24616f6
parent 753009 654ccd9b19992fa2bc8ae47a2d550751fbbe0482
child 753011 f79ecda3b064edc4660cc7cbe2ec1591424f1792
push id98443
push userluca.greco@alcacoop.it
push dateFri, 09 Feb 2018 12:22:06 +0000
bugs1406181
milestone60.0a1
Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends. MozReview-Commit-ID: C4ij1o3TXIO
toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_storage_content.html
@@ -12,16 +12,18 @@
 
 <script type="application/javascript">
 "use strict";
 
 // 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.
 const STORAGE_SYNC_PREF = "webextensions.storage.sync.enabled";
+const USE_STORAGE_IDB_PREF = "extensions.webextensions.useExtensionStorageIDB";
+
 /**
  * Utility function to ensure that all supported APIs for getting are
  * tested.
  *
  * @param {string} areaName
  *        either "local" or "sync" according to what we want to test
  * @param {string} prop
  *        "key" to look up using the storage API
@@ -237,30 +239,68 @@ let extensionData = {
     permissions: ["storage"],
   },
 
   files: {
     "content_script.js": `(${contentScript})(${checkGetImpl})`,
   },
 };
 
-add_task(async function test_contentscript() {
+add_task(async function test_contentscript_storage_sync() {
   let win = window.open("file_sample.html");
   await waitForLoad(win);
 
   await SpecialPowers.pushPrefEnv({
     set: [[STORAGE_SYNC_PREF, true]],
   });
 
   let extension = ExtensionTestUtils.loadExtension(extensionData);
   await Promise.all([extension.startup(), extension.awaitMessage("ready")]);
+
+  extension.sendMessage("test-sync");
+  await extension.awaitMessage("test-finished");
+
+  await SpecialPowers.popPrefEnv();
+  await extension.unload();
+
+  win.close();
+});
+
+add_task(async function test_contentscript_storage_local_file_backend() {
+  let win = window.open("file_sample.html");
+  await waitForLoad(win);
+
+  await SpecialPowers.pushPrefEnv({
+    set: [[USE_STORAGE_IDB_PREF, false]],
+  });
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  await Promise.all([extension.startup(), extension.awaitMessage("ready")]);
+
   extension.sendMessage("test-local");
   await extension.awaitMessage("test-finished");
 
-  extension.sendMessage("test-sync");
+  await SpecialPowers.popPrefEnv();
+  await extension.unload();
+
+  win.close();
+});
+
+add_task(async function test_contentscript_storage_local_idb_backend() {
+  let win = window.open("file_sample.html");
+  await waitForLoad(win);
+
+  await SpecialPowers.pushPrefEnv({
+    set: [[USE_STORAGE_IDB_PREF, true]],
+  });
+
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  await Promise.all([extension.startup(), extension.awaitMessage("ready")]);
+
+  extension.sendMessage("test-local");
   await extension.awaitMessage("test-finished");
 
   await SpecialPowers.popPrefEnv();
   await extension.unload();
 
   win.close();
 });