Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends. r=aswan
authorLuca Greco <lgreco@mozilla.com>
Thu, 19 Oct 2017 16:22:58 +0200
changeset 421618 73030596b51f12ed24a5c3482ce3722923635cbc
parent 421617 077af955cd73eb5d16e9d42079c6e244d2017b69
child 421619 de1544d92b89fdf13f89d28cb9c8b6b4b2bfbd90
push id34099
push userncsoregi@mozilla.com
push dateWed, 06 Jun 2018 22:00:08 +0000
treeherdermozilla-central@1ab062fd31db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1406181
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1406181 - Test storage.local from content scripts on file and indexedDB backends. r=aswan 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"));
+});