Sat, 03 Jan 2015 20:18:00 +0100
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 | Components.utils.import("resource://gre/modules/Services.jsm", this); |
michael@0 | 8 | Services.prefs.setBoolPref("toolkit.osfile.test.syslib_necessary", false); |
michael@0 | 9 | // We don't need libc/kernel32.dll for this test |
michael@0 | 10 | |
michael@0 | 11 | let ImportWin = {}; |
michael@0 | 12 | let ImportUnix = {}; |
michael@0 | 13 | Components.utils.import("resource://gre/modules/osfile/ospath_win.jsm", ImportWin); |
michael@0 | 14 | Components.utils.import("resource://gre/modules/osfile/ospath_unix.jsm", ImportUnix); |
michael@0 | 15 | |
michael@0 | 16 | let Win = ImportWin; |
michael@0 | 17 | let Unix = ImportUnix; |
michael@0 | 18 | |
michael@0 | 19 | function do_check_fail(f) |
michael@0 | 20 | { |
michael@0 | 21 | try { |
michael@0 | 22 | let result = f(); |
michael@0 | 23 | do_print("Failed do_check_fail: " + result); |
michael@0 | 24 | do_check_true(false); |
michael@0 | 25 | } catch (ex) { |
michael@0 | 26 | do_check_true(true); |
michael@0 | 27 | } |
michael@0 | 28 | }; |
michael@0 | 29 | |
michael@0 | 30 | function run_test() |
michael@0 | 31 | { |
michael@0 | 32 | do_print("Testing Windows paths"); |
michael@0 | 33 | |
michael@0 | 34 | do_print("Backslash-separated, no drive"); |
michael@0 | 35 | do_check_eq(Win.basename("a\\b"), "b"); |
michael@0 | 36 | do_check_eq(Win.basename("a\\b\\"), ""); |
michael@0 | 37 | do_check_eq(Win.basename("abc"), "abc"); |
michael@0 | 38 | do_check_eq(Win.dirname("a\\b"), "a"); |
michael@0 | 39 | do_check_eq(Win.dirname("a\\b\\"), "a\\b"); |
michael@0 | 40 | do_check_eq(Win.dirname("a\\\\\\\\b"), "a"); |
michael@0 | 41 | do_check_eq(Win.dirname("abc"), "."); |
michael@0 | 42 | do_check_eq(Win.normalize("\\a\\b\\c"), "\\a\\b\\c"); |
michael@0 | 43 | do_check_eq(Win.normalize("\\a\\b\\\\\\\\c"), "\\a\\b\\c"); |
michael@0 | 44 | do_check_eq(Win.normalize("\\a\\b\\c\\\\\\"), "\\a\\b\\c"); |
michael@0 | 45 | do_check_eq(Win.normalize("\\a\\b\\c\\..\\..\\..\\d\\e\\f"), "\\d\\e\\f"); |
michael@0 | 46 | do_check_eq(Win.normalize("a\\b\\c\\..\\..\\..\\d\\e\\f"), "d\\e\\f"); |
michael@0 | 47 | do_check_fail(function() Win.normalize("\\a\\b\\c\\..\\..\\..\\..\\d\\e\\f")); |
michael@0 | 48 | |
michael@0 | 49 | do_check_eq(Win.join("\\tmp", "foo", "bar"), "\\tmp\\foo\\bar", "join \\tmp,foo,bar"); |
michael@0 | 50 | do_check_eq(Win.join("\\tmp", "\\foo", "bar"), "\\foo\\bar", "join \\tmp,\\foo,bar"); |
michael@0 | 51 | do_check_eq(Win.winGetDrive("\\tmp"), null); |
michael@0 | 52 | do_check_eq(Win.winGetDrive("\\tmp\\a\\b\\c\\d\\e"), null); |
michael@0 | 53 | do_check_eq(Win.winGetDrive("\\"), null); |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | do_print("Backslash-separated, with a drive"); |
michael@0 | 57 | do_check_eq(Win.basename("c:a\\b"), "b"); |
michael@0 | 58 | do_check_eq(Win.basename("c:a\\b\\"), ""); |
michael@0 | 59 | do_check_eq(Win.basename("c:abc"), "abc"); |
michael@0 | 60 | do_check_eq(Win.dirname("c:a\\b"), "c:a"); |
michael@0 | 61 | do_check_eq(Win.dirname("c:a\\b\\"), "c:a\\b"); |
michael@0 | 62 | do_check_eq(Win.dirname("c:a\\\\\\\\b"), "c:a"); |
michael@0 | 63 | do_check_eq(Win.dirname("c:abc"), "c:"); |
michael@0 | 64 | let options = { |
michael@0 | 65 | winNoDrive: true |
michael@0 | 66 | }; |
michael@0 | 67 | do_check_eq(Win.dirname("c:a\\b", options), "a"); |
michael@0 | 68 | do_check_eq(Win.dirname("c:a\\b\\", options), "a\\b"); |
michael@0 | 69 | do_check_eq(Win.dirname("c:a\\\\\\\\b", options), "a"); |
michael@0 | 70 | do_check_eq(Win.dirname("c:abc", options), "."); |
michael@0 | 71 | do_check_eq(Win.join("c:", "abc"), "c:\\abc", "join c:,abc"); |
michael@0 | 72 | |
michael@0 | 73 | do_check_eq(Win.normalize("c:"), "c:\\"); |
michael@0 | 74 | do_check_eq(Win.normalize("c:\\"), "c:\\"); |
michael@0 | 75 | do_check_eq(Win.normalize("c:\\a\\b\\c"), "c:\\a\\b\\c"); |
michael@0 | 76 | do_check_eq(Win.normalize("c:\\a\\b\\\\\\\\c"), "c:\\a\\b\\c"); |
michael@0 | 77 | do_check_eq(Win.normalize("c:\\\\\\\\a\\b\\c"), "c:\\a\\b\\c"); |
michael@0 | 78 | do_check_eq(Win.normalize("c:\\a\\b\\c\\\\\\"), "c:\\a\\b\\c"); |
michael@0 | 79 | do_check_eq(Win.normalize("c:\\a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f"); |
michael@0 | 80 | do_check_eq(Win.normalize("c:a\\b\\c\\..\\..\\..\\d\\e\\f"), "c:\\d\\e\\f"); |
michael@0 | 81 | do_check_fail(function() Win.normalize("c:\\a\\b\\c\\..\\..\\..\\..\\d\\e\\f")); |
michael@0 | 82 | |
michael@0 | 83 | do_check_eq(Win.join("c:\\", "foo"), "c:\\foo", "join c:\,foo"); |
michael@0 | 84 | do_check_eq(Win.join("c:\\tmp", "foo", "bar"), "c:\\tmp\\foo\\bar", "join c:\\tmp,foo,bar"); |
michael@0 | 85 | do_check_eq(Win.join("c:\\tmp", "\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,\\foo,bar"); |
michael@0 | 86 | do_check_eq(Win.join("c:\\tmp", "c:\\foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:\\foo,bar"); |
michael@0 | 87 | do_check_eq(Win.join("c:\\tmp", "c:foo", "bar"), "c:\\foo\\bar", "join c:\\tmp,c:foo,bar"); |
michael@0 | 88 | do_check_eq(Win.winGetDrive("c:"), "c:"); |
michael@0 | 89 | do_check_eq(Win.winGetDrive("c:\\"), "c:"); |
michael@0 | 90 | do_check_eq(Win.winGetDrive("c:abc"), "c:"); |
michael@0 | 91 | do_check_eq(Win.winGetDrive("c:abc\\d\\e\\f\\g"), "c:"); |
michael@0 | 92 | do_check_eq(Win.winGetDrive("c:\\abc"), "c:"); |
michael@0 | 93 | do_check_eq(Win.winGetDrive("c:\\abc\\d\\e\\f\\g"), "c:"); |
michael@0 | 94 | |
michael@0 | 95 | do_print("Forwardslash-separated, no drive"); |
michael@0 | 96 | do_check_eq(Win.normalize("/a/b/c"), "\\a\\b\\c"); |
michael@0 | 97 | do_check_eq(Win.normalize("/a/b////c"), "\\a\\b\\c"); |
michael@0 | 98 | do_check_eq(Win.normalize("/a/b/c///"), "\\a\\b\\c"); |
michael@0 | 99 | do_check_eq(Win.normalize("/a/b/c/../../../d/e/f"), "\\d\\e\\f"); |
michael@0 | 100 | do_check_eq(Win.normalize("a/b/c/../../../d/e/f"), "d\\e\\f"); |
michael@0 | 101 | |
michael@0 | 102 | do_print("Forwardslash-separated, with a drive"); |
michael@0 | 103 | do_check_eq(Win.normalize("c:/"), "c:\\"); |
michael@0 | 104 | do_check_eq(Win.normalize("c:/a/b/c"), "c:\\a\\b\\c"); |
michael@0 | 105 | do_check_eq(Win.normalize("c:/a/b////c"), "c:\\a\\b\\c"); |
michael@0 | 106 | do_check_eq(Win.normalize("c:////a/b/c"), "c:\\a\\b\\c"); |
michael@0 | 107 | do_check_eq(Win.normalize("c:/a/b/c///"), "c:\\a\\b\\c"); |
michael@0 | 108 | do_check_eq(Win.normalize("c:/a/b/c/../../../d/e/f"), "c:\\d\\e\\f"); |
michael@0 | 109 | do_check_eq(Win.normalize("c:a/b/c/../../../d/e/f"), "c:\\d\\e\\f"); |
michael@0 | 110 | |
michael@0 | 111 | do_print("Backslash-separated, UNC-style"); |
michael@0 | 112 | do_check_eq(Win.basename("\\\\a\\b"), "b"); |
michael@0 | 113 | do_check_eq(Win.basename("\\\\a\\b\\"), ""); |
michael@0 | 114 | do_check_eq(Win.basename("\\\\abc"), ""); |
michael@0 | 115 | do_check_eq(Win.dirname("\\\\a\\b"), "\\\\a"); |
michael@0 | 116 | do_check_eq(Win.dirname("\\\\a\\b\\"), "\\\\a\\b"); |
michael@0 | 117 | do_check_eq(Win.dirname("\\\\a\\\\\\\\b"), "\\\\a"); |
michael@0 | 118 | do_check_eq(Win.dirname("\\\\abc"), "\\\\abc"); |
michael@0 | 119 | do_check_eq(Win.normalize("\\\\a\\b\\c"), "\\\\a\\b\\c"); |
michael@0 | 120 | do_check_eq(Win.normalize("\\\\a\\b\\\\\\\\c"), "\\\\a\\b\\c"); |
michael@0 | 121 | do_check_eq(Win.normalize("\\\\a\\b\\c\\\\\\"), "\\\\a\\b\\c"); |
michael@0 | 122 | do_check_eq(Win.normalize("\\\\a\\b\\c\\..\\..\\d\\e\\f"), "\\\\a\\d\\e\\f"); |
michael@0 | 123 | do_check_fail(function() Win.normalize("\\\\a\\b\\c\\..\\..\\..\\d\\e\\f")); |
michael@0 | 124 | |
michael@0 | 125 | do_check_eq(Win.join("\\\\a\\tmp", "foo", "bar"), "\\\\a\\tmp\\foo\\bar"); |
michael@0 | 126 | do_check_eq(Win.join("\\\\a\\tmp", "\\foo", "bar"), "\\\\a\\foo\\bar"); |
michael@0 | 127 | do_check_eq(Win.join("\\\\a\\tmp", "\\\\foo\\", "bar"), "\\\\foo\\bar"); |
michael@0 | 128 | do_check_eq(Win.winGetDrive("\\\\"), null); |
michael@0 | 129 | do_check_eq(Win.winGetDrive("\\\\c"), "\\\\c"); |
michael@0 | 130 | do_check_eq(Win.winGetDrive("\\\\c\\abc"), "\\\\c"); |
michael@0 | 131 | |
michael@0 | 132 | do_print("Testing unix paths"); |
michael@0 | 133 | do_check_eq(Unix.basename("a/b"), "b"); |
michael@0 | 134 | do_check_eq(Unix.basename("a/b/"), ""); |
michael@0 | 135 | do_check_eq(Unix.basename("abc"), "abc"); |
michael@0 | 136 | do_check_eq(Unix.dirname("a/b"), "a"); |
michael@0 | 137 | do_check_eq(Unix.dirname("a/b/"), "a/b"); |
michael@0 | 138 | do_check_eq(Unix.dirname("a////b"), "a"); |
michael@0 | 139 | do_check_eq(Unix.dirname("abc"), "."); |
michael@0 | 140 | do_check_eq(Unix.normalize("/a/b/c"), "/a/b/c"); |
michael@0 | 141 | do_check_eq(Unix.normalize("/a/b////c"), "/a/b/c"); |
michael@0 | 142 | do_check_eq(Unix.normalize("////a/b/c"), "/a/b/c"); |
michael@0 | 143 | do_check_eq(Unix.normalize("/a/b/c///"), "/a/b/c"); |
michael@0 | 144 | do_check_eq(Unix.normalize("/a/b/c/../../../d/e/f"), "/d/e/f"); |
michael@0 | 145 | do_check_eq(Unix.normalize("a/b/c/../../../d/e/f"), "d/e/f"); |
michael@0 | 146 | do_check_fail(function() Unix.normalize("/a/b/c/../../../../d/e/f")); |
michael@0 | 147 | |
michael@0 | 148 | do_check_eq(Unix.join("/tmp", "foo", "bar"), "/tmp/foo/bar", "join /tmp,foo,bar"); |
michael@0 | 149 | do_check_eq(Unix.join("/tmp", "/foo", "bar"), "/foo/bar", "join /tmp,/foo,bar"); |
michael@0 | 150 | |
michael@0 | 151 | do_print("Testing the presence of ospath.jsm"); |
michael@0 | 152 | let Scope = {}; |
michael@0 | 153 | try { |
michael@0 | 154 | Components.utils.import("resource://gre/modules/osfile/ospath.jsm", Scope); |
michael@0 | 155 | } catch (ex) { |
michael@0 | 156 | // Can't load ospath |
michael@0 | 157 | } |
michael@0 | 158 | do_check_true(!!Scope.basename); |
michael@0 | 159 | } |