1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { ctypes } = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
const { makeFakeAppDir } = ChromeUtils.importESModule(
"resource://testing-common/AppData.sys.mjs"
);
function compare_paths(ospath, key) {
let file;
try {
file = Services.dirsvc.get(key, Ci.nsIFile);
} catch (ex) {}
if (file) {
Assert.ok(!!ospath);
Assert.equal(ospath, file.path);
} else {
info(
"WARNING: " + key + " is not defined. Test may not be testing anything!"
);
Assert.ok(!ospath);
}
}
// Test simple paths
add_task(async function test_simple_paths() {
Assert.ok(!!OS.Constants.Path.tmpDir);
compare_paths(OS.Constants.Path.tmpDir, "TmpD");
});
// Some path constants aren't set up until the profile is available. This
// test verifies that behavior.
add_task(async function test_before_after_profile() {
// On Android the profile is initialized during xpcshell init, so this test
// will fail.
if (AppConstants.platform != "android") {
Assert.equal(null, OS.Constants.Path.profileDir);
Assert.equal(null, OS.Constants.Path.localProfileDir);
Assert.equal(null, OS.Constants.Path.userApplicationDataDir);
}
do_get_profile();
Assert.ok(!!OS.Constants.Path.profileDir);
Assert.ok(!!OS.Constants.Path.localProfileDir);
// UAppData is still null because the xpcshell profile doesn't set it up.
// This test is mostly here to fail in case behavior of do_get_profile() ever
// changes. We want to know if our assumptions no longer hold!
Assert.equal(null, OS.Constants.Path.userApplicationDataDir);
await makeFakeAppDir();
Assert.ok(!!OS.Constants.Path.userApplicationDataDir);
// FUTURE: verify AppData too (bug 964291).
});
// Test presence of paths that only exist on Desktop platforms
add_task(async function test_desktop_paths() {
if (OS.Constants.Sys.Name == "Android") {
return;
}
Assert.ok(!!OS.Constants.Path.homeDir);
compare_paths(OS.Constants.Path.homeDir, "Home");
compare_paths(OS.Constants.Path.userApplicationDataDir, "UAppData");
compare_paths(OS.Constants.Path.macUserLibDir, "ULibDir");
});
// Open libxul
add_task(async function test_libxul() {
ctypes.open(OS.Constants.Path.libxul);
info("Linked to libxul");
});
|