Bug 1518863: Part 4 - Add tests. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Wed, 27 Feb 2019 13:57:08 -0800
changeset 461864 05528e4ad2fed74be18afd20be32375c8a8ea42e
parent 461863 e75922833e757d0012dfa3b01779091bd28fbdb9
child 461865 5b59b3bf72d880c4b3e05156ef329854075b24f8
push id35631
push userrgurzau@mozilla.com
push dateFri, 01 Mar 2019 13:06:03 +0000
treeherdermozilla-central@d4e19870e27f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1518863
milestone67.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 1518863: Part 4 - Add tests. r=aswan 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);
+  });
+}
+
+const {Extension} = 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
@@ -102,16 +102,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"