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: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | // This tests taskbar jump list functionality available on win7 and up. |
michael@0 | 7 | |
michael@0 | 8 | const Cc = Components.classes; |
michael@0 | 9 | const Ci = Components.interfaces; |
michael@0 | 10 | |
michael@0 | 11 | function test_basics() |
michael@0 | 12 | { |
michael@0 | 13 | var item = Cc["@mozilla.org/windows-jumplistitem;1"]. |
michael@0 | 14 | createInstance(Ci.nsIJumpListItem); |
michael@0 | 15 | |
michael@0 | 16 | var sep = Cc["@mozilla.org/windows-jumplistseparator;1"]. |
michael@0 | 17 | createInstance(Ci.nsIJumpListSeparator); |
michael@0 | 18 | |
michael@0 | 19 | var shortcut = Cc["@mozilla.org/windows-jumplistshortcut;1"]. |
michael@0 | 20 | createInstance(Ci.nsIJumpListShortcut); |
michael@0 | 21 | |
michael@0 | 22 | var link = Cc["@mozilla.org/windows-jumplistlink;1"]. |
michael@0 | 23 | createInstance(Ci.nsIJumpListLink); |
michael@0 | 24 | |
michael@0 | 25 | do_check_false(item.equals(sep)); |
michael@0 | 26 | do_check_false(item.equals(shortcut)); |
michael@0 | 27 | do_check_false(item.equals(link)); |
michael@0 | 28 | |
michael@0 | 29 | do_check_false(sep.equals(item)); |
michael@0 | 30 | do_check_false(sep.equals(shortcut)); |
michael@0 | 31 | do_check_false(sep.equals(link)); |
michael@0 | 32 | |
michael@0 | 33 | do_check_false(shortcut.equals(item)); |
michael@0 | 34 | do_check_false(shortcut.equals(sep)); |
michael@0 | 35 | do_check_false(shortcut.equals(link)); |
michael@0 | 36 | |
michael@0 | 37 | do_check_false(link.equals(item)); |
michael@0 | 38 | do_check_false(link.equals(sep)); |
michael@0 | 39 | do_check_false(link.equals(shortcut)); |
michael@0 | 40 | |
michael@0 | 41 | do_check_true(item.equals(item)); |
michael@0 | 42 | do_check_true(sep.equals(sep)); |
michael@0 | 43 | do_check_true(link.equals(link)); |
michael@0 | 44 | do_check_true(shortcut.equals(shortcut)); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | function test_separator() |
michael@0 | 48 | { |
michael@0 | 49 | // separators: |
michael@0 | 50 | |
michael@0 | 51 | var item = Cc["@mozilla.org/windows-jumplistseparator;1"]. |
michael@0 | 52 | createInstance(Ci.nsIJumpListSeparator); |
michael@0 | 53 | |
michael@0 | 54 | do_check_true(item.type == Ci.nsIJumpListItem.JUMPLIST_ITEM_SEPARATOR); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function test_hashes() |
michael@0 | 58 | { |
michael@0 | 59 | var link = Cc["@mozilla.org/windows-jumplistlink;1"] |
michael@0 | 60 | .createInstance(Ci.nsIJumpListLink); |
michael@0 | 61 | var uri1 = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 62 | .createInstance(Ci.nsIURI); |
michael@0 | 63 | var uri2 = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 64 | .createInstance(Ci.nsIURI); |
michael@0 | 65 | |
michael@0 | 66 | uri1.spec = "http://www.123.com/"; |
michael@0 | 67 | uri2.spec = "http://www.123.com/"; |
michael@0 | 68 | |
michael@0 | 69 | link.uri = uri1; |
michael@0 | 70 | |
michael@0 | 71 | do_check_true(link.compareHash(uri2)) |
michael@0 | 72 | uri2.spec = "http://www.456.com/"; |
michael@0 | 73 | do_check_false(link.compareHash(uri2)) |
michael@0 | 74 | uri2.spec = "http://www.123.com/"; |
michael@0 | 75 | do_check_true(link.compareHash(uri2)) |
michael@0 | 76 | uri2.spec = "https://www.123.com/"; |
michael@0 | 77 | do_check_false(link.compareHash(uri2)) |
michael@0 | 78 | uri2.spec = "http://www.123.com/test/"; |
michael@0 | 79 | do_check_false(link.compareHash(uri2)) |
michael@0 | 80 | uri1.spec = "http://www.123.com/test/"; |
michael@0 | 81 | uri2.spec = "http://www.123.com/test/"; |
michael@0 | 82 | do_check_true(link.compareHash(uri2)) |
michael@0 | 83 | uri1.spec = "https://www.123.com/test/"; |
michael@0 | 84 | uri2.spec = "https://www.123.com/test/"; |
michael@0 | 85 | do_check_true(link.compareHash(uri2)) |
michael@0 | 86 | uri2.spec = "ftp://www.123.com/test/"; |
michael@0 | 87 | do_check_false(link.compareHash(uri2)) |
michael@0 | 88 | uri2.spec = "http://123.com/test/"; |
michael@0 | 89 | do_check_false(link.compareHash(uri2)) |
michael@0 | 90 | uri1.spec = "https://www.123.com/test/"; |
michael@0 | 91 | uri2.spec = "https://www.123.com/Test/"; |
michael@0 | 92 | do_check_false(link.compareHash(uri2)) |
michael@0 | 93 | |
michael@0 | 94 | uri1.spec = "http://www.123.com/"; |
michael@0 | 95 | do_check_eq(link.uriHash, "QGLmWuwuTozr3tOfXSf5mg=="); |
michael@0 | 96 | uri1.spec = "http://www.123.com/test/"; |
michael@0 | 97 | do_check_eq(link.uriHash, "AG87Ls+GmaUYSUJFETRr3Q=="); |
michael@0 | 98 | uri1.spec = "https://www.123.com/"; |
michael@0 | 99 | do_check_eq(link.uriHash, "iSx6UH1a9enVPzUA9JZ42g=="); |
michael@0 | 100 | |
michael@0 | 101 | var uri3 = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 102 | .createInstance(Ci.nsIURI); |
michael@0 | 103 | link.uri = uri3; |
michael@0 | 104 | do_check_eq(link.uriHash, "hTrpDwNRMkvXPqYV5kh1Fw=="); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | function test_links() |
michael@0 | 108 | { |
michael@0 | 109 | // links: |
michael@0 | 110 | var link1 = Cc["@mozilla.org/windows-jumplistlink;1"] |
michael@0 | 111 | .createInstance(Ci.nsIJumpListLink); |
michael@0 | 112 | var link2 = Cc["@mozilla.org/windows-jumplistlink;1"] |
michael@0 | 113 | .createInstance(Ci.nsIJumpListLink); |
michael@0 | 114 | |
michael@0 | 115 | var uri1 = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 116 | .createInstance(Ci.nsIURI); |
michael@0 | 117 | var uri2 = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 118 | .createInstance(Ci.nsIURI); |
michael@0 | 119 | |
michael@0 | 120 | uri1.spec = "http://www.test.com/"; |
michael@0 | 121 | uri2.spec = "http://www.test.com/"; |
michael@0 | 122 | |
michael@0 | 123 | link1.uri = uri1; |
michael@0 | 124 | link1.uriTitle = "Test"; |
michael@0 | 125 | link2.uri = uri2; |
michael@0 | 126 | link2.uriTitle = "Test"; |
michael@0 | 127 | |
michael@0 | 128 | do_check_true(link1.equals(link2)); |
michael@0 | 129 | |
michael@0 | 130 | link2.uriTitle = "Testing"; |
michael@0 | 131 | |
michael@0 | 132 | do_check_false(link1.equals(link2)); |
michael@0 | 133 | |
michael@0 | 134 | link2.uriTitle = "Test"; |
michael@0 | 135 | uri2.spec = "http://www.testing.com/"; |
michael@0 | 136 | |
michael@0 | 137 | do_check_false(link1.equals(link2)); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | function test_shortcuts() |
michael@0 | 141 | { |
michael@0 | 142 | // shortcuts: |
michael@0 | 143 | var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"] |
michael@0 | 144 | .createInstance(Ci.nsIJumpListShortcut); |
michael@0 | 145 | |
michael@0 | 146 | var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] |
michael@0 | 147 | .createInstance(Ci.nsILocalHandlerApp); |
michael@0 | 148 | |
michael@0 | 149 | handlerApp.name = "TestApp"; |
michael@0 | 150 | handlerApp.detailedDescription = "TestApp detailed description."; |
michael@0 | 151 | handlerApp.appendParameter("-test"); |
michael@0 | 152 | |
michael@0 | 153 | sc.iconIndex = 1; |
michael@0 | 154 | do_check_eq(sc.iconIndex, 1); |
michael@0 | 155 | |
michael@0 | 156 | var faviconPageUri = Cc["@mozilla.org/network/simple-uri;1"] |
michael@0 | 157 | .createInstance(Ci.nsIURI); |
michael@0 | 158 | faviconPageUri.spec = "http://www.123.com/"; |
michael@0 | 159 | sc.faviconPageUri = faviconPageUri; |
michael@0 | 160 | do_check_eq(sc.faviconPageUri, faviconPageUri); |
michael@0 | 161 | |
michael@0 | 162 | var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 163 | getService(Ci.nsIProperties). |
michael@0 | 164 | QueryInterface(Ci.nsIDirectoryService); |
michael@0 | 165 | var notepad = dirSvc.get("WinD", Ci.nsIFile); |
michael@0 | 166 | notepad.append("notepad.exe"); |
michael@0 | 167 | if (notepad.exists()) { |
michael@0 | 168 | handlerApp.executable = notepad; |
michael@0 | 169 | sc.app = handlerApp; |
michael@0 | 170 | do_check_eq(sc.app.detailedDescription, "TestApp detailed description."); |
michael@0 | 171 | do_check_eq(sc.app.name, "TestApp"); |
michael@0 | 172 | do_check_true(sc.app.parameterExists("-test")); |
michael@0 | 173 | do_check_false(sc.app.parameterExists("-notset")); |
michael@0 | 174 | } |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | function test_jumplist() |
michael@0 | 178 | { |
michael@0 | 179 | // Jump lists can't register links unless the application is the default |
michael@0 | 180 | // protocol handler for the protocol of the link, so we skip off testing |
michael@0 | 181 | // those in these tests. We'll init the jump list for the xpc shell harness, |
michael@0 | 182 | // add a task item, and commit it. |
michael@0 | 183 | |
michael@0 | 184 | // not compiled in |
michael@0 | 185 | if (Ci.nsIWinTaskbar == null) |
michael@0 | 186 | return; |
michael@0 | 187 | |
michael@0 | 188 | var taskbar = Cc["@mozilla.org/windows-taskbar;1"] |
michael@0 | 189 | .getService(Ci.nsIWinTaskbar); |
michael@0 | 190 | |
michael@0 | 191 | var builder = taskbar.createJumpListBuilder(); |
michael@0 | 192 | |
michael@0 | 193 | do_check_neq(builder, null); |
michael@0 | 194 | |
michael@0 | 195 | // Win7 and up only |
michael@0 | 196 | try { |
michael@0 | 197 | var sysInfo = Cc["@mozilla.org/system-info;1"]. |
michael@0 | 198 | getService(Ci.nsIPropertyBag2); |
michael@0 | 199 | var ver = parseFloat(sysInfo.getProperty("version")); |
michael@0 | 200 | if (ver < 6.1) { |
michael@0 | 201 | do_check_false(builder.available, false); |
michael@0 | 202 | return; |
michael@0 | 203 | } |
michael@0 | 204 | } catch (ex) { } |
michael@0 | 205 | |
michael@0 | 206 | do_check_true(taskbar.available); |
michael@0 | 207 | |
michael@0 | 208 | builder.deleteActiveList(); |
michael@0 | 209 | |
michael@0 | 210 | var items = Cc["@mozilla.org/array;1"] |
michael@0 | 211 | .createInstance(Ci.nsIMutableArray); |
michael@0 | 212 | |
michael@0 | 213 | var sc = Cc["@mozilla.org/windows-jumplistshortcut;1"] |
michael@0 | 214 | .createInstance(Ci.nsIJumpListShortcut); |
michael@0 | 215 | |
michael@0 | 216 | var handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"] |
michael@0 | 217 | .createInstance(Ci.nsILocalHandlerApp); |
michael@0 | 218 | |
michael@0 | 219 | handlerApp.name = "Notepad"; |
michael@0 | 220 | handlerApp.detailedDescription = "Testing detailed description."; |
michael@0 | 221 | |
michael@0 | 222 | var dirSvc = Cc["@mozilla.org/file/directory_service;1"]. |
michael@0 | 223 | getService(Ci.nsIProperties). |
michael@0 | 224 | QueryInterface(Ci.nsIDirectoryService); |
michael@0 | 225 | var notepad = dirSvc.get("WinD", Ci.nsIFile); |
michael@0 | 226 | notepad.append("notepad.exe"); |
michael@0 | 227 | if (notepad.exists()) { |
michael@0 | 228 | handlerApp.executable = notepad; |
michael@0 | 229 | sc.app = handlerApp; |
michael@0 | 230 | items.appendElement(sc, false); |
michael@0 | 231 | |
michael@0 | 232 | var removed = Cc["@mozilla.org/array;1"] |
michael@0 | 233 | .createInstance(Ci.nsIMutableArray); |
michael@0 | 234 | do_check_true(builder.initListBuild(removed)); |
michael@0 | 235 | do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_TASKS, items)); |
michael@0 | 236 | do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_RECENT)); |
michael@0 | 237 | do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_FREQUENT)); |
michael@0 | 238 | do_check_true(builder.commitListBuild()); |
michael@0 | 239 | |
michael@0 | 240 | builder.deleteActiveList(); |
michael@0 | 241 | |
michael@0 | 242 | do_check_true(builder.initListBuild(removed)); |
michael@0 | 243 | do_check_true(builder.addListToBuild(builder.JUMPLIST_CATEGORY_CUSTOM, items, "Custom List")); |
michael@0 | 244 | do_check_true(builder.commitListBuild()); |
michael@0 | 245 | |
michael@0 | 246 | builder.deleteActiveList(); |
michael@0 | 247 | } |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | function run_test() |
michael@0 | 251 | { |
michael@0 | 252 | var isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes); |
michael@0 | 253 | if (!isWindows) |
michael@0 | 254 | return; |
michael@0 | 255 | |
michael@0 | 256 | test_basics(); |
michael@0 | 257 | test_separator(); |
michael@0 | 258 | test_hashes(); |
michael@0 | 259 | test_links(); |
michael@0 | 260 | test_shortcuts(); |
michael@0 | 261 | test_jumplist(); |
michael@0 | 262 | } |