1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 var EXPORTED_SYMBOLS = ["TestFile"];
9 // we don't have the test harness' utilities in this scope, so we need this
10 // little helper. In the failure case, the exception is propagated to the
11 // caller in the main run_test() function, and the test fails.
13 throw "Failed check: " + text;
18 doTest: function(cb) {
19 // throw if anything goes wrong
21 // find the current directory path
22 var file = Cc["@mozilla.org/file/directory_service;1"]
23 .getService(Ci.nsIProperties)
24 .get("CurWorkD", Ci.nsIFile);
25 file.append("xpcshell.toml");
27 // should be able to construct a file
30 File.createFromFileName(file.path).then(f => { f1 = f; }),
31 File.createFromNsIFile(file).then(f => { f2 = f; }),
35 Assert.ok(f1 instanceof File, "Should be a DOM File");
36 Assert.ok(f2 instanceof File, "Should be a DOM File");
38 Assert.ok(f1.name == "xpcshell.toml", "Should be the right file");
39 Assert.ok(f2.name == "xpcshell.toml", "Should be the right file");
41 Assert.ok(f1.type == "", "Should be the right type");
42 Assert.ok(f2.type == "", "Should be the right type");
47 // Needs a ctor argument
52 Assert.ok(threw, "No ctor arguments should throw");
56 // Needs a valid ctor argument
57 var f7 = new File(Date(132131532));
61 Assert.ok(threw, "Passing a random object should fail");
64 var dir = Cc["@mozilla.org/file/directory_service;1"]
65 .getService(Ci.nsIProperties)
66 .get("CurWorkD", Ci.nsIFile);
67 return File.createFromNsIFile(dir)
70 Assert.ok(false, "Can't create a File object for a directory");
72 Assert.ok(true, "Can't create a File object for a directory");