Bug 663075 - FileUtils.jsm should have an easy way to create an nsILocalFile with a path; r=sdwilsh sr=rstrong
authorGeoff Lankow <geoff@darktrojan.net>
Tue, 20 Sep 2011 17:20:51 +0100
changeset 77686 ebbc50bbebeb2b3142efd9fbde0d0be0666008f9
parent 77685 028baeb2ca2125590df8cae87beabf91b25e2117
child 77687 969aaa109a23e2f9a0fe3a4efa0642f67d938d88
push idunknown
push userunknown
push dateunknown
reviewerssdwilsh, rstrong
bugs663075
milestone9.0a1
Bug 663075 - FileUtils.jsm should have an easy way to create an nsILocalFile with a path; r=sdwilsh sr=rstrong
toolkit/mozapps/shared/FileUtils.jsm
toolkit/mozapps/shared/test/unit/test_FileUtils.js
--- a/toolkit/mozapps/shared/FileUtils.jsm
+++ b/toolkit/mozapps/shared/FileUtils.jsm
@@ -153,10 +153,12 @@ var FileUtils = {
       try {
         stream.finish();
         return;
       }
       catch (e) {
       }
     }
     stream.close();
-  }
+  },
+
+  File: Components.Constructor("@mozilla.org/file/local;1", Ci.nsILocalFile, "initWithPath")
 };
--- a/toolkit/mozapps/shared/test/unit/test_FileUtils.js
+++ b/toolkit/mozapps/shared/test/unit/test_FileUtils.js
@@ -179,11 +179,21 @@ add_test(function test_closeSafeFileOutp
   // But once we close it, we can't anymore.
   FileUtils.closeSafeFileOutputStream(fos);
   do_check_throws(function () {
     fos.write(data, data.length);
   }, Components.results.NS_BASE_STREAM_CLOSED);
   run_next_test();
 });
 
+add_test(function test_newFile() {
+  let testfile = FileUtils.getFile("ProfD", ["test"]);
+  let testpath = testfile.path;
+  let file = new FileUtils.File(testpath);
+  do_check_true(file instanceof Components.interfaces.nsILocalFile);
+  do_check_true(file.equals(testfile));
+  do_check_eq(file.path, testpath);
+  run_next_test();
+});
+
 function run_test() {
   run_next_test();
 }