|
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 "use strict"; |
|
6 |
|
7 Cu.import("resource://gre/modules/ctypes.jsm", this); |
|
8 Cu.import("resource://testing-common/AppData.jsm", this); |
|
9 |
|
10 |
|
11 function run_test() { |
|
12 run_next_test(); |
|
13 } |
|
14 |
|
15 function compare_paths(ospath, key) { |
|
16 let file; |
|
17 try { |
|
18 file = Services.dirsvc.get(key, Components.interfaces.nsIFile); |
|
19 } catch(ex) {} |
|
20 |
|
21 if (file) { |
|
22 do_check_true(!!ospath); |
|
23 do_check_eq(ospath, file.path); |
|
24 } else { |
|
25 do_print("WARNING: " + key + " is not defined. Test may not be testing anything!"); |
|
26 do_check_false(!!ospath); |
|
27 } |
|
28 } |
|
29 |
|
30 // Some path constants aren't set up until the profile is available. This |
|
31 // test verifies that behavior. |
|
32 add_task(function* test_before_after_profile() { |
|
33 do_check_null(OS.Constants.Path.profileDir); |
|
34 do_check_null(OS.Constants.Path.localProfileDir); |
|
35 do_check_null(OS.Constants.Path.userApplicationDataDir); |
|
36 |
|
37 do_get_profile(); |
|
38 do_check_true(!!OS.Constants.Path.profileDir); |
|
39 do_check_true(!!OS.Constants.Path.localProfileDir); |
|
40 |
|
41 // UAppData is still null because the xpcshell profile doesn't set it up. |
|
42 // This test is mostly here to fail in case behavior of do_get_profile() ever |
|
43 // changes. We want to know if our assumptions no longer hold! |
|
44 do_check_null(OS.Constants.Path.userApplicationDataDir); |
|
45 |
|
46 yield makeFakeAppDir(); |
|
47 do_check_true(!!OS.Constants.Path.userApplicationDataDir); |
|
48 |
|
49 // FUTURE: verify AppData too (bug 964291). |
|
50 }); |
|
51 |
|
52 // Test simple paths |
|
53 add_task(function() { |
|
54 do_check_true(!!OS.Constants.Path.tmpDir); |
|
55 do_check_eq(OS.Constants.Path.tmpDir, Services.dirsvc.get("TmpD", Components.interfaces.nsIFile).path); |
|
56 |
|
57 do_check_true(!!OS.Constants.Path.homeDir); |
|
58 do_check_eq(OS.Constants.Path.homeDir, Services.dirsvc.get("Home", Components.interfaces.nsIFile).path); |
|
59 |
|
60 do_check_true(!!OS.Constants.Path.desktopDir); |
|
61 do_check_eq(OS.Constants.Path.desktopDir, Services.dirsvc.get("Desk", Components.interfaces.nsIFile).path); |
|
62 |
|
63 compare_paths(OS.Constants.Path.userApplicationDataDir, "UAppData"); |
|
64 |
|
65 compare_paths(OS.Constants.Path.winAppDataDir, "AppData"); |
|
66 compare_paths(OS.Constants.Path.winStartMenuProgsDir, "Progs"); |
|
67 |
|
68 compare_paths(OS.Constants.Path.macUserLibDir, "ULibDir"); |
|
69 compare_paths(OS.Constants.Path.macLocalApplicationsDir, "LocApp"); |
|
70 }); |
|
71 |
|
72 // Open libxul |
|
73 add_task(function() { |
|
74 ctypes.open(OS.Constants.Path.libxul); |
|
75 do_print("Linked to libxul"); |
|
76 }); |