michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: Cu.import("resource://gre/modules/ctypes.jsm", this); michael@0: Cu.import("resource://testing-common/AppData.jsm", this); michael@0: michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: function compare_paths(ospath, key) { michael@0: let file; michael@0: try { michael@0: file = Services.dirsvc.get(key, Components.interfaces.nsIFile); michael@0: } catch(ex) {} michael@0: michael@0: if (file) { michael@0: do_check_true(!!ospath); michael@0: do_check_eq(ospath, file.path); michael@0: } else { michael@0: do_print("WARNING: " + key + " is not defined. Test may not be testing anything!"); michael@0: do_check_false(!!ospath); michael@0: } michael@0: } michael@0: michael@0: // Some path constants aren't set up until the profile is available. This michael@0: // test verifies that behavior. michael@0: add_task(function* test_before_after_profile() { michael@0: do_check_null(OS.Constants.Path.profileDir); michael@0: do_check_null(OS.Constants.Path.localProfileDir); michael@0: do_check_null(OS.Constants.Path.userApplicationDataDir); michael@0: michael@0: do_get_profile(); michael@0: do_check_true(!!OS.Constants.Path.profileDir); michael@0: do_check_true(!!OS.Constants.Path.localProfileDir); michael@0: michael@0: // UAppData is still null because the xpcshell profile doesn't set it up. michael@0: // This test is mostly here to fail in case behavior of do_get_profile() ever michael@0: // changes. We want to know if our assumptions no longer hold! michael@0: do_check_null(OS.Constants.Path.userApplicationDataDir); michael@0: michael@0: yield makeFakeAppDir(); michael@0: do_check_true(!!OS.Constants.Path.userApplicationDataDir); michael@0: michael@0: // FUTURE: verify AppData too (bug 964291). michael@0: }); michael@0: michael@0: // Test simple paths michael@0: add_task(function() { michael@0: do_check_true(!!OS.Constants.Path.tmpDir); michael@0: do_check_eq(OS.Constants.Path.tmpDir, Services.dirsvc.get("TmpD", Components.interfaces.nsIFile).path); michael@0: michael@0: do_check_true(!!OS.Constants.Path.homeDir); michael@0: do_check_eq(OS.Constants.Path.homeDir, Services.dirsvc.get("Home", Components.interfaces.nsIFile).path); michael@0: michael@0: do_check_true(!!OS.Constants.Path.desktopDir); michael@0: do_check_eq(OS.Constants.Path.desktopDir, Services.dirsvc.get("Desk", Components.interfaces.nsIFile).path); michael@0: michael@0: compare_paths(OS.Constants.Path.userApplicationDataDir, "UAppData"); michael@0: michael@0: compare_paths(OS.Constants.Path.winAppDataDir, "AppData"); michael@0: compare_paths(OS.Constants.Path.winStartMenuProgsDir, "Progs"); michael@0: michael@0: compare_paths(OS.Constants.Path.macUserLibDir, "ULibDir"); michael@0: compare_paths(OS.Constants.Path.macLocalApplicationsDir, "LocApp"); michael@0: }); michael@0: michael@0: // Open libxul michael@0: add_task(function() { michael@0: ctypes.open(OS.Constants.Path.libxul); michael@0: do_print("Linked to libxul"); michael@0: });