|
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/. */ |
|
4 |
|
5 const Ci = Components.interfaces; |
|
6 |
|
7 function run_test() { |
|
8 // throw if anything goes wrong |
|
9 |
|
10 // find the current directory path |
|
11 var file = Components.classes["@mozilla.org/file/directory_service;1"] |
|
12 .getService(Ci.nsIProperties) |
|
13 .get("CurWorkD", Ci.nsIFile); |
|
14 file.append("xpcshell.ini"); |
|
15 |
|
16 // should be able to construct a file |
|
17 var f1 = File(file.path); |
|
18 // with either constructor syntax |
|
19 var f2 = new File(file.path); |
|
20 // and with nsIFiles |
|
21 var f3 = File(file); |
|
22 var f4 = new File(file); |
|
23 |
|
24 // do some tests |
|
25 do_check_true(f1 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
|
26 do_check_true(f2 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
|
27 do_check_true(f3 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
|
28 do_check_true(f4 instanceof Ci.nsIDOMFile, "Should be a DOM File"); |
|
29 |
|
30 do_check_true(f1.name == "xpcshell.ini", "Should be the right file"); |
|
31 do_check_true(f2.name == "xpcshell.ini", "Should be the right file"); |
|
32 do_check_true(f3.name == "xpcshell.ini", "Should be the right file"); |
|
33 do_check_true(f4.name == "xpcshell.ini", "Should be the right file"); |
|
34 |
|
35 do_check_true(f1.type == "", "Should be the right type"); |
|
36 do_check_true(f2.type == "", "Should be the right type"); |
|
37 do_check_true(f3.type == "", "Should be the right type"); |
|
38 do_check_true(f4.type == "", "Should be the right type"); |
|
39 |
|
40 var threw = false; |
|
41 try { |
|
42 // Needs a ctor argument |
|
43 var f7 = File(); |
|
44 } catch (e) { |
|
45 threw = true; |
|
46 } |
|
47 do_check_true(threw, "No ctor arguments should throw"); |
|
48 |
|
49 var threw = false; |
|
50 try { |
|
51 // Needs a valid ctor argument |
|
52 var f7 = File(Date(132131532)); |
|
53 } catch (e) { |
|
54 threw = true; |
|
55 } |
|
56 do_check_true(threw, "Passing a random object should fail"); |
|
57 |
|
58 var threw = false |
|
59 try { |
|
60 // Directories fail |
|
61 var dir = Components.classes["@mozilla.org/file/directory_service;1"] |
|
62 .getService(Ci.nsIProperties) |
|
63 .get("CurWorkD", Ci.nsIFile); |
|
64 var f7 = File(dir) |
|
65 } catch (e) { |
|
66 threw = true; |
|
67 } |
|
68 do_check_true(threw, "Can't create a File object for a directory"); |
|
69 } |