Bug 1518863: Part 4 - Add tests. r=aswan, a=lizzard
authorKris Maglione <maglione.k@gmail.com>
Wed, 27 Feb 2019 13:57:08 -0800
changeset 516338 6719bb90ce8ae048c9366e92cff22dcedd59eae7
parent 516337 24f6b74fe41c781c47c81eb69e737f60e0d0ca8f
child 516339 fb07e38d917f7d605c23dec973b5811b9b9bd9a9
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan, lizzard
bugs1518863
milestone66.0
Bug 1518863: Part 4 - Add tests. r=aswan, a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D21449
toolkit/components/extensions/test/xpcshell/test_ext_startup_request_handler.js
toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_startup_request_handler.js
@@ -0,0 +1,62 @@
+"use strict";
+
+function delay(time) {
+  return new Promise(resolve => {
+    // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
+    setTimeout(resolve, time);
+  });
+}
+
+ChromeUtils.import("resource://gre/modules/Extension.jsm");
+
+add_task(async function test_startup_request_handler() {
+  const ID = "request-startup@xpcshell.mozilla.org";
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      applications: {gecko: {id: ID}},
+    },
+
+    files: {
+      "meh.txt": "Meh.",
+    },
+  });
+
+  let ready = false;
+  let resolvePromise;
+  let promise = new Promise(resolve => {
+    resolvePromise = resolve;
+  });
+  promise.then(() => {
+    ready = true;
+  });
+
+  let origInitLocale = Extension.prototype.initLocale;
+  Extension.prototype.initLocale = async function initLocale() {
+    await promise;
+    return origInitLocale.call(this);
+  };
+
+  let startupPromise = extension.startup();
+
+  await delay(0);
+  let policy = WebExtensionPolicy.getByID(ID);
+  let url = policy.getURL("meh.txt");
+
+  let resp = ExtensionTestUtils.fetch(url, url);
+  resp.then(() => {
+    ok(ready, "Shouldn't get response before extension is ready");
+  });
+
+  await delay(2000);
+
+  resolvePromise();
+  await startupPromise;
+
+  let body = await resp;
+  equal(body, "Meh.", "Got the correct response");
+
+  await extension.unload();
+
+  Extension.prototype.initLocale = origInitLocale;
+});
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -101,16 +101,17 @@ skip-if = os == "android" && debug
 [test_ext_sandbox_var.js]
 [test_ext_schema.js]
 [test_ext_shutdown_cleanup.js]
 [test_ext_simple.js]
 [test_ext_startupData.js]
 [test_ext_startup_cache.js]
 skip-if = os == "android"
 [test_ext_startup_perf.js]
+[test_ext_startup_request_handler.js]
 [test_ext_storage.js]
 skip-if = os == "android" && debug
 [test_ext_storage_idb_data_migration.js]
 skip-if = os == "android" && debug
 [test_ext_storage_content.js]
 skip-if = os == "android" && debug
 [test_ext_storage_managed.js]
 skip-if = os == "android"