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
--- 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 = [];