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 Cu.importGlobalProperties(['File']);
7 add_task(async function() {
8 // throw if anything goes wrong
10 // find the current directory path
11 var file = Cc["@mozilla.org/file/directory_service;1"]
12 .getService(Ci.nsIProperties)
13 .get("CurWorkD", Ci.nsIFile);
14 file.append("xpcshell.toml");
16 // should be able to construct a file
17 var f1 = await File.createFromFileName(file.path);
19 var f2 = await File.createFromNsIFile(file);
22 Assert.ok(f1 instanceof File, "Should be a DOM File");
23 Assert.ok(f2 instanceof File, "Should be a DOM File");
25 Assert.ok(f1.name == "xpcshell.toml", "Should be the right file");
26 Assert.ok(f2.name == "xpcshell.toml", "Should be the right file");
28 Assert.ok(f1.type == "", "Should be the right type");
29 Assert.ok(f2.type == "", "Should be the right type");
33 // Needs a ctor argument
38 Assert.ok(threw, "No ctor arguments should throw");
42 // Needs a valid ctor argument
43 var f7 = File(Date(132131532));
47 Assert.ok(threw, "Passing a random object should fail");
52 var dir = Cc["@mozilla.org/file/directory_service;1"]
53 .getService(Ci.nsIProperties)
54 .get("CurWorkD", Ci.nsIFile);
55 var f7 = await File.createFromNsIFile(dir)
59 Assert.ok(threw, "Can't create a File object for a directory");