Bug 589413 - Failure to open libnss3.so when Firefox path contains UTF-8 characters. Part 3: tests. r=bent, a=final+
authorDan Witte <dwitte@mozilla.com>
Mon, 13 Sep 2010 10:54:02 -0700
changeset 53707 7b0f220344a94efba84f7415cdc3295adcd175e8
parent 53706 00835152707247a21e7c7dc623eb4eb920a25a3d
child 53708 fd5ff14bc45abbedf9a9c4c789dff5d57c88f7ed
child 54097 b51a3574a530767b0cc8b00585f057552c640436
push id15680
push userdwitte@mozilla.com
push dateMon, 13 Sep 2010 17:55:00 +0000
treeherdermozilla-central@7b0f220344a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent, final
bugs589413
milestone2.0b6pre
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 589413 - Failure to open libnss3.so when Firefox path contains UTF-8 characters. Part 3: tests. r=bent, a=final+
toolkit/components/ctypes/tests/test_ctypes.xul
toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
--- a/toolkit/components/ctypes/tests/test_ctypes.xul
+++ b/toolkit/components/ctypes/tests/test_ctypes.xul
@@ -46,16 +46,20 @@
           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="chrome://mochikit/content/chrome-harness.js"/>
 
   <script type="application/javascript">
   <![CDATA[
+    Components.utils.import("resource://gre/modules/ctypes.jsm");
+
+    CTYPES_TEST_LIB = ctypes.libraryName("jsctypes-test");
+    CTYPES_UNICODE_LIB = ctypes.libraryName("jsctyp\u00E8s-t\u00EB\u00DFt");
 
     /*
      * input: string of the url where we are running from
      * return: nsILocalFile
      */
     function getCurrentDir(path) {
       var rootDir = getRootDirectory(window.location.href);
       var jar = getJar(rootDir);
@@ -76,33 +80,52 @@
                                          -1 * "/test_ctypes.xul".length);
       let components = path.split("/");
       for (let part in components) {
         dir.append(components[part]);
       }
       return dir;    
     }
 
+    function setupLibs(path) {
+      let libFile = path.clone();
+      libFile.append(CTYPES_TEST_LIB);
+      ok(libFile.exists(), "ctypes test library doesn't exist!?");
+
+      libFile.copyTo(null, CTYPES_UNICODE_LIB);
+    }
+
+    function cleanupLibs(path) {
+      let unicodeFile = path.clone();
+      unicodeFile.append(CTYPES_UNICODE_LIB);
+      ok(unicodeFile.exists(), "ctypes unicode test library doesn't exist!?");
+      unicodeFile.remove(false);
+    }
+
     function test()
     {
       SimpleTest.waitForExplicitFinish();
 
+      var dir = getCurrentDir(location.path);
+      ok(dir.exists() && dir.isDirectory(), "Chrome test dir doesn't exist?!");
+      setupLibs(dir);
+
       var worker = new ChromeWorker("ctypes_worker.js");
       worker.onmessage = function(event) {
         is(event.data, "Done!", "Wrong message!");
+        cleanupLibs(dir);
         SimpleTest.finish();
       }
       worker.onerror = function(event) {
         ok(false, "Worker had an error: " + event.message);
         worker.terminate();
+        cleanupLibs(dir);
         SimpleTest.finish();
       }
 
-      var dir = getCurrentDir(location.path);
-      ok(dir.exists() && dir.isDirectory(), "Chrome test dir doesn't exist?!");
       worker.postMessage(dir.path);
     }
 
   ]]>
   </script>
 
   <body xmlns="http://www.w3.org/1999/xhtml">
     <p id="display"></p>
--- a/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
+++ b/toolkit/components/ctypes/tests/unit/test_jsctypes.js.in
@@ -33,39 +33,47 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-Components.utils.import("resource://gre/modules/ctypes.jsm");
-
-const Cc = Components.classes;
-const Ci = Components.interfaces;
+try {
+  // We might be running without privileges, in which case it's up to the
+  // harness to give us the 'ctypes' object.
+  Components.utils.import("resource://gre/modules/ctypes.jsm");
+} catch(e) {
+}
 
 CTYPES_TEST_LIB = ctypes.libraryName("jsctypes-test");
+CTYPES_UNICODE_LIB = ctypes.libraryName("jsctyp\u00E8s-t\u00EB\u00DFt");
 
 function getParent(obj, fun)
 {
   if (typeof parent === "function")
     fun(parent(obj));
 }
 
 function checkParentIsCTypes(o)
 {
   function parentIsCTypes(p) { do_check_true(p === ctypes); }
   getParent(o, parentIsCTypes);
 }
 
 function do_check_throws(f, type, stack)
 {
-  if (!stack)
-    stack = Components.stack.caller;
+  if (!stack) {
+    try {
+      // We might not have a 'Components' object.
+      stack = Components.stack.caller;
+    } catch (e) {
+    }
+  }
 
   try {
     f();
   } catch (exc) {
     if (exc instanceof type) {
       do_check_true(true);
       return;
     }
@@ -83,18 +91,18 @@ function do_check_class(obj, class, stac
 }
 
 function run_test()
 {
   // Test ctypes.CType and ctypes.CData are set up correctly.
   run_abstract_class_tests();
 
   // open the library
-  let libfile = do_get_file(CTYPES_TEST_LIB).path;
-  let library = ctypes.open(libfile);
+  let libfile = do_get_file(CTYPES_TEST_LIB);
+  let library = ctypes.open(libfile.path);
 
   // Make sure we can call a function in the library.
   run_void_tests(library);
 
   // Test Int64 and UInt64.
   run_Int64_tests();
   run_UInt64_tests();
 
@@ -210,17 +218,17 @@ function run_test()
   let test_void_t = library.declare("test_void_t_cdecl", ctypes.default_abi, ctypes.void_t);
   library.close();
   do_check_throws(function() { test_void_t(); }, Error);
   do_check_throws(function() {
     library.declare("test_void_t_cdecl", ctypes.default_abi, ctypes.void_t);
   }, Error);
 
   // test that library functions throw when bound to other objects
-  library = ctypes.open(libfile);
+  library = ctypes.open(libfile.path);
   let obj = {};
   obj.declare = library.declare;
   do_check_throws(function () { run_void_tests(obj); }, Error);
   obj.close = library.close;
   do_check_throws(function () { obj.close(); }, Error);
 
   // test that functions work as properties of other objects
   let getter = library.declare("get_int8_t_cdecl", ctypes.default_abi, ctypes.int8_t);
@@ -228,16 +236,29 @@ function run_test()
   obj.t = getter;
   do_check_eq(obj.t(), 109);
 
   // bug 521937
   do_check_throws(function () { let nolib = ctypes.open("notfoundlibrary.dll"); nolib.close(); }, Error);
 
   // bug 522360
   do_check_eq(run_load_system_library(), true);
+
+  // Test loading a library with a unicode name (bug 589413). Note that nsIFile
+  // implementations are not available in some harnesses; if not, the harness
+  // should take care of the copy for us.
+  let unicodefile = do_get_file(CTYPES_UNICODE_LIB, true);
+  let copy = libfile.copyTo instanceof Function;
+  if (copy)
+    libfile.copyTo(null, unicodefile.leafName);
+  library = ctypes.open(unicodefile.path);
+  run_void_tests(library);
+  library.close();
+  if (copy)
+    unicodefile.remove(false);
 }
 
 function run_abstract_class_tests()
 {
   // Test that ctypes.CType is an abstract constructor that throws.
   do_check_throws(function() { ctypes.CType(); }, Error);
   do_check_throws(function() { new ctypes.CType() }, Error);