Rework test for bug 292789 to try and fix the timeout on qm-centos5-01
authorgavin@gavinsharp.com
Mon, 14 Apr 2008 01:50:51 -0700
changeset 14301 e1c8ddf7902f6c72f9d1403e94da93721d30d2dc
parent 14300 bdc4c9044e38d6ef39e8cf7b30ee71250ecf0069
child 14302 a8cc1b1d3eff52c24923746ca19655e7d66c7272
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs292789
milestone1.9pre
Rework test for bug 292789 to try and fix the timeout on qm-centos5-01
caps/tests/mochitest/test_bug292789.html
--- a/caps/tests/mochitest/test_bug292789.html
+++ b/caps/tests/mochitest/test_bug292789.html
@@ -20,59 +20,86 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 292789
  **
  ** Selectively allow access to whitelisted chrome packages
  ** even for ALLOW_CHROME mechanisms (<script>, <img> etc)
  **/
 
-/** <script src=""> test **/
-
-is(typeof srGetStrBundle, "function",
-   "content can still load <script> from chrome://global");
-is(typeof XPInstallConfirm, "undefined",
-   "content should not be able to load <script> from chrome://mozapps");
+SimpleTest.waitForExplicitFinish();
 
-/** make sure the last one didn't pass because someone
- ** moved the resource
- **/
-var resjs = document.createElement("script");
-resjs.src = "jar:resource://gre/chrome/toolkit.jar!/content/mozapps/xpinstall/xpinstallConfirm.js";
-document.body.appendChild(resjs);
+/** <script src=""> test **/
+function testScriptSrc(aCallback) {
+    is(typeof srGetStrBundle, "function",
+       "content can still load <script> from chrome://global");
+    is(typeof XPInstallConfirm, "undefined",
+       "content should not be able to load <script> from chrome://mozapps");
+    
+    /** make sure the last one didn't pass because someone
+     ** moved the resource
+     **/
+    var resjs = document.createElement("script");
+    resjs.src = "jar:resource://gre/chrome/toolkit.jar!/content/mozapps/xpinstall/xpinstallConfirm.js";
+    resjs.onload = scriptOnload;
+    document.getElementById("content").appendChild(resjs);
 
-setTimeout('is(typeof XPInstallConfirm, "object",'+
-   '"xpinstallConfirm.js has not moved unexpectedly")',0);
-
+    function scriptOnload() {
+      is(typeof XPInstallConfirm, "object",
+         "xpinstallConfirm.js has not moved unexpectedly");
+  
+      // trigger the callback
+      if (aCallback)
+        aCallback();
+    }
+}
 
 /** <img src=""> tests **/
 var img_global = "chrome://global/skin/icons/Error.png";
 var img_mozapps = "chrome://mozapps/skin/passwordmgr/key.png";
 var res_mozapps = "jar:resource://gre/chrome/classic.jar!/skin/classic/mozapps/passwordmgr/key.png";
 
+var imgTests = [[img_global, "success"],
+                [img_mozapps, "fail"],
+                [res_mozapps, "success"]];
+
+var curImgTest = 0;
+
+function runImgTest() {
+    var test = imgTests[curImgTest++];
+    var callback = curImgTest == imgTests.length ? finishTest : runImgTest;
+    loadImage(test[0], test[1], callback);
+}
+
+function finishTest() {
+  SimpleTest.finish();
+}
+
 function fail(event) {
     is(event.target.expected, "fail",
        "content should not be allowed to load "+event.target.src);
+    if (event.target.callback)
+      event.target.callback();
 }
 
 function success(event) {
     is(event.target.expected, "success",
        "content should be able to load "+event.target.src);
+    if (event.target.callback)
+      event.target.callback();
 }
 
-function loadImage(uri, expect) {
+function loadImage(uri, expect, callback) {
     var img = document.createElement("img");
     img.onerror = fail;
     img.onload = success;
     img.expected = expect;
+    img.callback = callback;
     img.src = uri;
     //document.getElementById("content").appendChild(img);
 }
 
-loadImage(img_global, "success");
-loadImage(img_mozapps, "fail");
-loadImage(res_mozapps, "success");
-
+// Start off the script src test, and have it start the img tests when complete.
+testScriptSrc(runImgTest);
 </script>
 </pre>
 </body>
 </html>
-