Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 6 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | const Cr = Components.results; |
michael@0 | 9 | const Ci = Components.interfaces; |
michael@0 | 10 | const Cc = Components.classes; |
michael@0 | 11 | const Cu = Components.utils; |
michael@0 | 12 | const CC = Components.Constructor; |
michael@0 | 13 | |
michael@0 | 14 | const LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath"); |
michael@0 | 15 | |
michael@0 | 16 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 17 | |
michael@0 | 18 | function run_test() |
michael@0 | 19 | { |
michael@0 | 20 | // This test makes sense only on Windows, so skip it on other platforms |
michael@0 | 21 | if ("nsILocalFileWin" in Ci |
michael@0 | 22 | && do_get_cwd() instanceof Ci.nsILocalFileWin) { |
michael@0 | 23 | |
michael@0 | 24 | let tempDir = Services.dirsvc.get("TmpD", Ci.nsILocalFile); |
michael@0 | 25 | tempDir.append("shortcutTesting"); |
michael@0 | 26 | tempDir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0666); |
michael@0 | 27 | |
michael@0 | 28 | test_create_noargs(tempDir); |
michael@0 | 29 | test_create_notarget(tempDir); |
michael@0 | 30 | test_create_targetonly(tempDir); |
michael@0 | 31 | test_create_normal(tempDir); |
michael@0 | 32 | test_create_unicode(tempDir); |
michael@0 | 33 | |
michael@0 | 34 | test_update_noargs(tempDir); |
michael@0 | 35 | test_update_notarget(tempDir); |
michael@0 | 36 | test_update_targetonly(tempDir); |
michael@0 | 37 | test_update_normal(tempDir); |
michael@0 | 38 | test_update_unicode(tempDir); |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function test_create_noargs(tempDir) |
michael@0 | 43 | { |
michael@0 | 44 | let shortcutFile = tempDir.clone(); |
michael@0 | 45 | shortcutFile.append("shouldNeverExist.lnk"); |
michael@0 | 46 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 47 | |
michael@0 | 48 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 49 | |
michael@0 | 50 | try |
michael@0 | 51 | { |
michael@0 | 52 | win.setShortcut(); |
michael@0 | 53 | do_throw("Creating a shortcut with no args (no target) should throw"); |
michael@0 | 54 | } |
michael@0 | 55 | catch(e if (e instanceof Ci.nsIException |
michael@0 | 56 | && e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)) |
michael@0 | 57 | { |
michael@0 | 58 | |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | function test_create_notarget(tempDir) |
michael@0 | 63 | { |
michael@0 | 64 | let shortcutFile = tempDir.clone(); |
michael@0 | 65 | shortcutFile.append("shouldNeverExist2.lnk"); |
michael@0 | 66 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 67 | |
michael@0 | 68 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 69 | |
michael@0 | 70 | try |
michael@0 | 71 | { |
michael@0 | 72 | win.setShortcut(null, |
michael@0 | 73 | do_get_cwd(), |
michael@0 | 74 | "arg1 arg2", |
michael@0 | 75 | "Shortcut with no target"); |
michael@0 | 76 | do_throw("Creating a shortcut with no target should throw"); |
michael@0 | 77 | } |
michael@0 | 78 | catch(e if (e instanceof Ci.nsIException |
michael@0 | 79 | && e.result == Cr.NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)) |
michael@0 | 80 | { |
michael@0 | 81 | |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | function test_create_targetonly(tempDir) |
michael@0 | 86 | { |
michael@0 | 87 | let shortcutFile = tempDir.clone(); |
michael@0 | 88 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 89 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 90 | |
michael@0 | 91 | let targetFile = tempDir.clone(); |
michael@0 | 92 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 93 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 94 | |
michael@0 | 95 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 96 | |
michael@0 | 97 | win.setShortcut(targetFile); |
michael@0 | 98 | |
michael@0 | 99 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 100 | do_check_true(shortcutTarget.equals(targetFile)); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function test_create_normal(tempDir) |
michael@0 | 104 | { |
michael@0 | 105 | let shortcutFile = tempDir.clone(); |
michael@0 | 106 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 107 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 108 | |
michael@0 | 109 | let targetFile = tempDir.clone(); |
michael@0 | 110 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 111 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 112 | |
michael@0 | 113 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 114 | |
michael@0 | 115 | win.setShortcut(targetFile, |
michael@0 | 116 | do_get_cwd(), |
michael@0 | 117 | "arg1 arg2", |
michael@0 | 118 | "Ordinary shortcut"); |
michael@0 | 119 | |
michael@0 | 120 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 121 | do_check_true(shortcutTarget.equals(targetFile)) |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | function test_create_unicode(tempDir) |
michael@0 | 125 | { |
michael@0 | 126 | let shortcutFile = tempDir.clone(); |
michael@0 | 127 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 128 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 129 | |
michael@0 | 130 | let targetFile = tempDir.clone(); |
michael@0 | 131 | targetFile.append("ṩhогТϾừ†Target.exe"); |
michael@0 | 132 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 133 | |
michael@0 | 134 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 135 | |
michael@0 | 136 | win.setShortcut(targetFile, |
michael@0 | 137 | do_get_cwd(), // XXX: This should probably be a unicode dir |
michael@0 | 138 | "ᾶṟǵ1 ᾶṟǵ2", |
michael@0 | 139 | "ῧṋіḉѻₑ"); |
michael@0 | 140 | |
michael@0 | 141 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 142 | do_check_true(shortcutTarget.equals(targetFile)) |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function test_update_noargs(tempDir) |
michael@0 | 146 | { |
michael@0 | 147 | let shortcutFile = tempDir.clone(); |
michael@0 | 148 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 149 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 150 | |
michael@0 | 151 | let targetFile = tempDir.clone(); |
michael@0 | 152 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 153 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 154 | |
michael@0 | 155 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 156 | |
michael@0 | 157 | win.setShortcut(targetFile, |
michael@0 | 158 | do_get_cwd(), |
michael@0 | 159 | "arg1 arg2", |
michael@0 | 160 | "A sample shortcut"); |
michael@0 | 161 | |
michael@0 | 162 | win.setShortcut(); |
michael@0 | 163 | |
michael@0 | 164 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 165 | do_check_true(shortcutTarget.equals(targetFile)) |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | function test_update_notarget(tempDir) |
michael@0 | 169 | { |
michael@0 | 170 | let shortcutFile = tempDir.clone(); |
michael@0 | 171 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 172 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 173 | |
michael@0 | 174 | let targetFile = tempDir.clone(); |
michael@0 | 175 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 176 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 177 | |
michael@0 | 178 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 179 | |
michael@0 | 180 | win.setShortcut(targetFile, |
michael@0 | 181 | do_get_cwd(), |
michael@0 | 182 | "arg1 arg2", |
michael@0 | 183 | "A sample shortcut"); |
michael@0 | 184 | |
michael@0 | 185 | win.setShortcut(null, |
michael@0 | 186 | do_get_profile(), |
michael@0 | 187 | "arg3 arg4", |
michael@0 | 188 | "An UPDATED shortcut"); |
michael@0 | 189 | |
michael@0 | 190 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 191 | do_check_true(shortcutTarget.equals(targetFile)) |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | function test_update_targetonly(tempDir) |
michael@0 | 195 | { |
michael@0 | 196 | let shortcutFile = tempDir.clone(); |
michael@0 | 197 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 198 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 199 | |
michael@0 | 200 | let targetFile = tempDir.clone(); |
michael@0 | 201 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 202 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 203 | |
michael@0 | 204 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 205 | |
michael@0 | 206 | win.setShortcut(targetFile, |
michael@0 | 207 | do_get_cwd(), |
michael@0 | 208 | "arg1 arg2", |
michael@0 | 209 | "A sample shortcut"); |
michael@0 | 210 | |
michael@0 | 211 | let newTargetFile = tempDir.clone(); |
michael@0 | 212 | newTargetFile.append("shortcutTarget.exe"); |
michael@0 | 213 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 214 | |
michael@0 | 215 | win.setShortcut(newTargetFile); |
michael@0 | 216 | |
michael@0 | 217 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 218 | do_check_true(shortcutTarget.equals(newTargetFile)) |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | function test_update_normal(tempDir) |
michael@0 | 222 | { |
michael@0 | 223 | let shortcutFile = tempDir.clone(); |
michael@0 | 224 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 225 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 226 | |
michael@0 | 227 | let targetFile = tempDir.clone(); |
michael@0 | 228 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 229 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 230 | |
michael@0 | 231 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 232 | |
michael@0 | 233 | win.setShortcut(targetFile, |
michael@0 | 234 | do_get_cwd(), |
michael@0 | 235 | "arg1 arg2", |
michael@0 | 236 | "A sample shortcut"); |
michael@0 | 237 | |
michael@0 | 238 | let newTargetFile = tempDir.clone(); |
michael@0 | 239 | newTargetFile.append("shortcutTarget.exe"); |
michael@0 | 240 | newTargetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 241 | |
michael@0 | 242 | win.setShortcut(newTargetFile, |
michael@0 | 243 | do_get_profile(), |
michael@0 | 244 | "arg3 arg4", |
michael@0 | 245 | "An UPDATED shortcut"); |
michael@0 | 246 | |
michael@0 | 247 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 248 | do_check_true(shortcutTarget.equals(newTargetFile)) |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | function test_update_unicode(tempDir) |
michael@0 | 252 | { |
michael@0 | 253 | let shortcutFile = tempDir.clone(); |
michael@0 | 254 | shortcutFile.append("createdShortcut.lnk"); |
michael@0 | 255 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 256 | |
michael@0 | 257 | let targetFile = tempDir.clone(); |
michael@0 | 258 | targetFile.append("shortcutTarget.exe"); |
michael@0 | 259 | targetFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 260 | |
michael@0 | 261 | let win = shortcutFile.QueryInterface(Ci.nsILocalFileWin); |
michael@0 | 262 | |
michael@0 | 263 | win.setShortcut(targetFile, |
michael@0 | 264 | do_get_cwd(), |
michael@0 | 265 | "arg1 arg2", |
michael@0 | 266 | "A sample shortcut"); |
michael@0 | 267 | |
michael@0 | 268 | let newTargetFile = tempDir.clone(); |
michael@0 | 269 | newTargetFile.append("ṩhогТϾừ†Target.exe"); |
michael@0 | 270 | shortcutFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 271 | |
michael@0 | 272 | win.setShortcut(newTargetFile, |
michael@0 | 273 | do_get_profile(), // XXX: This should probably be unicode |
michael@0 | 274 | "ᾶṟǵ3 ᾶṟǵ4", |
michael@0 | 275 | "A ῧṋіḉѻₑ shortcut"); |
michael@0 | 276 | |
michael@0 | 277 | let shortcutTarget = LocalFile(shortcutFile.target); |
michael@0 | 278 | do_check_true(shortcutTarget.equals(newTargetFile)) |
michael@0 | 279 | } |