Bug 1018169 - [OS.File] Write a test to check if OS.Constants is accessible from a worker. r=Yoric
☠☠ backed out by 445724f95b28 ☠ ☠
authorkushagra singh[:kushagra] <singh.kushagra93@gmail.com>
Thu, 05 Jun 2014 12:43:00 -0700
changeset 206270 e28e73446d88c5d9bd56465916a26eab0a0e43ac
parent 206269 da60b8bc18a32ca050ab8543c222a4443c34f768
child 206271 3a3b6d6a8f2eed2071ddb8afee7e5aed90c6fe75
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1018169
milestone32.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 1018169 - [OS.File] Write a test to check if OS.Constants is accessible from a worker. r=Yoric
toolkit/components/osfile/tests/xpcshell/data/chrome.manifest
toolkit/components/osfile/tests/xpcshell/data/worker_test_constants.js
toolkit/components/osfile/tests/xpcshell/test_constants.js
toolkit/components/osfile/tests/xpcshell/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/osfile/tests/xpcshell/data/chrome.manifest
@@ -0,0 +1,1 @@
+content workers ./
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/toolkit/components/osfile/tests/xpcshell/data/worker_test_constants.js
@@ -0,0 +1,10 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+onmessage = function(e) {
+    // send the OS.Constants as a stringified JSON
+    postMessage(JSON.stringify({'OS_Constants': OS.Constants, 'OS_Constants_Win': OS.Constants.Win,
+        'OS_Constants_Path': OS.Constants.Path, 'OS_Constants_Sys': OS.Constants.Sys,
+        'OS_Constants_libc': OS.Constants.libc, 'OS_Constants_Sys_DEBUG': OS.Constants.Sys.DEBUG,
+        'OS_Constants_Sys_Name': OS.Constants.Sys.Name}));
+};
\ No newline at end of file
--- a/toolkit/components/osfile/tests/xpcshell/test_constants.js
+++ b/toolkit/components/osfile/tests/xpcshell/test_constants.js
@@ -1,26 +1,64 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
 "use strict";
 
+Components.utils.import("resource://gre/modules/Promise.jsm", this);
 Components.utils.import("resource://gre/modules/osfile.jsm");
-Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm", this);
+let isDebugBuild = Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug2).isDebugBuild;
+// import the worker using a chrome uri
+let worker_url = "chrome://workers/content/worker_test_constants.js";
+do_load_manifest("data/chrome.manifest");
 
 function run_test() {
   run_next_test();
 }
 
 // Test that OS.Constants is defined correctly.
 add_task(function* check_definition() {
   do_check_true(OS.Constants!=null);
   do_check_true(!!OS.Constants.Win || !!OS.Constants.libc);
   do_check_true(OS.Constants.Path!=null);
   do_check_true(OS.Constants.Sys!=null);
-  //check system name
+  // check system name
   do_check_eq(OS.Constants.Sys.Name, Services.appinfo.OS);
-
-  //check if using DEBUG build
-  if (Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug2).isDebugBuild == true) {
+  // check if using DEBUG build
+  if (isDebugBuild) {
     do_check_true(OS.Constants.Sys.DEBUG);
   } else {
     do_check_true(typeof(OS.Constants.Sys.DEBUG) == 'undefined');
   }
+});
+
+function test_worker(worker) {
+  var deferred = Promise.defer();
+  worker.onmessage = function (e) {
+    // parse the stringified data
+    var data = JSON.parse(e.data);
+    try {
+      // perform the tests
+      do_check_true(data.OS_Constants != null);
+      do_check_true(!!data.OS_Constants_Win || !!data.OS_Constants_libc);
+      do_check_true(data.OS_Constants_Path != null);
+      do_check_true(data.OS_Constants_Sys != null);
+      do_check_eq(data.OS_Constants_Sys_Name, Services.appinfo.OS);
+      if (isDebugBuild) {
+        do_check_true(data.OS_Constants_Sys_DEBUG);
+      } else {
+        do_check_true(typeof(data.OS_Constants_Sys_DEBUG) == 'undefined');
+      }
+    }  finally {
+       // resolve the promise
+       deferred.resolve();
+    }
+  };
+  // start the worker
+  worker.postMessage('Start tests');
+  return deferred.promise;
+}
+
+add_task(function* check_worker() {
+  // create a new ChromeWorker
+  return test_worker(new ChromeWorker(worker_url));
 });
\ No newline at end of file
--- a/toolkit/components/osfile/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/osfile/tests/xpcshell/xpcshell.ini
@@ -1,11 +1,14 @@
 [DEFAULT]
 head = head.js
 tail =
+support-files =
+  data/worker_test_constants.js
+  data/chrome.manifest
 
 [test_available_free_space.js]
 [test_osfile_closed.js]
 [test_path.js]
 [test_osfile_async.js]
 [test_osfile_async_append.js]
 [test_osfile_async_bytes.js]
 [test_osfile_async_copy.js]