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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Tests compatibility overrides, for when strict compatibility checking is |
michael@0 | 5 | // disabled. See bug 693906. |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; |
michael@0 | 9 | |
michael@0 | 10 | Components.utils.import("resource://testing-common/httpd.js"); |
michael@0 | 11 | var gServer = new HttpServer(); |
michael@0 | 12 | gServer.start(-1); |
michael@0 | 13 | gPort = gServer.identity.primaryPort; |
michael@0 | 14 | |
michael@0 | 15 | const PORT = gPort; |
michael@0 | 16 | const BASE_URL = "http://localhost:" + PORT; |
michael@0 | 17 | const DEFAULT_URL = "about:blank"; |
michael@0 | 18 | const REQ_URL = "/data.xml"; |
michael@0 | 19 | |
michael@0 | 20 | // register static file and mark it for interpolation |
michael@0 | 21 | mapUrlToFile(REQ_URL, do_get_file("data/test_compatoverrides.xml"), gServer); |
michael@0 | 22 | |
michael@0 | 23 | Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); |
michael@0 | 24 | Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
michael@0 | 25 | Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, |
michael@0 | 26 | BASE_URL + REQ_URL); |
michael@0 | 27 | |
michael@0 | 28 | |
michael@0 | 29 | // Not hosted, no overrides |
michael@0 | 30 | var addon1 = { |
michael@0 | 31 | id: "addon1@tests.mozilla.org", |
michael@0 | 32 | version: "1.0", |
michael@0 | 33 | name: "Test addon 1", |
michael@0 | 34 | targetApplications: [{ |
michael@0 | 35 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 36 | minVersion: "1", |
michael@0 | 37 | maxVersion: "1" |
michael@0 | 38 | }] |
michael@0 | 39 | }; |
michael@0 | 40 | |
michael@0 | 41 | // Hosted, no overrides |
michael@0 | 42 | var addon2 = { |
michael@0 | 43 | id: "addon2@tests.mozilla.org", |
michael@0 | 44 | version: "1.0", |
michael@0 | 45 | name: "Test addon 2", |
michael@0 | 46 | targetApplications: [{ |
michael@0 | 47 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 48 | minVersion: "1", |
michael@0 | 49 | maxVersion: "1" |
michael@0 | 50 | }] |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | // Hosted, matching override |
michael@0 | 54 | var addon3 = { |
michael@0 | 55 | id: "addon3@tests.mozilla.org", |
michael@0 | 56 | version: "1.0", |
michael@0 | 57 | name: "Test addon 3", |
michael@0 | 58 | targetApplications: [{ |
michael@0 | 59 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 60 | minVersion: "1", |
michael@0 | 61 | maxVersion: "1" |
michael@0 | 62 | }] |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | // Hosted, matching override, wouldn't be compatible if strict checking is enabled |
michael@0 | 66 | var addon4 = { |
michael@0 | 67 | id: "addon4@tests.mozilla.org", |
michael@0 | 68 | version: "1.0", |
michael@0 | 69 | name: "Test addon 4", |
michael@0 | 70 | targetApplications: [{ |
michael@0 | 71 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 72 | minVersion: "0.1", |
michael@0 | 73 | maxVersion: "0.2" |
michael@0 | 74 | }] |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | // Hosted, app ID doesn't match in override |
michael@0 | 78 | var addon5 = { |
michael@0 | 79 | id: "addon5@tests.mozilla.org", |
michael@0 | 80 | version: "1.0", |
michael@0 | 81 | name: "Test addon 5", |
michael@0 | 82 | targetApplications: [{ |
michael@0 | 83 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 84 | minVersion: "1", |
michael@0 | 85 | maxVersion: "1" |
michael@0 | 86 | }] |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | // Hosted, addon version range doesn't match in override |
michael@0 | 90 | var addon6 = { |
michael@0 | 91 | id: "addon6@tests.mozilla.org", |
michael@0 | 92 | version: "1.0", |
michael@0 | 93 | name: "Test addon 6", |
michael@0 | 94 | targetApplications: [{ |
michael@0 | 95 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 96 | minVersion: "1", |
michael@0 | 97 | maxVersion: "1" |
michael@0 | 98 | }] |
michael@0 | 99 | }; |
michael@0 | 100 | |
michael@0 | 101 | // Hosted, app version range doesn't match in override |
michael@0 | 102 | var addon7 = { |
michael@0 | 103 | id: "addon7@tests.mozilla.org", |
michael@0 | 104 | version: "1.0", |
michael@0 | 105 | name: "Test addon 7", |
michael@0 | 106 | targetApplications: [{ |
michael@0 | 107 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 108 | minVersion: "1", |
michael@0 | 109 | maxVersion: "1" |
michael@0 | 110 | }] |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | // Hosted, multiple overrides |
michael@0 | 114 | var addon8 = { |
michael@0 | 115 | id: "addon8@tests.mozilla.org", |
michael@0 | 116 | version: "1.0", |
michael@0 | 117 | name: "Test addon 8", |
michael@0 | 118 | targetApplications: [{ |
michael@0 | 119 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 120 | minVersion: "1", |
michael@0 | 121 | maxVersion: "1" |
michael@0 | 122 | }] |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | // Not hosted, matching override |
michael@0 | 126 | var addon9 = { |
michael@0 | 127 | id: "addon9@tests.mozilla.org", |
michael@0 | 128 | version: "1.0", |
michael@0 | 129 | name: "Test addon 9", |
michael@0 | 130 | targetApplications: [{ |
michael@0 | 131 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 132 | minVersion: "1", |
michael@0 | 133 | maxVersion: "1" |
michael@0 | 134 | }] |
michael@0 | 135 | }; |
michael@0 | 136 | |
michael@0 | 137 | // Not hosted, override is of unsupported type (compatible) |
michael@0 | 138 | var addon10 = { |
michael@0 | 139 | id: "addon10@tests.mozilla.org", |
michael@0 | 140 | version: "1.0", |
michael@0 | 141 | name: "Test addon 10", |
michael@0 | 142 | targetApplications: [{ |
michael@0 | 143 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 144 | minVersion: "1", |
michael@0 | 145 | maxVersion: "1" |
michael@0 | 146 | }] |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | |
michael@0 | 150 | const profileDir = gProfD.clone(); |
michael@0 | 151 | profileDir.append("extensions"); |
michael@0 | 152 | |
michael@0 | 153 | |
michael@0 | 154 | /* |
michael@0 | 155 | * Trigger an AddonManager background update check |
michael@0 | 156 | * |
michael@0 | 157 | * @param aCallback |
michael@0 | 158 | * Callback to call once the background update is complete |
michael@0 | 159 | */ |
michael@0 | 160 | function trigger_background_update(aCallback) { |
michael@0 | 161 | Services.obs.addObserver({ |
michael@0 | 162 | observe: function(aSubject, aTopic, aData) { |
michael@0 | 163 | Services.obs.removeObserver(this, "addons-background-update-complete"); |
michael@0 | 164 | do_execute_soon(aCallback); |
michael@0 | 165 | } |
michael@0 | 166 | }, "addons-background-update-complete", false); |
michael@0 | 167 | |
michael@0 | 168 | gInternalManager.notify(null); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function run_test() { |
michael@0 | 172 | do_test_pending(); |
michael@0 | 173 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "2"); |
michael@0 | 174 | |
michael@0 | 175 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 176 | writeInstallRDFForExtension(addon2, profileDir); |
michael@0 | 177 | writeInstallRDFForExtension(addon3, profileDir); |
michael@0 | 178 | writeInstallRDFForExtension(addon4, profileDir); |
michael@0 | 179 | writeInstallRDFForExtension(addon5, profileDir); |
michael@0 | 180 | writeInstallRDFForExtension(addon6, profileDir); |
michael@0 | 181 | writeInstallRDFForExtension(addon7, profileDir); |
michael@0 | 182 | writeInstallRDFForExtension(addon8, profileDir); |
michael@0 | 183 | writeInstallRDFForExtension(addon9, profileDir); |
michael@0 | 184 | writeInstallRDFForExtension(addon10, profileDir); |
michael@0 | 185 | |
michael@0 | 186 | startupManager(); |
michael@0 | 187 | |
michael@0 | 188 | trigger_background_update(run_test_1); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | function end_test() { |
michael@0 | 192 | gServer.stop(do_test_finished); |
michael@0 | 193 | } |
michael@0 | 194 | |
michael@0 | 195 | function check_compat_status(aCallback) { |
michael@0 | 196 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 197 | "addon2@tests.mozilla.org", |
michael@0 | 198 | "addon3@tests.mozilla.org", |
michael@0 | 199 | "addon4@tests.mozilla.org", |
michael@0 | 200 | "addon5@tests.mozilla.org", |
michael@0 | 201 | "addon6@tests.mozilla.org", |
michael@0 | 202 | "addon7@tests.mozilla.org", |
michael@0 | 203 | "addon8@tests.mozilla.org", |
michael@0 | 204 | "addon9@tests.mozilla.org", |
michael@0 | 205 | "addon10@tests.mozilla.org"], |
michael@0 | 206 | function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10]) { |
michael@0 | 207 | |
michael@0 | 208 | do_check_neq(a1, null); |
michael@0 | 209 | do_check_eq(a1.compatibilityOverrides, null); |
michael@0 | 210 | do_check_true(a1.isCompatible); |
michael@0 | 211 | do_check_false(a1.appDisabled); |
michael@0 | 212 | |
michael@0 | 213 | do_check_neq(a2, null); |
michael@0 | 214 | do_check_eq(a2.compatibilityOverrides, null); |
michael@0 | 215 | do_check_true(a2.isCompatible); |
michael@0 | 216 | do_check_false(a2.appDisabled); |
michael@0 | 217 | |
michael@0 | 218 | do_check_neq(a3, null); |
michael@0 | 219 | do_check_neq(a3.compatibilityOverrides, null); |
michael@0 | 220 | do_check_eq(a3.compatibilityOverrides.length, 1); |
michael@0 | 221 | do_check_false(a3.isCompatible); |
michael@0 | 222 | do_check_true(a3.appDisabled); |
michael@0 | 223 | |
michael@0 | 224 | do_check_neq(a4, null); |
michael@0 | 225 | do_check_neq(a4.compatibilityOverrides, null); |
michael@0 | 226 | do_check_eq(a4.compatibilityOverrides.length, 1); |
michael@0 | 227 | do_check_false(a4.isCompatible); |
michael@0 | 228 | do_check_true(a4.appDisabled); |
michael@0 | 229 | |
michael@0 | 230 | do_check_neq(a5, null); |
michael@0 | 231 | do_check_eq(a5.compatibilityOverrides, null); |
michael@0 | 232 | do_check_true(a5.isCompatible); |
michael@0 | 233 | do_check_false(a5.appDisabled); |
michael@0 | 234 | |
michael@0 | 235 | do_check_neq(a6, null); |
michael@0 | 236 | do_check_neq(a6.compatibilityOverrides, null); |
michael@0 | 237 | do_check_eq(a6.compatibilityOverrides.length, 1); |
michael@0 | 238 | do_check_true(a6.isCompatible); |
michael@0 | 239 | do_check_false(a6.appDisabled); |
michael@0 | 240 | |
michael@0 | 241 | do_check_neq(a7, null); |
michael@0 | 242 | do_check_neq(a7.compatibilityOverrides, null); |
michael@0 | 243 | do_check_eq(a7.compatibilityOverrides.length, 1); |
michael@0 | 244 | do_check_true(a7.isCompatible); |
michael@0 | 245 | do_check_false(a7.appDisabled); |
michael@0 | 246 | |
michael@0 | 247 | do_check_neq(a8, null); |
michael@0 | 248 | do_check_neq(a8.compatibilityOverrides, null); |
michael@0 | 249 | do_check_eq(a8.compatibilityOverrides.length, 3); |
michael@0 | 250 | do_check_false(a8.isCompatible); |
michael@0 | 251 | do_check_true(a8.appDisabled); |
michael@0 | 252 | |
michael@0 | 253 | do_check_neq(a9, null); |
michael@0 | 254 | do_check_neq(a9.compatibilityOverrides, null); |
michael@0 | 255 | do_check_eq(a9.compatibilityOverrides.length, 1); |
michael@0 | 256 | do_check_false(a9.isCompatible); |
michael@0 | 257 | do_check_true(a9.appDisabled); |
michael@0 | 258 | |
michael@0 | 259 | do_check_neq(a10, null); |
michael@0 | 260 | do_check_eq(a10.compatibilityOverrides, null); |
michael@0 | 261 | do_check_true(a10.isCompatible); |
michael@0 | 262 | do_check_false(a10.appDisabled); |
michael@0 | 263 | |
michael@0 | 264 | do_execute_soon(aCallback); |
michael@0 | 265 | }); |
michael@0 | 266 | } |
michael@0 | 267 | |
michael@0 | 268 | function run_test_1() { |
michael@0 | 269 | do_print("Run test 1"); |
michael@0 | 270 | check_compat_status(run_test_2); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | function run_test_2() { |
michael@0 | 274 | do_print("Run test 2"); |
michael@0 | 275 | restartManager(); |
michael@0 | 276 | check_compat_status(end_test); |
michael@0 | 277 | } |