toolkit/components/osfile/tests/xpcshell/test_path_constants.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial