Bug 1345095 - ensure SimpleTest.js is loaded before all other scripts. r?jib draft
authorJW Wang <jwwang@mozilla.com>
Tue, 07 Mar 2017 23:59:02 +0800
changeset 495601 5503d3b955443235dc3100051cc7ca7f8f930014
parent 495600 50ba073fc8190106556abbb1ce209a7dfdff0dbd
child 495602 46549972adc0600eb4044ffa952e1ba98330b3a2
child 495617 ad1e8c4cb85d8186b43090110a614f585d7d8729
push id48382
push userjwwang@mozilla.com
push dateThu, 09 Mar 2017 02:49:45 +0000
reviewersjib
bugs1345095
milestone55.0a1
Bug 1345095 - ensure SimpleTest.js is loaded before all other scripts. r?jib Scripts are not necessarily loaded in the same order of |document.head.appendChild(el)|. We use 2-pass loading to ensure SimpleTest.js is loaded before other scripts start loading. MozReview-Commit-ID: FNMmYo83adF
dom/media/tests/mochitest/pc.js
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -1882,34 +1882,43 @@ PeerConnectionWrapper.prototype = {
   toString : function() {
     return "PeerConnectionWrapper (" + this.label + ")";
   }
 };
 
 // haxx to prevent SimpleTest from failing at window.onload
 function addLoadEvent() {}
 
-var scriptsReady = Promise.all([
-  "/tests/SimpleTest/SimpleTest.js",
-  "../../test/manifest.js",
-  "head.js",
-  "templates.js",
-  "turnConfig.js",
-  "dataChannel.js",
-  "network.js",
-  "sdpUtils.js"
-].map(script  => {
-  var el = document.createElement("script");
-  if (typeof scriptRelativePath === 'string' && script.charAt(0) !== '/') {
-    script = scriptRelativePath + script;
-  }
-  el.src = script;
-  document.head.appendChild(el);
-  return new Promise(r => { el.onload = r; el.onerror = r; });
-}));
+function loadScript(...scripts) {
+  return Promise.all(scripts.map(script => {
+    var el = document.createElement("script");
+    if (typeof scriptRelativePath === 'string' && script.charAt(0) !== '/') {
+      script = scriptRelativePath + script;
+    }
+    el.src = script;
+    document.head.appendChild(el);
+    return new Promise(r => {
+      el.onload = r;
+      el.onerror = r;
+    });
+  }));
+}
+
+// Ensure SimpleTest.js is loaded before other scripts.
+var scriptsReady = loadScript("/tests/SimpleTest/SimpleTest.js").then(() => {
+  return loadScript(
+    "../../test/manifest.js",
+    "head.js",
+    "templates.js",
+    "turnConfig.js",
+    "dataChannel.js",
+    "network.js",
+    "sdpUtils.js"
+  );
+});
 
 function createHTML(options) {
   return scriptsReady.then(() => realCreateHTML(options));
 }
 
 var iceServerWebsocket;
 var iceServersArray = [];