Bug 685995 - DOM chrome worker tests do not really test anything; r=ted
authorEhsan Akhgari <ehsan@mozilla.com>
Thu, 22 Sep 2011 22:36:09 -0400
changeset 77376 583b4c9b3d4eb73466b57ac4587432c7df7b1561
parent 77375 0ec8974f09172e85dc883a84e808193b80ad88b8
child 77377 1d41a35e38918e1636e1918c31d6b72844bd776f
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersted
bugs685995
milestone9.0a1
Bug 685995 - DOM chrome worker tests do not really test anything; r=ted
dom/workers/test/Makefile.in
dom/workers/test/dom_worker_helper.js
dom/workers/test/test_chromeWorker.xul
dom/workers/test/test_chromeWorkerJSM.xul
dom/workers/test/test_file.xul
dom/workers/test/test_fileBlobPosting.xul
dom/workers/test/test_fileBlobSubWorker.xul
dom/workers/test/test_fileMozSlice.xul
dom/workers/test/test_filePosting.xul
dom/workers/test/test_fileReadMozSlice.xul
dom/workers/test/test_fileReaderSync.xul
dom/workers/test/test_fileReaderSyncErrors.xul
dom/workers/test/test_fileSubWorker.xul
dom/workers/test/test_workersDisabled.xul
--- a/dom/workers/test/Makefile.in
+++ b/dom/workers/test/Makefile.in
@@ -140,16 +140,17 @@ include $(topsrcdir)/config/rules.mk
   fileBlobSubWorker_worker.js \
   WorkerTest.jsm \
   WorkerTest_worker.js \
   WorkerTest_subworker.js \
   chromeWorker_worker.js \
   chromeWorker_subworker.js \
   test_workersDisabled.xul \
   workersDisabled_worker.js \
+  dom_worker_helper.js \
   $(NULL)
 
 ifneq ($(OS_ARCH),WINNT)
 _TEST_FILES += \
   test_closeOnGC.html \
   closeOnGC_worker.js \
   closeOnGC_server.sjs \
   $(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/workers/test/dom_worker_helper.js
@@ -0,0 +1,21 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var gRemainingTests = 0;
+
+function waitForWorkerFinish() {
+  if (gRemainingTests == 0) {
+    SimpleTest.waitForExplicitFinish();
+  }
+  ++gRemainingTests;
+}
+
+function finish() {
+  --gRemainingTests;
+  if (gRemainingTests == 0) {
+    SimpleTest.finish();
+  }
+}
+
--- a/dom/workers/test/test_chromeWorker.xul
+++ b/dom/workers/test/test_chromeWorker.xul
@@ -6,33 +6,34 @@
 <window title="DOM Worker Threads Test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="test();">
 
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <script type="application/javascript">
   <![CDATA[
 
     function test()
     {
-      SimpleTest.waitForExplicitFinish();
+      waitForWorkerFinish();
 
       var worker = new ChromeWorker("chromeWorker_worker.js");
       worker.onmessage = function(event) {
         is(event.data, "Done!", "Wrong message!");
-        SimpleTest.finish();
+        finish();
       }
       worker.onerror = function(event) {
         ok(false, "Worker had an error: " + event.message);
         worker.terminate();
-        SimpleTest.finish();
+        finish();
       }
       worker.postMessage("go");
     }
 
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
--- a/dom/workers/test/test_chromeWorkerJSM.xul
+++ b/dom/workers/test/test_chromeWorkerJSM.xul
@@ -6,30 +6,31 @@
 <window title="DOM Worker Threads Test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="test();">
 
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <script type="application/javascript">
   <![CDATA[
 
     function test()
     {
-      SimpleTest.waitForExplicitFinish();
+      waitForWorkerFinish();
 
       var worker;
 
       function done()
       {
         worker = null;
-        SimpleTest.finish();
+        finish();
       }
 
       function messageCallback(event) {
         is(event.data, "Done", "Correct message");
         done();
       }
 
       function errorCallback(event) {
--- a/dom/workers/test/test_file.xul
+++ b/dom/workers/test/test_file.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=123456
 -->
 <window title="Mozilla Bug 123456"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=123456"
      target="_blank">Mozilla Bug 123456</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -52,33 +51,34 @@ https://bugzilla.mozilla.org/show_bug.cg
 
     return fileList.files[0];
   }
 
   /**
    * Create a worker to access file properties.
    */
   function accessFileProperties(file, expectedSize, expectedType) {
+    waitForWorkerFinish();
+
     var worker = new Worker("file_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread.");
       is(event.data.type, expectedType, "type proproperty accessed from worker is incorrect.");
       is(event.data.name, file.name, "name proproperty accessed from worker is incorrect.");
       is(event.data.mozFullPath, file.mozFullPath, "mozFullPath proproperty accessed from worker is not the same as on main thread.");
-      SimpleTest.finish();
+      finish();
     };
 
     worker.postMessage(file);
-    SimpleTest.waitForExplicitFinish();
   }
 
   // Empty file.
   accessFileProperties(createFileWithData(""), 0, "");
 
   // Typical use case.
   accessFileProperties(createFileWithData("Hello"), 5, "");
 
--- a/dom/workers/test/test_fileBlobPosting.xul
+++ b/dom/workers/test/test_fileBlobPosting.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -57,28 +56,28 @@ https://bugzilla.mozilla.org/show_bug.cg
    * Checks the size, type, name and path of the file posted from the worker to ensure it
    * is the same as the original.
    */
   function postBlob(file) {
     var worker = new Worker("filePosting_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       console.log(event.data);
       is(event.data.size, file.size, "size of file posted from worker does not match file posted to worker.");
-      SimpleTest.finish();
+      finish();
     };
 
     var blob = file.mozSlice();
     worker.postMessage(blob);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   postBlob(createFileWithData(""));
 
   // Typical use case.
   postBlob(createFileWithData("Hello"));
 
--- a/dom/workers/test/test_fileBlobSubWorker.xul
+++ b/dom/workers/test/test_fileBlobSubWorker.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -56,31 +55,31 @@ https://bugzilla.mozilla.org/show_bug.cg
   /**
    * Create a worker to access blob properties.
    */
   function accessFileProperties(file, expectedSize) {
     var worker = new Worker("fileBlobSubWorker_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       if (event.data == undefined) {
         ok(false, "Worker had an error.");
       } else {
         is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread.");
       }
-      SimpleTest.finish();
+      finish();
     };
 
     var blob = file.mozSlice();
     worker.postMessage(blob);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   accessFileProperties(createFileWithData(""), 0);
 
   // Typical use case.
   accessFileProperties(createFileWithData("Hello"), 5);
 
--- a/dom/workers/test/test_fileMozSlice.xul
+++ b/dom/workers/test/test_fileMozSlice.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -57,28 +56,28 @@ https://bugzilla.mozilla.org/show_bug.cg
    * Starts a worker which slices the blob to the given start offset and optional end offset and
    * content type. It then verifies that the size and type of the sliced blob is correct.
    */
   function createMozSlice(blob, start, expectedLength, /** optional */ end, /** optional */ contentType) {
     var worker = new Worker("fileMozSlice_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       is(event.data.size, expectedLength, "size property of slice is incorrect.");
       is(event.data.type, contentType ? contentType : blob.type, "type property of slice is incorrect.");
-      SimpleTest.finish();
+      finish();
     };
 
     var params = {blob: blob, start: start, end: end, contentType: contentType};
     worker.postMessage(params);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   createMozSlice(createFileWithData(""), 0, 0, 0);
 
   // Typical use case.
   createMozSlice(createFileWithData("Hello"), 1, 1, 2);
 
--- a/dom/workers/test/test_filePosting.xul
+++ b/dom/workers/test/test_filePosting.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -57,29 +56,29 @@ https://bugzilla.mozilla.org/show_bug.cg
    * Checks the size, type, name and path of the file posted from the worker to ensure it
    * is the same as the original.
    */
   function postFile(file) {
     var worker = new Worker("file_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       is(event.data.size, file.size, "size of file posted from worker does not match file posted to worker.");
       is(event.data.type, file.type, "type of file posted from worker does not match file posted to worker.");
       is(event.data.name, file.name, "name of file posted from worker does not match file posted to worker.");
       is(event.data.mozFullPath, file.mozFullPath, "mozFullPath of file posted from worker does not match file posted to worker.");
-      SimpleTest.finish();
+      finish();
     };
 
     worker.postMessage(file);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   postFile(createFileWithData(""));
 
   // Typical use case.
   postFile(createFileWithData("Hello"));
 
--- a/dom/workers/test/test_fileReadMozSlice.xul
+++ b/dom/workers/test/test_fileReadMozSlice.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -56,27 +55,27 @@ https://bugzilla.mozilla.org/show_bug.cg
    * Creates a worker which slices a blob to the given start and end offset and
    * reads the content as text.
    */
   function readMozSlice(blob, start, end, expectedText) {
     var worker = new Worker("fileReadMozSlice_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       is(event.data, expectedText, "Text from sliced blob in worker is incorrect.");
-      SimpleTest.finish();
+      finish();
     };
 
     var params = {blob: blob, start: start, end: end};
     worker.postMessage(params);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   readMozSlice(createFileWithData(""), 0, 0, "");
 
   // Typical use case.
   readMozSlice(createFileWithData("HelloBye"), 5, 8, "Bye");
 
--- a/dom/workers/test/test_fileReaderSync.xul
+++ b/dom/workers/test/test_fileReaderSync.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -77,105 +76,105 @@ https://bugzilla.mozilla.org/show_bug.cg
   function readFileData(fileData, expectedText, /** optional */ encoding) {
     var worker = new Worker("fileReaderSync_worker.js");
 
     worker.onmessage = function(event) {
       is(event.data.text, expectedText, "readAsText in worker returned incorrect result.");
       is(event.data.bin, fileData, "readAsBinaryString in worker returned incorrect result.");
       is(event.data.url, convertToDataURL("application/octet-stream", fileData), "readAsDataURL in worker returned incorrect result.");
       is(event.data.arrayBuffer.byteLength, fileData.length, "readAsArrayBuffer returned buffer of incorrect length.");
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     var params = {file: createFileWithData(fileData), encoding: encoding};
 
     worker.postMessage(params);
 
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   /**
    * Create a worker which reuses a FileReaderSync to read multiple files as DataURLs.
    */
   function reuseReaderForURL(files, expected) {
     var worker = new Worker("fileReaderSync_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     var k = 0;
     worker.onmessage = function(event) {
       is(event.data.url, expected[k], "readAsDataURL in worker returned incorrect result when reusing FileReaderSync.");
       k++;
-      SimpleTest.finish();
+      finish();
     };
 
     for (var i = 0; i < files.length; ++i) {
       var params = {file: files[i], encoding: undefined};
       worker.postMessage(params);
-      SimpleTest.waitForExplicitFinish();
+      waitForWorkerFinish();
     }
   }
 
   /**
    * Create a worker which reuses a FileReaderSync to read multiple files as text.
    */
   function reuseReaderForText(fileData, expected) {
     var worker = new Worker("fileReaderSync_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     var k = 0;
     worker.onmessage = function(event) {
       is(event.data.text, expected[k++], "readAsText in worker returned incorrect result when reusing FileReaderSync.");
-      SimpleTest.finish();
+      finish();
     };
 
     for (var i = 0; i < fileData.length; ++i) {
       var params = {file: createFileWithData(fileData[i]), encoding: undefined};
       worker.postMessage(params);
-      SimpleTest.waitForExplicitFinish();
+      waitForWorkerFinish();
     }
   }
 
 
   /**
    * Creates a a worker which reads a file containing fileData as an ArrayBuffer.
    * Verifies that the ArrayBuffer when interpreted as a string matches the original data.
    */
   function readArrayBuffer(fileData) {
     var worker = new Worker("fileReaderSync_worker.js");
 
     worker.onmessage = function(event) {
       var view = new Uint8Array(event.data.arrayBuffer);
       is(event.data.arrayBuffer.byteLength, fileData.length, "readAsArrayBuffer returned buffer of incorrect length.");
       is(String.fromCharCode.apply(String, view), fileData, "readAsArrayBuffer returned buffer containing incorrect data.");
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     var params = {file: createFileWithData(fileData), encoding: undefined};
 
     worker.postMessage(params);
 
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   readFileData("", "");
 
   // Typical use case.
   readFileData("text", "text");
 
--- a/dom/workers/test/test_fileReaderSyncErrors.xul
+++ b/dom/workers/test/test_fileReaderSyncErrors.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -55,31 +54,31 @@ https://bugzilla.mozilla.org/show_bug.cg
   /**
    * Creates a worker which runs errors cases.
    */
   function runWorkerErrors(file) {
     var worker = new Worker("fileReaderSyncErrors_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       if(event.data == undefined) {
         // Worker returns undefined when tests have finished running.
-        SimpleTest.finish();
+        finish();
       } else {
         // Otherwise worker will return results of tests to be evaluated.
         is(event.data.actual, event.data.expected, event.data.message);
       }
     };
 
     worker.postMessage(file);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Run worker which creates exceptions.
   runWorkerErrors(createFileWithData("text"));
 
   ]]>
   </script>
 </window>
--- a/dom/workers/test/test_fileSubWorker.xul
+++ b/dom/workers/test/test_fileSubWorker.xul
@@ -2,19 +2,18 @@
 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=664783
 -->
 <window title="Mozilla Bug 664783"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <script type="application/javascript"
-          src="chrome://mochikit/content/MochiKit/packed.js"/>
-  <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <!-- test results are displayed in the html:body -->
   <body xmlns="http://www.w3.org/1999/xhtml">
   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=664783"
      target="_blank">Mozilla Bug 664783</a>
 
   <div id="content" style="display: none">
     <input id="fileList" type="file"></input>
@@ -56,33 +55,33 @@ https://bugzilla.mozilla.org/show_bug.cg
   /**
    * Create a worker to access file properties.
    */
   function accessFileProperties(file, expectedSize, expectedType) {
     var worker = new Worker("fileSubWorker_worker.js");
 
     worker.onerror = function(event) {
       ok(false, "Worker had an error: " + event.data);
-      SimpleTest.finish();
+      finish();
     };
 
     worker.onmessage = function(event) {
       if (event.data == undefined) {
         ok(false, "Worker had an error.");
       } else {
         is(event.data.size, expectedSize, "size proproperty accessed from worker is not the same as on main thread.");
         is(event.data.type, expectedType, "type proproperty accessed from worker is incorrect.");
         is(event.data.name, file.name, "name proproperty accessed from worker is incorrect.");
         is(event.data.mozFullPath, file.mozFullPath, "mozFullPath proproperty accessed from worker is not the same as on main thread.");
       }
-      SimpleTest.finish();
+      finish();
     };
 
     worker.postMessage(file);
-    SimpleTest.waitForExplicitFinish();
+    waitForWorkerFinish();
   }
 
   // Empty file.
   accessFileProperties(createFileWithData(""), 0, "");
 
   // Typical use case.
   accessFileProperties(createFileWithData("Hello"), 5, "");
 
--- a/dom/workers/test/test_workersDisabled.xul
+++ b/dom/workers/test/test_workersDisabled.xul
@@ -3,16 +3,17 @@
   Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <window title="DOM Worker Threads Test"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="test();">
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+  <script type="application/javascript" src="dom_worker_helper.js"/>
 
   <script type="application/javascript">
   <![CDATA[
     function test()
     {
       const enabledPref = "dom.workers.enabled";
       const message = "Hi";
 
@@ -25,21 +26,21 @@
       ok("Worker" in window, "Worker constructor should be available.");
       ok("ChromeWorker" in window,
          "ChromeWorker constructor should be available.");
 
       var worker = new ChromeWorker("workersDisabled_worker.js");
       worker.onmessage = function(event) {
         is(event.data, message, "Good message.");
         prefs.clearUserPref(enabledPref);
-        SimpleTest.finish();
+        finish();
       }
       worker.postMessage(message);
 
-      SimpleTest.waitForExplicitFinish();
+      waitForWorkerFinish();
     }
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <p id="display"></p>
     <div id="content" style="display:none;"></div>
     <pre id="test"></pre>